Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 677
SelectPanel: Add variant=modal#5817
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
fbd625c1b75223cc94b85be1a38a9e3f6deddd5d7d1f73c860cd98d793ab7000cd4c67def876a9d48d0aab31fb90169cf015f98a36e34ef4054f0eb1a336edd9640e321911536e3c5bf3c54302174401f583dd69b4928a3e906b5ba76b712973ebabFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@primer/react": minor | ||
| --- | ||
| SelectPanel: Add variant="modal" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -103,13 +103,15 @@ const StyledOverlay = toggleStyledComponent( | ||
| max-width: calc(100vw - 2rem); | ||
| } | ||
| &:where([data-variant='fullscreen']) { | ||
| ||
| top: 0; | ||
| left: 0; | ||
| width: 100vw; | ||
| height: 100vh; | ||
| margin: 0; | ||
| border-radius: unset; | ||
| &:where([data-responsive='fullscreen']) { | ||
| @media screen and (max-width: calc(768px - 0.02px)) { | ||
| top: 0; | ||
| left: 0; | ||
| width: 100vw; | ||
| height: 100vh; | ||
| margin: 0; | ||
| border-radius: unset; | ||
| } | ||
| } | ||
| ${sx}; | ||
| @@ -127,6 +129,7 @@ type BaseOverlayProps = { | ||
| role?: AriaRole | ||
| children?: React.ReactNode | ||
| className?: string | ||
| responsiveVariant?: 'fullscreen' // we only support fullscreen today but we might add bottomsheet in the future | ||
| } | ||
| type OwnOverlayProps = Merge<StyledOverlayProps, BaseOverlayProps> | ||
| @@ -265,6 +268,7 @@ const Overlay = React.forwardRef<HTMLDivElement, internalOverlayProps>( | ||
| role = 'none', | ||
| visibility = 'visible', | ||
| width = 'auto', | ||
| responsiveVariant, | ||
| ...props | ||
| }, | ||
| forwardedRef, | ||
| @@ -322,6 +326,7 @@ const Overlay = React.forwardRef<HTMLDivElement, internalOverlayProps>( | ||
| right={right} | ||
| height={height} | ||
| visibility={visibility} | ||
| data-responsive={responsiveVariant} | ||
| {...props} | ||
| /> | ||
| </Portal> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -857,3 +857,80 @@ export const WithOnCancel = () => { | ||
| </FormControl> | ||
| ) | ||
| } | ||
| export const AsMultiSelectModal = () => { | ||
hectahertz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const [intialSelection, setInitialSelection] = React.useState<ItemInput[]>(items.slice(1, 3)) | ||
| const [selected, setSelected] = React.useState<ItemInput[]>(intialSelection) | ||
| const [filter, setFilter] = React.useState('') | ||
| const filteredItems = items.filter( | ||
| item => | ||
| // design guidelines say to always show selected items in the list | ||
| selected.some(selectedItem => selectedItem.text === item.text) || | ||
| // then filter the rest | ||
| item.text.toLowerCase().startsWith(filter.toLowerCase()), | ||
| ) | ||
hectahertz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // design guidelines say to sort selected items first | ||
| const selectedItemsSortedFirst = filteredItems.sort((a, b) => { | ||
| const aIsSelected = selected.some(selectedItem => selectedItem.text === a.text) | ||
| const bIsSelected = selected.some(selectedItem => selectedItem.text === b.text) | ||
| if (aIsSelected && !bIsSelected) return -1 | ||
| if (!aIsSelected && bIsSelected) return 1 | ||
| return 0 | ||
| }) | ||
| const [open, setOpen] = useState(false) | ||
| React.useEffect(() => { | ||
| if (!open) setInitialSelection(selected) // set initialSelection for next time | ||
| }, [open, selected]) | ||
| return ( | ||
| <SelectPanel | ||
| variant="modal" | ||
| title="Select labels" | ||
| placeholder="Select labels" | ||
| subtitle="Use labels to organize issues and pull requests" | ||
| renderAnchor={({children, ...anchorProps}) => ( | ||
| <Button trailingAction={TriangleDownIcon} {...anchorProps} aria-haspopup="dialog"> | ||
| {children} | ||
| </Button> | ||
| )} | ||
| open={open} | ||
| onOpenChange={setOpen} | ||
| items={selectedItemsSortedFirst} | ||
| selected={selected} | ||
| onSelectedChange={setSelected} | ||
| onCancel={() => setSelected(intialSelection)} | ||
| onFilterChange={setFilter} | ||
| width="medium" | ||
| /> | ||
| ) | ||
| } | ||
| export const AsSingleSelectModal = () => { | ||
| const [selected, setSelected] = useState<ItemInput | undefined>(undefined) | ||
| const [filter, setFilter] = useState('') | ||
| const [open, setOpen] = useState(false) | ||
| const filteredItems = items.filter(item => item.text.toLowerCase().startsWith(filter.toLowerCase())) | ||
| return ( | ||
| <SelectPanel | ||
| variant="modal" | ||
| title="Select labels" | ||
| placeholder="Select labels" | ||
| subtitle="Use labels to organize issues and pull requests" | ||
| renderAnchor={({children, ...anchorProps}) => ( | ||
| <Button trailingAction={TriangleDownIcon} {...anchorProps} aria-haspopup="dialog"> | ||
| {children} | ||
| </Button> | ||
| )} | ||
| open={open} | ||
| onOpenChange={setOpen} | ||
| items={filteredItems} | ||
| selected={selected} | ||
| onSelectedChange={setSelected} | ||
| onFilterChange={setFilter} | ||
| width="medium" | ||
| /> | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewer: I changed full screen to only be a responsive thing instead of variant you can apply whenever.
data-variant→data-responsive