Skip to content

Commit c0cbdd0

Browse files
authored
Add minWidth prop to PageLayout.Pane (#3229)
* Add minWidth prop to PageLayout.Pane * Create late-wombats-switch.md * Update generated/components.json * Update playground stories --------- Co-authored-by: colebemis <[email protected]>
1 parent 66995dc commit c0cbdd0

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

.changeset/late-wombats-switch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Add `minWidth prop to `PageLayout.Pane` and `SplitPageLayout.Pane`

generated/components.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,12 @@
27232723
"defaultValue": "'medium'",
27242724
"description": "The width of the pane."
27252725
},
2726+
{
2727+
"name": "minWidth",
2728+
"type": "number",
2729+
"defaultValue": "256",
2730+
"description": "The minimum width of the pane."
2731+
},
27262732
{
27272733
"name": "resizable",
27282734
"type": "boolean",
@@ -3720,6 +3726,12 @@
37203726
"defaultValue": "'medium'",
37213727
"description": "The width of the pane."
37223728
},
3729+
{
3730+
"name": "minWidth",
3731+
"type": "number",
3732+
"defaultValue": "256",
3733+
"description": "The minimum width of the pane."
3734+
},
37233735
{
37243736
"name": "resizable",
37253737
"type": "boolean",

src/PageLayout/PageLayout.docs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@
152152
"defaultValue": "'medium'",
153153
"description": "The width of the pane."
154154
},
155+
{
156+
"name": "minWidth",
157+
"type": "number",
158+
"defaultValue": "256",
159+
"description": "The minimum width of the pane."
160+
},
155161
{
156162
"name": "resizable",
157163
"type": "boolean",

src/PageLayout/PageLayout.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ const meta: Meta = {
238238
control: {type: 'radio'},
239239
table: {category: 'Pane props'},
240240
},
241+
'Pane.minWidth': {
242+
type: 'number',
243+
defaultValue: 256,
244+
table: {category: 'Pane props'},
245+
},
241246
'Pane.sticky': {
242247
type: 'boolean',
243248
table: {category: 'Pane props'},
@@ -383,6 +388,7 @@ const Template: Story = args => (
383388
wide: args['Pane.position.wide'],
384389
}}
385390
width={args['Pane.width']}
391+
minWidth={args['Pane.minWidth']}
386392
sticky={args['Pane.sticky']}
387393
resizable={args['Pane.resizable']}
388394
padding={args['Pane.padding']}

src/PageLayout/PageLayout.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,11 @@ export type PageLayoutPaneProps = {
482482
* position={{regular: 'start', narrow: 'end'}}
483483
* ```
484484
*/
485+
positionWhenNarrow?: 'inherit' | keyof typeof panePositions
485486
'aria-labelledby'?: string
486487
'aria-label'?: string
487-
positionWhenNarrow?: 'inherit' | keyof typeof panePositions
488488
width?: keyof typeof paneWidths
489+
minWidth?: number
489490
resizable?: boolean
490491
widthStorageKey?: string
491492
padding?: keyof typeof SPACING_MAP
@@ -532,6 +533,7 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
532533
position: responsivePosition = 'end',
533534
positionWhenNarrow = 'inherit',
534535
width = 'medium',
536+
minWidth = 256,
535537
padding = 'none',
536538
resizable = false,
537539
widthStorageKey = 'paneWidth',
@@ -603,7 +605,6 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
603605
const paneRef = React.useRef<HTMLDivElement>(null)
604606
useRefObjectAsForwardedRef(forwardRef, paneRef)
605607

606-
const MIN_PANE_WIDTH = 256 // 256px, related to `--pane-min-width CSS var.
607608
const [minPercent, setMinPercent] = React.useState(0)
608609
const [maxPercent, setMaxPercent] = React.useState(0)
609610
const hasOverflow = useOverflow(paneRef)
@@ -618,7 +619,7 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
618619
const viewportWidth = window.innerWidth
619620
const maxPaneWidth = viewportWidth > maxPaneWidthDiff ? viewportWidth - maxPaneWidthDiff : viewportWidth
620621

621-
const minPercent = Math.round((100 * MIN_PANE_WIDTH) / viewportWidth)
622+
const minPercent = Math.round((100 * minWidth) / viewportWidth)
622623
setMinPercent(minPercent)
623624

624625
const maxPercent = Math.round((100 * maxPaneWidth) / viewportWidth)
@@ -627,7 +628,7 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
627628
const widthPercent = Math.round((100 * paneWidth) / viewportWidth)
628629
setWidthPercent(widthPercent.toString())
629630
}
630-
}, [paneRef])
631+
}, [paneRef, minWidth])
631632

632633
const [widthPercent, setWidthPercent] = React.useState('')
633634
const [prevPercent, setPrevPercent] = React.useState('')
@@ -742,7 +743,7 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
742743
'--pane-width': `${paneWidth}px`,
743744
}}
744745
sx={(theme: Theme) => ({
745-
'--pane-min-width': `256px`,
746+
'--pane-min-width': `${minWidth}px`,
746747
'--pane-max-width-diff': '511px',
747748
'--pane-max-width': `calc(100vw - var(--pane-max-width-diff))`,
748749
width: resizable

src/SplitPageLayout/SplitPageLayout.docs.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
"defaultValue": "'medium'",
8181
"description": "The width of the pane."
8282
},
83+
{
84+
"name": "minWidth",
85+
"type": "number",
86+
"defaultValue": "256",
87+
"description": "The minimum width of the pane."
88+
},
8389
{
8490
"name": "resizable",
8591
"type": "boolean",
@@ -156,4 +162,4 @@
156162
]
157163
}
158164
]
159-
}
165+
}

src/SplitPageLayout/SplitPageLayout.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ export default {
189189
control: {type: 'radio'},
190190
table: {category: 'Pane props'},
191191
},
192+
'Pane.minWidth': {
193+
type: 'number',
194+
defaultValue: 256,
195+
table: {category: 'Pane props'},
196+
},
192197
'Pane.sticky': {
193198
type: 'boolean',
194199
defaultValue: true,
@@ -342,6 +347,7 @@ const Template: Story = args => (
342347
wide: args['Pane.position.wide'],
343348
}}
344349
width={args['Pane.width']}
350+
minWidth={args['Pane.minWidth']}
345351
sticky={args['Pane.sticky']}
346352
padding={args['Pane.padding']}
347353
divider={{

0 commit comments

Comments
 (0)