Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strange-starfishes-work.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

experimental/SelectPanel: Automatically adjust height based on contents
2 changes: 1 addition & 1 deletion packages/react/src/Overlay/Overlay.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ type StyledOverlayProps = {
anchorSide?: AnchorSide
} & SxProp

const heightMap = {
export const heightMap = {
xsmall: '192px',
small: '256px',
medium: '320px',
Expand Down
16 changes: 12 additions & 4 deletions packages/react/src/drafts/SelectPanel2/SelectPanel.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ import {ActionListContainerContext} from '../../ActionList/ActionListContainerCo
import {useSlots} from '../../hooks/useSlots'
import {useProvidedRefOrCreate, useId, useAnchoredPosition} from '../../hooks'
import {useFocusZone} from '../../hooks/useFocusZone'
import {StyledOverlay, OverlayProps} from '../../Overlay/Overlay'
import {StyledOverlay, OverlayProps, heightMap} from '../../Overlay/Overlay'
import InputLabel from '../../internal/components/InputLabel'
import {invariant} from '../../utils/invariant'

Expand DownExpand Up@@ -65,7 +65,8 @@ export type SelectPanelProps = {

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

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

width = 'medium',
height = 'large',
maxHeight = 'large',
...props
}) => {
const [internalOpen, setInternalOpen] = React.useState(defaultOpen)
Expand DownExpand Up@@ -229,8 +230,10 @@ const Panel: React.FC<SelectPanelProps> = ({
aria-labelledby={`${panelId}--title`}
aria-describedby={description ? `${panelId}--description` : undefined}
width={width}
height={height}
height="fit-content"
maxHeight={maxHeight}
sx={{
'--max-height': heightMap[maxHeight],
// reset dialog default styles
border: 'none',
padding: 0,
Expand DownExpand Up@@ -433,6 +436,7 @@ const SelectPanelFooter = ({...props}) => {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
flexShrink: 0,
padding: hidePrimaryActions ? 2 : 3,
minHeight: '44px',
borderTop: '1px solid',
Expand DownExpand Up@@ -518,6 +522,8 @@ const SelectPanelLoading: React.FC<{children: string}> = ({children = 'Fetching
alignItems: 'center',
height: '100%',
gap: 3,
minHeight: 'min(calc(var(--max-height) - 150px), 324px)',
// maxHeight of dialog - (header & footer)
}}
>
<Spinner size="medium" />
Expand DownExpand Up@@ -560,6 +566,8 @@ const SelectPanelMessage: React.FC<SelectPanelMessageProps> = ({
paddingX: 4,
textAlign: 'center',
a: {color: 'inherit', textDecoration: 'underline'},
minHeight: 'min(calc(var(--max-height) - 150px), 324px)',
// maxHeight of dialog - (header & footer)
}}
>
{variant !== 'empty' ? (
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -439,7 +439,6 @@ export const OpenFromMenu = () => {
variant="modal"
title="Custom"
open={selectPanelOpen}
height="medium"
onSubmit={() => {
setSelectedSetting('Custom')
setSelectPanelOpen(false)
Expand DownExpand Up@@ -603,7 +602,7 @@ export const ShortSelectPanel = () => {
<p>
Use <code>height=fit-content</code> to match height of contents
</p>
<SelectPanel title="Select notification channels" height="fit-content" onSubmit={onSubmit}>
<SelectPanel title="Select notification channels" onSubmit={onSubmit}>
<SelectPanel.Button>
<Text sx={{color: 'fg.muted'}}>Notify me:</Text>{' '}
{Object.keys(channels)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,7 @@ export const InstantSelectionVariant = () => {
<>
<h1>Instant selection variant</h1>

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

<ActionList>
Expand Down