Skip to content

Commit 6475b07

Browse files
siddharthkplukasoppermann
authored andcommitted
SelectPanel2: Automatically adjust height based on contents (#4245)
* replace height with maxHeight * adjust height of loading & message based on container * remove redundant height from stories * Create strange-starfishes-work.md * fix bad merge
1 parent b80ea33 commit 6475b07

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
experimental/SelectPanel: Automatically adjust height based on contents

packages/react/src/Overlay/Overlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type StyledOverlayProps = {
2121
anchorSide?: AnchorSide
2222
} & SxProp
2323

24-
const heightMap = {
24+
export const heightMap = {
2525
xsmall: '192px',
2626
small: '256px',
2727
medium: '320px',

packages/react/src/drafts/SelectPanel2/SelectPanel.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {ActionListContainerContext} from '../../ActionList/ActionListContainerCo
2424
import {useSlots} from '../../hooks/useSlots'
2525
import {useProvidedRefOrCreate, useId, useAnchoredPosition} from '../../hooks'
2626
import {useFocusZone} from '../../hooks/useFocusZone'
27-
import {StyledOverlay, OverlayProps} from '../../Overlay/Overlay'
27+
import {StyledOverlay, OverlayProps, heightMap} from '../../Overlay/Overlay'
2828
import InputLabel from '../../internal/components/InputLabel'
2929
import {invariant} from '../../utils/invariant'
3030

@@ -65,7 +65,8 @@ export type SelectPanelProps = {
6565

6666
// TODO: move these to SelectPanel.Overlay or overlayProps
6767
width?: OverlayProps['width']
68-
height?: OverlayProps['height'] | 'fit-content'
68+
height?: 'fit-content' // not used, keeping it around temporary for backward compatibility
69+
maxHeight?: Exclude<OverlayProps['maxHeight'], 'xsmall'>
6970

7071
children: React.ReactNode
7172
}
@@ -86,7 +87,7 @@ const Panel: React.FC<SelectPanelProps> = ({
8687
onSubmit: propsOnSubmit,
8788

8889
width = 'medium',
89-
height = 'large',
90+
maxHeight = 'large',
9091
...props
9192
}) => {
9293
const [internalOpen, setInternalOpen] = React.useState(defaultOpen)
@@ -229,8 +230,10 @@ const Panel: React.FC<SelectPanelProps> = ({
229230
aria-labelledby={`${panelId}--title`}
230231
aria-describedby={description ? `${panelId}--description` : undefined}
231232
width={width}
232-
height={height}
233+
height="fit-content"
234+
maxHeight={maxHeight}
233235
sx={{
236+
'--max-height': heightMap[maxHeight],
234237
// reset dialog default styles
235238
border: 'none',
236239
padding: 0,
@@ -433,6 +436,7 @@ const SelectPanelFooter = ({...props}) => {
433436
display: 'flex',
434437
justifyContent: 'space-between',
435438
alignItems: 'center',
439+
flexShrink: 0,
436440
padding: hidePrimaryActions ? 2 : 3,
437441
minHeight: '44px',
438442
borderTop: '1px solid',
@@ -518,6 +522,8 @@ const SelectPanelLoading: React.FC<{children: string}> = ({children = 'Fetching
518522
alignItems: 'center',
519523
height: '100%',
520524
gap: 3,
525+
minHeight: 'min(calc(var(--max-height) - 150px), 324px)',
526+
// maxHeight of dialog - (header & footer)
521527
}}
522528
>
523529
<Spinner size="medium" />
@@ -560,6 +566,8 @@ const SelectPanelMessage: React.FC<SelectPanelMessageProps> = ({
560566
paddingX: 4,
561567
textAlign: 'center',
562568
a: {color: 'inherit', textDecoration: 'underline'},
569+
minHeight: 'min(calc(var(--max-height) - 150px), 324px)',
570+
// maxHeight of dialog - (header & footer)
563571
}}
564572
>
565573
{variant !== 'empty' ? (

packages/react/src/drafts/SelectPanel2/stories/SelectPanel.examples.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ export const OpenFromMenu = () => {
439439
variant="modal"
440440
title="Custom"
441441
open={selectPanelOpen}
442-
height="medium"
443442
onSubmit={() => {
444443
setSelectedSetting('Custom')
445444
setSelectPanelOpen(false)
@@ -603,7 +602,7 @@ export const ShortSelectPanel = () => {
603602
<p>
604603
Use <code>height=fit-content</code> to match height of contents
605604
</p>
606-
<SelectPanel title="Select notification channels" height="fit-content" onSubmit={onSubmit}>
605+
<SelectPanel title="Select notification channels" onSubmit={onSubmit}>
607606
<SelectPanel.Button>
608607
<Text sx={{color: 'fg.muted'}}>Notify me:</Text>{' '}
609608
{Object.keys(channels)

packages/react/src/drafts/SelectPanel2/stories/SelectPanel.features.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const InstantSelectionVariant = () => {
2727
<>
2828
<h1>Instant selection variant</h1>
2929

30-
<SelectPanel title="Choose a tag" selectionVariant="instant" onSubmit={onSubmit} height="medium">
30+
<SelectPanel title="Choose a tag" selectionVariant="instant" onSubmit={onSubmit}>
3131
<SelectPanel.Button leadingVisual={TagIcon}>{selectedTag || 'Choose a tag'}</SelectPanel.Button>
3232

3333
<ActionList>

0 commit comments

Comments
 (0)