-
Notifications
You must be signed in to change notification settings - Fork 0
feat!: filter popover: flip placement above the trigger row when bottom-anchored (#912) #915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
frano-m
wants to merge
1
commit into
main
Choose a base branch
from
fran/278-filter-position
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/components/Filter/components/Filter/components/Backdrop/backdrop.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import styled from "@emotion/styled"; | ||
| import { Backdrop } from "@mui/material"; | ||
|
|
||
| export const StyledBackdrop = styled(Backdrop)` | ||
| background-color: transparent; | ||
| overflow: hidden; | ||
| overscroll-behavior: none; | ||
| z-index: 1300; | ||
| `; |
15 changes: 15 additions & 0 deletions
15
src/components/Filter/components/Filter/components/Backdrop/backdrop.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Portal } from "@mui/material"; | ||
| import { JSX } from "react"; | ||
| import { useCloseOnEscape } from "../../hooks/UseCloseOnEscape/hook"; | ||
| import { StyledBackdrop } from "./backdrop.styles"; | ||
| import { BACKDROP_PROPS } from "./constants"; | ||
| import { BackdropProps } from "./types"; | ||
|
|
||
| export const Backdrop = (props: BackdropProps): JSX.Element => { | ||
| useCloseOnEscape({ onClose: props.onClick, open: props.open }); | ||
| return ( | ||
| <Portal> | ||
| <StyledBackdrop {...BACKDROP_PROPS} {...props} /> | ||
| </Portal> | ||
| ); | ||
| }; |
5 changes: 5 additions & 0 deletions
5
src/components/Filter/components/Filter/components/Backdrop/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { BackdropProps } from "@mui/material"; | ||
|
|
||
| export const BACKDROP_PROPS: Omit<BackdropProps, "open"> = { | ||
| slotProps: { transition: { unmountOnExit: true } }, | ||
| }; |
5 changes: 5 additions & 0 deletions
5
src/components/Filter/components/Filter/components/Backdrop/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { BackdropProps as MBackdropProps } from "@mui/material"; | ||
|
|
||
| export interface BackdropProps extends Omit<MBackdropProps, "onClick"> { | ||
| onClick: () => void; | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/components/Filter/components/Filter/components/DrawerTransition/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { SlideProps } from "@mui/material"; | ||
|
|
||
| export const SIDE_PROPS: Omit<SlideProps, "children"> = { | ||
| direction: "right", | ||
| easing: "ease-out", | ||
| timeout: { enter: 250, exit: 300 }, | ||
| unmountOnExit: true, | ||
| }; |
48 changes: 25 additions & 23 deletions
48
src/components/Filter/components/Filter/components/DrawerTransition/drawerTransition.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,26 @@ | ||
| import { Slide as MSlide, SlideProps as MSlideProps } from "@mui/material"; | ||
| import { JSX, forwardRef } from "react"; | ||
| import { Slide } from "@mui/material"; | ||
| import { JSX } from "react"; | ||
| import { SIDE_PROPS } from "./constants"; | ||
| import { DrawerTransitionProps } from "./types"; | ||
|
|
||
| export const DrawerTransition = forwardRef<Element, MSlideProps>( | ||
| function DrawerTransition( | ||
| { | ||
| children, | ||
| ...props /* Spread props to allow for Mui SlideProps specific prop overrides. */ | ||
| }: MSlideProps, | ||
| ref, | ||
| ): JSX.Element { | ||
| return ( | ||
| <MSlide | ||
| direction="right" | ||
| easing="ease-out" | ||
| ref={ref} | ||
| unmountOnExit | ||
| {...props} | ||
| > | ||
| {children} | ||
| </MSlide> | ||
| ); | ||
| }, | ||
| ); | ||
| /** | ||
| * Slide transition used for the drawer-surface filter popover. | ||
| * @param props - Component props (extends MUI SlideProps). | ||
| * @param props.children - Transition child. | ||
| * @param props.placement - Popper placement; consumed only to keep it off the DOM. | ||
| * @param props.ref - Forwarded ref. | ||
| * @returns Slide transition element. | ||
| */ | ||
| export const DrawerTransition = ({ | ||
| children, | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars -- destructured out so it doesn't spread onto the DOM Slide element | ||
| placement: _placement, | ||
| ref, | ||
| ...props | ||
| }: DrawerTransitionProps): JSX.Element => { | ||
| return ( | ||
| <Slide {...SIDE_PROPS} ref={ref} {...props}> | ||
| {children} | ||
| </Slide> | ||
| ); | ||
| }; | ||
7 changes: 7 additions & 0 deletions
7
src/components/Filter/components/Filter/components/DrawerTransition/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { PopperPlacementType, SlideProps } from "@mui/material"; | ||
| import { Ref } from "react"; | ||
|
|
||
| export interface DrawerTransitionProps extends SlideProps { | ||
| placement?: PopperPlacementType; | ||
| ref?: Ref<unknown>; | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/components/Filter/components/Filter/components/MenuTransition/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { PopperPlacementType } from "@mui/material"; | ||
| import { CSSProperties } from "react"; | ||
| import { POPPER_PROPS } from "../../../../../../styles/common/mui/popper"; | ||
|
|
||
| export const PLACEMENT_TRANSFORM_ORIGIN: Partial< | ||
| Record<PopperPlacementType, CSSProperties["transformOrigin"]> | ||
| > = { | ||
| [POPPER_PROPS.PLACEMENT.BOTTOM_START]: "0 0 0", | ||
| [POPPER_PROPS.PLACEMENT.RIGHT]: "0 50% 0", | ||
| [POPPER_PROPS.PLACEMENT.TOP_START]: "0 100% 0", | ||
| }; |
31 changes: 31 additions & 0 deletions
31
src/components/Filter/components/Filter/components/MenuTransition/menuTransition.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { Grow } from "@mui/material"; | ||
| import { JSX } from "react"; | ||
| import { POPPER_PROPS } from "../../../../../../styles/common/mui/popper"; | ||
| import { PLACEMENT_TRANSFORM_ORIGIN } from "./constants"; | ||
| import { MenuTransitionProps } from "./types"; | ||
|
|
||
| /** | ||
| * Grow transition with a placement-driven transform origin. | ||
| * @param props - Component props. | ||
| * @param props.placement - Popper placement, drives the transform origin. | ||
| * @param props.ref - Forwarded ref. | ||
| * @param props.style - Style merged with the placement-derived transform origin. | ||
| * @returns Grow transition element. | ||
| */ | ||
| export const MenuTransition = ({ | ||
| placement = POPPER_PROPS.PLACEMENT.BOTTOM_START, | ||
| ref, | ||
| style, | ||
| ...props | ||
| }: MenuTransitionProps): JSX.Element => { | ||
| return ( | ||
| <Grow | ||
| {...props} | ||
| ref={ref} | ||
| style={{ | ||
| ...style, | ||
| transformOrigin: PLACEMENT_TRANSFORM_ORIGIN[placement], | ||
| }} | ||
| /> | ||
|
frano-m marked this conversation as resolved.
|
||
| ); | ||
| }; | ||
7 changes: 7 additions & 0 deletions
7
src/components/Filter/components/Filter/components/MenuTransition/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { GrowProps, PopperPlacementType } from "@mui/material"; | ||
| import { Ref } from "react"; | ||
|
|
||
| export interface MenuTransitionProps extends GrowProps { | ||
| placement?: PopperPlacementType; | ||
| ref?: Ref<unknown>; | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/components/Filter/components/Filter/components/Popper/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { PopperProps } from "@mui/material"; | ||
| import { POPPER_PROPS as MUI_POPPER_PROPS } from "../../../../../../styles/common/mui/popper"; | ||
|
|
||
| export const POPPER_PROPS: Omit<PopperProps, "open"> = { | ||
| placement: MUI_POPPER_PROPS.PLACEMENT.BOTTOM_START, | ||
| popperOptions: { | ||
| modifiers: [ | ||
| { | ||
| name: "flip", | ||
| options: { | ||
| fallbackPlacements: [ | ||
| MUI_POPPER_PROPS.PLACEMENT.TOP_START, | ||
| MUI_POPPER_PROPS.PLACEMENT.RIGHT, | ||
| ], | ||
| }, | ||
| }, | ||
| { name: "offset", options: { offset: [0, 4] } }, | ||
| ], | ||
| }, | ||
| role: "dialog", | ||
| transition: true, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,34 @@ | ||
| import { css } from "@emotion/react"; | ||
| import styled from "@emotion/styled"; | ||
| import { Popover } from "@mui/material"; | ||
| import { Popper } from "@mui/material"; | ||
| import { PALETTE } from "../../../../styles/common/constants/palette"; | ||
| import { SURFACE_TYPE } from "../surfaces/types"; | ||
| import { FilterProps } from "./filter"; | ||
| import { FilterProps } from "./types"; | ||
|
|
||
| export const StyledPopover = styled(Popover, { | ||
| export const StyledPopper = styled(Popper, { | ||
| shouldForwardProp: (prop) => prop !== "surfaceType", | ||
| })<Pick<FilterProps, "surfaceType">>` | ||
| .MuiPaper-menu { | ||
| margin: 4px 0; | ||
| z-index: 1300; | ||
|
|
||
| .MuiPaper-root { | ||
| overflow: hidden; | ||
| overscroll-behavior: none; | ||
| } | ||
|
frano-m marked this conversation as resolved.
|
||
|
|
||
| ${({ surfaceType }) => | ||
| surfaceType === SURFACE_TYPE.DRAWER && | ||
| css` | ||
| inset: 0 auto 0 0 !important; // required to override Popper's default positioning for correct placement within the drawer. | ||
| transform: none !important; // required to override Popper's transform for correct positioning within the drawer. | ||
|
|
||
| .MuiPaper-root { | ||
| background-color: ${PALETTE.SMOKE_LIGHT}; | ||
| border: none; | ||
| border-radius: 0; | ||
| box-shadow: none; | ||
| height: 100%; | ||
| margin: 0; | ||
| max-height: 100%; | ||
| overflow: visible; // required; allows backdrop button to render outside of drawer container. | ||
| } | ||
| `} | ||
| `; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.