Skip to content

Commit f544ef8

Browse files
vdepizzolactions-userjonrohan
authored
Make pane an optional region for PageLayout component (#1989)
* Fix PageLayout storybook example imports * Align PageLayout story spacing props with component * Fix inherit state of ..DividerWhenNarrow * Make pane an optional region of PageLayout * Stylelint auto-fixes * Create nasty-singers-compare.md Co-authored-by: Actions Auto Build <actions@github.com> Co-authored-by: Jon Rohan <yes@jonrohan.codes>
1 parent e3443f1 commit f544ef8

File tree

5 files changed

+100
-63
lines changed

5 files changed

+100
-63
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": minor
3+
---
4+
5+
Make `pane` an optional region for PageLayout component

docs/src/stories/components/Layout/LayoutBeta.stories.jsx

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export default {
9999

100100
// Pane
101101

102+
hasPane: {
103+
control: {type: 'boolean'},
104+
table: {
105+
category: 'Pane'
106+
}
107+
},
108+
102109
paneWidth: {
103110
options: ['default', 'narrow', 'wide'],
104111
control: {
@@ -275,6 +282,7 @@ export const LayoutTemplate = ({
275282
rowGap,
276283

277284
// Pane
285+
hasPane,
278286
paneWidth,
279287
panePosition,
280288
panePositionWhenNarrow,
@@ -336,20 +344,14 @@ export const LayoutTemplate = ({
336344

337345
if (hasPaneDivider) {
338346
paneDividerWhenNarrow = paneDividerWhenNarrow === 'inherit' ? 'line' : paneDividerWhenNarrow
339-
} else {
340-
paneDividerWhenNarrow = null
341347
}
342348

343349
if (hasHeaderDivider) {
344350
headerDividerWhenNarrow = headerDividerWhenNarrow === 'inherit' ? 'line' : headerDividerWhenNarrow
345-
} else {
346-
headerDividerWhenNarrow = null
347351
}
348352

349353
if (hasFooterDivider) {
350354
footerDividerWhenNarrow = footerDividerWhenNarrow === 'inherit' ? 'line' : footerDividerWhenNarrow
351-
} else {
352-
footerDividerWhenNarrow = null
353355
}
354356

355357
PageLayoutBehavior()
@@ -392,54 +394,69 @@ export const LayoutTemplate = ({
392394
</div>
393395
)}
394396

395-
<div className={clsx(layoutClassName + '-columns')}>
396-
{/* pane if rendered first */}
397-
{panePosition === 'start' && (
398-
<div
399-
className={clsx(
400-
layoutClassName + '-region',
401-
layoutClassName + '-pane',
402-
paneDividerWhenNarrow &&
403-
layoutClassName +
404-
'-region--dividerNarrow-' +
405-
paneDividerWhenNarrow +
406-
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
397+
{hasPane && (
398+
<div className={clsx(layoutClassName + '-columns')}>
399+
{/* pane if rendered first */}
400+
{panePosition === 'start' && (
401+
<div
402+
className={clsx(
403+
layoutClassName + '-region',
404+
layoutClassName + '-pane',
405+
paneDividerWhenNarrow &&
406+
layoutClassName +
407+
'-region--dividerNarrow-' +
408+
paneDividerWhenNarrow +
409+
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
410+
)}
411+
>
412+
{paneChildren}
413+
</div>
414+
)}
415+
416+
{/* content */}
417+
<div className={clsx(layoutClassName + '-region', layoutClassName + '-content')}>
418+
{contentWidth ? (
419+
<>
420+
<div className={layoutClassName + '-content-centered-' + contentWidth}>
421+
<div className={'container-' + contentWidth}>{contentChildren}</div>
422+
</div>
423+
</>
424+
) : (
425+
<>{contentChildren}</>
407426
)}
408-
>
409-
{paneChildren}
410427
</div>
411-
)}
412428

413-
{/* content */}
414-
<div className={clsx(layoutClassName + '-region', layoutClassName + '-content')}>
415-
{contentWidth ? (
416-
<>
417-
<div className={layoutClassName + '-content-centered-' + contentWidth}>
418-
<div className={'container-' + contentWidth}>{contentChildren}</div>
419-
</div>
420-
</>
421-
) : (
422-
<>{contentChildren}</>
429+
{/* pane if rendered last */}
430+
{panePosition === 'end' && (
431+
<div
432+
className={clsx(
433+
layoutClassName + '-region',
434+
layoutClassName + '-pane',
435+
paneDividerWhenNarrow &&
436+
layoutClassName +
437+
'-region--dividerNarrow-' +
438+
paneDividerWhenNarrow +
439+
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
440+
)}
441+
>
442+
{paneChildren}
443+
</div>
423444
)}
424445
</div>
425-
426-
{/* pane if rendered last */}
427-
{panePosition === 'end' && (
428-
<div
429-
className={clsx(
430-
layoutClassName + '-region',
431-
layoutClassName + '-pane',
432-
paneDividerWhenNarrow &&
433-
layoutClassName +
434-
'-region--dividerNarrow-' +
435-
paneDividerWhenNarrow +
436-
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
446+
) || (
447+
<>
448+
{/* single-column layout */}
449+
<div className={clsx(layoutClassName + '-region', layoutClassName + '-content')}>
450+
{contentWidth ? (
451+
<>
452+
<div className={'container-' + contentWidth}>{contentChildren}</div>
453+
</>
454+
) : (
455+
<>{contentChildren}</>
437456
)}
438-
>
439-
{paneChildren}
440457
</div>
441-
)}
442-
</div>
458+
</>
459+
)}
443460

444461
{/* footer */}
445462
{hasFooter && (
@@ -494,6 +511,7 @@ Playground.args = {
494511
responsiveVariant: 'stackRegions',
495512
primaryRegion: 'content',
496513

514+
hasPane: true,
497515
paneWidth: 'default',
498516
panePosition: 'end',
499517
panePositionWhenNarrow: 'inherit',

docs/src/stories/components/Layout/LayoutExamples.stories.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react'
22
import clsx from 'clsx'
33
import {PageLayoutTemplate} from './PageLayout.stories'
44
import {SplitPageLayoutTemplate} from './SplitPageLayout.stories'
5-
import {RepoSettings, DiscussionsPane, ActionListTreeViewTemplate} from '../ActionList/ActionListExamples.stories'
5+
import {ActionListTreeViewTemplate} from '../../ui-patterns/ActionList/ActionListTree.stories'
6+
import {RepoSettings, NavDiscussionsPane} from '../NavigationList/NavigationListExamples.stories'
67
import {LayoutAlphaTemplate} from './LayoutAlpha.stories'
78

89
export default {
@@ -32,7 +33,7 @@ Settings.args = {
3233
<>
3334
<h2 className="h3 ml-2 mr-2">Repository settings</h2>
3435
<div className="ml-n2 mr-n2">
35-
<NavRepoSettings {...NavRepoSettings.args} />
36+
<RepoSettings {...RepoSettings.args} />
3637
</div>
3738
</>
3839
),

docs/src/stories/components/Layout/PageLayout.stories.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default {
4141
},
4242

4343
columnGap: {
44-
options: ['normal', 'condensed'],
44+
options: ['normal', 'condensed', 'none'],
4545
control: {
4646
type: 'inline-radio'
4747
},
@@ -51,7 +51,7 @@ export default {
5151
}
5252
},
5353
rowGap: {
54-
options: ['normal', 'condensed'],
54+
options: ['normal', 'condensed', 'none'],
5555
control: {
5656
type: 'inline-radio'
5757
},
@@ -86,6 +86,13 @@ export default {
8686
},
8787

8888
// Pane
89+
90+
hasPane: {
91+
control: {type: 'boolean'},
92+
table: {
93+
category: 'Pane'
94+
}
95+
},
8996

9097
panePosition: {
9198
options: ['start', 'end'],
@@ -241,6 +248,7 @@ export const PageLayoutTemplate = ({
241248
rowGap,
242249
responsiveVariant,
243250
primaryRegion,
251+
hasPane,
244252
paneWidth,
245253
panePosition,
246254
panePositionWhenNarrow,
@@ -271,6 +279,7 @@ export const PageLayoutTemplate = ({
271279
responsiveVariant={responsiveVariant}
272280
primaryRegion={primaryRegion}
273281

282+
hasPane={hasPane}
274283
paneWidth={paneWidth}
275284
panePosition={panePosition}
276285
panePositionWhenNarrow={panePositionWhenNarrow}
@@ -315,6 +324,7 @@ Playground.args = {
315324
primaryRegion: 'content',
316325

317326
// Pane
327+
hasPane: true,
318328
panePosition: 'end',
319329
panePositionWhenNarrow: 'inherit',
320330
paneWidth: 'default',

src/layout/page-layout.scss

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,34 @@ $Layout-responsive-variant-max-breakpoint: 'md' !default;
270270
}
271271
}
272272

273+
// PageLayout-wrapper bundles header, footer, pane, and content regions
273274
.PageLayout-wrapper {
274275
display: grid;
275276
grid: auto-flow / 1fr;
276277
row-gap: var(--Layout-row-gap);
277278
}
278279

280+
// PageLayout-columns wrap pane and content regions
281+
// If layout has no pane, PageLayout-columns is not present
279282
.PageLayout-columns {
280283
display: grid;
281284
column-gap: var(--Layout-column-gap);
282285
row-gap: var(--Layout-row-gap);
283286
grid-template-columns: var(--Layout-template-columns);
284287
grid-template-rows: 1fr;
285288
grid-template-areas: var(--Layout-template-areas);
289+
290+
.PageLayout-content {
291+
// stylelint-disable-next-line primer/spacing
292+
padding-right: var(--Layout-inner-spacing-max);
293+
// stylelint-disable-next-line primer/spacing
294+
padding-left: var(--Layout-inner-spacing-max);
295+
grid-area: content;
296+
}
297+
298+
.PageLayout-pane {
299+
grid-area: pane;
300+
}
286301
}
287302

288303
// outer spacing
@@ -367,15 +382,3 @@ $Layout-responsive-variant-max-breakpoint: 'md' !default;
367382
// stylelint-disable-next-line primer/spacing
368383
padding: var(--Layout-inner-spacing-min);
369384
}
370-
371-
.PageLayout-content {
372-
// stylelint-disable-next-line primer/spacing
373-
padding-right: var(--Layout-inner-spacing-max);
374-
// stylelint-disable-next-line primer/spacing
375-
padding-left: var(--Layout-inner-spacing-max);
376-
grid-area: content;
377-
}
378-
379-
.PageLayout-pane {
380-
grid-area: pane;
381-
}

0 commit comments

Comments
 (0)