From 19a473e85e6746c146d681b97ecdb357484eba14 Mon Sep 17 00:00:00 2001 From: Siddharth Kshetrapal Date: Sat, 13 Jan 2024 22:48:45 +0530 Subject: [PATCH 1/5] add secondary actions: link and checkbox --- src/drafts/SelectPanel2/SelectPanel.tsx | 46 ++++++++++++++++--- .../stories/SelectPanel.examples.stories.tsx | 7 +-- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/drafts/SelectPanel2/SelectPanel.tsx b/src/drafts/SelectPanel2/SelectPanel.tsx index 10404a96f87..d1f5ce6d2e5 100644 --- a/src/drafts/SelectPanel2/SelectPanel.tsx +++ b/src/drafts/SelectPanel2/SelectPanel.tsx @@ -15,12 +15,17 @@ import { Text, ActionListProps, Octicon, + Link, + LinkProps, + Checkbox, } from '../../index' import {ActionListContainerContext} from '../../ActionList/ActionListContainerContext' import {useSlots} from '../../hooks/useSlots' import {useProvidedRefOrCreate, useId, useAnchoredPosition} from '../../hooks' import {useFocusZone} from '../../hooks/useFocusZone' import {StyledOverlay, OverlayProps} from '../../Overlay/Overlay' +import InputLabel from '../../internal/components/InputLabel' +import {invariant} from '../../utils/invariant' const SelectPanelContext = React.createContext<{ title: string @@ -405,7 +410,9 @@ const SelectPanelFooter = ({...props}) => { sx={{ display: 'flex', justifyContent: 'space-between', - padding: 3, + alignItems: 'center', + padding: hidePrimaryActions ? 2 : 3, + minHeight: '44px', borderTop: '1px solid', borderColor: 'border.default', }} @@ -426,13 +433,38 @@ const SelectPanelFooter = ({...props}) => { ) } -// TODO: is this the right way to add button props? const SelectPanelSecondaryButton: React.FC = props => { return + ) +} + +const SelectPanelSecondaryCheckbox: React.FC<{children: string; id?: string}> = props => { + const id = useId(props.id) + const {selectionVariant} = React.useContext(SelectPanelContext) + + // Checkbox should not be used with instant selection + invariant( + selectionVariant !== 'instant', + 'Sorry! Secondary action with checkbox is not allowed with selectionVariant="instant"', + ) + + return ( + + + + {props.children} + + + ) +} const SelectPanelLoading: React.FC<{children: string}> = ({children = 'Fetching items...'}) => { return ( @@ -536,7 +568,9 @@ export const SelectPanel = Object.assign(Panel, { Header: SelectPanelHeader, SearchInput: SelectPanelSearchInput, Footer: SelectPanelFooter, - SecondaryButton: SelectPanelSecondaryButton, Loading: SelectPanelLoading, Message: SelectPanelMessage, + SecondaryButton: SelectPanelSecondaryButton, + SecondaryLink: SelectPanelSecondaryLink, + SecondaryCheckbox: SelectPanelSecondaryCheckbox, }) diff --git a/src/drafts/SelectPanel2/stories/SelectPanel.examples.stories.tsx b/src/drafts/SelectPanel2/stories/SelectPanel.examples.stories.tsx index 81698bdb900..e890a706efe 100644 --- a/src/drafts/SelectPanel2/stories/SelectPanel.examples.stories.tsx +++ b/src/drafts/SelectPanel2/stories/SelectPanel.examples.stories.tsx @@ -574,7 +574,7 @@ export const WithFilterButtons = () => { Try a different search term ) : ( - + {itemsToShow.map(item => ( { )} - {/* @ts-ignore TODO as prop is not identified by button? */} - - View all {selectedFilter} - + View all {selectedFilter} From 02e3ac278da72bae2436d3e6e93680c956a5a0f0 Mon Sep 17 00:00:00 2001 From: Siddharth Kshetrapal Date: Sun, 14 Jan 2024 00:52:04 +0530 Subject: [PATCH 2/5] merge secondary actions --- src/drafts/SelectPanel2/SelectPanel.tsx | 91 ++++++++++++------- .../stories/SelectPanel.default.stories.tsx | 2 +- .../stories/SelectPanel.examples.stories.tsx | 8 +- .../stories/SelectPanel.features.stories.tsx | 2 +- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/drafts/SelectPanel2/SelectPanel.tsx b/src/drafts/SelectPanel2/SelectPanel.tsx index d1f5ce6d2e5..21050ff1fd2 100644 --- a/src/drafts/SelectPanel2/SelectPanel.tsx +++ b/src/drafts/SelectPanel2/SelectPanel.tsx @@ -18,6 +18,7 @@ import { Link, LinkProps, Checkbox, + CheckboxProps, } from '../../index' import {ActionListContainerContext} from '../../ActionList/ActionListContainerContext' import {useSlots} from '../../hooks/useSlots' @@ -394,6 +395,7 @@ const SelectPanelSearchInput: React.FC = ({onChange: propsOnChan ) } +const FooterContext = React.createContext(false) const SelectPanelFooter = ({...props}) => { const {onCancel, selectionVariant} = React.useContext(SelectPanelContext) @@ -406,38 +408,40 @@ const SelectPanelFooter = ({...props}) => { } return ( - - {props.children} - - {hidePrimaryActions ? null : ( - - - - - )} - + + + {props.children} + + {hidePrimaryActions ? null : ( + + + + + )} + + ) } -const SelectPanelSecondaryButton: React.FC = props => { +const SecondaryButton: React.FC = props => { return