Skip to content

Commit

Permalink
Make pane an optional region for PageLayout component (#1989)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Mar 14, 2022
1 parent e3443f1 commit f544ef8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-singers-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": minor
---

Make `pane` an optional region for PageLayout component
112 changes: 65 additions & 47 deletions docs/src/stories/components/Layout/LayoutBeta.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export default {

// Pane

hasPane: {
control: {type: 'boolean'},
table: {
category: 'Pane'
}
},

paneWidth: {
options: ['default', 'narrow', 'wide'],
control: {
Expand Down Expand Up @@ -275,6 +282,7 @@ export const LayoutTemplate = ({
rowGap,

// Pane
hasPane,
paneWidth,
panePosition,
panePositionWhenNarrow,
Expand Down Expand Up @@ -336,20 +344,14 @@ export const LayoutTemplate = ({

if (hasPaneDivider) {
paneDividerWhenNarrow = paneDividerWhenNarrow === 'inherit' ? 'line' : paneDividerWhenNarrow
} else {
paneDividerWhenNarrow = null
}

if (hasHeaderDivider) {
headerDividerWhenNarrow = headerDividerWhenNarrow === 'inherit' ? 'line' : headerDividerWhenNarrow
} else {
headerDividerWhenNarrow = null
}

if (hasFooterDivider) {
footerDividerWhenNarrow = footerDividerWhenNarrow === 'inherit' ? 'line' : footerDividerWhenNarrow
} else {
footerDividerWhenNarrow = null
}

PageLayoutBehavior()
Expand Down Expand Up @@ -392,54 +394,69 @@ export const LayoutTemplate = ({
</div>
)}

<div className={clsx(layoutClassName + '-columns')}>
{/* pane if rendered first */}
{panePosition === 'start' && (
<div
className={clsx(
layoutClassName + '-region',
layoutClassName + '-pane',
paneDividerWhenNarrow &&
layoutClassName +
'-region--dividerNarrow-' +
paneDividerWhenNarrow +
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
{hasPane && (
<div className={clsx(layoutClassName + '-columns')}>
{/* pane if rendered first */}
{panePosition === 'start' && (
<div
className={clsx(
layoutClassName + '-region',
layoutClassName + '-pane',
paneDividerWhenNarrow &&
layoutClassName +
'-region--dividerNarrow-' +
paneDividerWhenNarrow +
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
)}
>
{paneChildren}
</div>
)}

{/* content */}
<div className={clsx(layoutClassName + '-region', layoutClassName + '-content')}>
{contentWidth ? (
<>
<div className={layoutClassName + '-content-centered-' + contentWidth}>
<div className={'container-' + contentWidth}>{contentChildren}</div>
</div>
</>
) : (
<>{contentChildren}</>
)}
>
{paneChildren}
</div>
)}

{/* content */}
<div className={clsx(layoutClassName + '-region', layoutClassName + '-content')}>
{contentWidth ? (
<>
<div className={layoutClassName + '-content-centered-' + contentWidth}>
<div className={'container-' + contentWidth}>{contentChildren}</div>
</div>
</>
) : (
<>{contentChildren}</>
{/* pane if rendered last */}
{panePosition === 'end' && (
<div
className={clsx(
layoutClassName + '-region',
layoutClassName + '-pane',
paneDividerWhenNarrow &&
layoutClassName +
'-region--dividerNarrow-' +
paneDividerWhenNarrow +
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
)}
>
{paneChildren}
</div>
)}
</div>

{/* pane if rendered last */}
{panePosition === 'end' && (
<div
className={clsx(
layoutClassName + '-region',
layoutClassName + '-pane',
paneDividerWhenNarrow &&
layoutClassName +
'-region--dividerNarrow-' +
paneDividerWhenNarrow +
(panePositionWhenNarrow === 'start' ? '-after' : '-before')
) || (
<>
{/* single-column layout */}
<div className={clsx(layoutClassName + '-region', layoutClassName + '-content')}>
{contentWidth ? (
<>
<div className={'container-' + contentWidth}>{contentChildren}</div>
</>
) : (
<>{contentChildren}</>
)}
>
{paneChildren}
</div>
)}
</div>
</>
)}

{/* footer */}
{hasFooter && (
Expand Down Expand Up @@ -494,6 +511,7 @@ Playground.args = {
responsiveVariant: 'stackRegions',
primaryRegion: 'content',

hasPane: true,
paneWidth: 'default',
panePosition: 'end',
panePositionWhenNarrow: 'inherit',
Expand Down
5 changes: 3 additions & 2 deletions docs/src/stories/components/Layout/LayoutExamples.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react'
import clsx from 'clsx'
import {PageLayoutTemplate} from './PageLayout.stories'
import {SplitPageLayoutTemplate} from './SplitPageLayout.stories'
import {RepoSettings, DiscussionsPane, ActionListTreeViewTemplate} from '../ActionList/ActionListExamples.stories'
import {ActionListTreeViewTemplate} from '../../ui-patterns/ActionList/ActionListTree.stories'
import {RepoSettings, NavDiscussionsPane} from '../NavigationList/NavigationListExamples.stories'
import {LayoutAlphaTemplate} from './LayoutAlpha.stories'

export default {
Expand Down Expand Up @@ -32,7 +33,7 @@ Settings.args = {
<>
<h2 className="h3 ml-2 mr-2">Repository settings</h2>
<div className="ml-n2 mr-n2">
<NavRepoSettings {...NavRepoSettings.args} />
<RepoSettings {...RepoSettings.args} />
</div>
</>
),
Expand Down
14 changes: 12 additions & 2 deletions docs/src/stories/components/Layout/PageLayout.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
},

columnGap: {
options: ['normal', 'condensed'],
options: ['normal', 'condensed', 'none'],
control: {
type: 'inline-radio'
},
Expand All @@ -51,7 +51,7 @@ export default {
}
},
rowGap: {
options: ['normal', 'condensed'],
options: ['normal', 'condensed', 'none'],
control: {
type: 'inline-radio'
},
Expand Down Expand Up @@ -86,6 +86,13 @@ export default {
},

// Pane

hasPane: {
control: {type: 'boolean'},
table: {
category: 'Pane'
}
},

panePosition: {
options: ['start', 'end'],
Expand Down Expand Up @@ -241,6 +248,7 @@ export const PageLayoutTemplate = ({
rowGap,
responsiveVariant,
primaryRegion,
hasPane,
paneWidth,
panePosition,
panePositionWhenNarrow,
Expand Down Expand Up @@ -271,6 +279,7 @@ export const PageLayoutTemplate = ({
responsiveVariant={responsiveVariant}
primaryRegion={primaryRegion}

hasPane={hasPane}
paneWidth={paneWidth}
panePosition={panePosition}
panePositionWhenNarrow={panePositionWhenNarrow}
Expand Down Expand Up @@ -315,6 +324,7 @@ Playground.args = {
primaryRegion: 'content',

// Pane
hasPane: true,
panePosition: 'end',
panePositionWhenNarrow: 'inherit',
paneWidth: 'default',
Expand Down
27 changes: 15 additions & 12 deletions src/layout/page-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,34 @@ $Layout-responsive-variant-max-breakpoint: 'md' !default;
}
}

// PageLayout-wrapper bundles header, footer, pane, and content regions
.PageLayout-wrapper {
display: grid;
grid: auto-flow / 1fr;
row-gap: var(--Layout-row-gap);
}

// PageLayout-columns wrap pane and content regions
// If layout has no pane, PageLayout-columns is not present
.PageLayout-columns {
display: grid;
column-gap: var(--Layout-column-gap);
row-gap: var(--Layout-row-gap);
grid-template-columns: var(--Layout-template-columns);
grid-template-rows: 1fr;
grid-template-areas: var(--Layout-template-areas);

.PageLayout-content {
// stylelint-disable-next-line primer/spacing
padding-right: var(--Layout-inner-spacing-max);
// stylelint-disable-next-line primer/spacing
padding-left: var(--Layout-inner-spacing-max);
grid-area: content;
}

.PageLayout-pane {
grid-area: pane;
}
}

// outer spacing
Expand Down Expand Up @@ -367,15 +382,3 @@ $Layout-responsive-variant-max-breakpoint: 'md' !default;
// stylelint-disable-next-line primer/spacing
padding: var(--Layout-inner-spacing-min);
}

.PageLayout-content {
// stylelint-disable-next-line primer/spacing
padding-right: var(--Layout-inner-spacing-max);
// stylelint-disable-next-line primer/spacing
padding-left: var(--Layout-inner-spacing-max);
grid-area: content;
}

.PageLayout-pane {
grid-area: pane;
}

0 comments on commit f544ef8

Please sign in to comment.