Skip to content

Commit

Permalink
PageLayout component / Layout beta + storybook (#1737)
Browse files Browse the repository at this point in the history
* storybook for layout alpha

* the beginning of layout beta

* simplify spacing structure and other things

this is a reminder that all the abstraction can happen in the viewComponent;
there's no need to flood the css with constricted behaviors

* add rowGap & dividers, clean spacing props

* content-width support, sticky pane

* cleanup props

* add preset property

* !default

* component name & settings example

* typo, cleaner header & footer template

* fix preset options

* mobile-friendly responsive behavior

* ongoing flowVertical breakpoint behavior

* finish panePosition + responsive pos & dividers

* panePosition fix

* add splitAsPage, finish responsive divider

* Layout beta ongoing updates (#1779)

- simplify component with better names
- rename it to `PageLayout`
- stylelint cleanup
- finalize responsive variants
- finalize variant-specific region dividers

* add minimum 320px viewport

* fix layout alpha, add layout patterns

* cleanup bg colors, stylint pass

* enable debug bg colors

* colorful regions by default for dubugging

* "Needless disable for primer/no-undefined-vars"

* Stylelint auto-fixes

* line breaks a EOF

* introduce page layout behavior as a sb helper

* children props in specialized components

* cleanup

* typo

* discussions responsive temporary example

* layout alpha descriptions

* pageLayout prop descriptions

* cleanup

* fix conflict

* copy

* responsiveVariant storybook description

* 0 padding on fullscreen storybook layout

* has__divider for boolean props

* cleanup, copy

* cleanup

* cleanup

* cleanup chained selections/descendants

* Stylelint auto-fixes

* inherit values for responsive divider props

* consolidate modifier names for responsive props

Changelog:

### CSS classes
- `PageLayout--variant-stackRegions` → `PageLayout--responsive-stackRegions`
- `PageLayout--variant-separateRegions` → `PageLayout--responsive-separateRegions`
- `PageLayout--variant-stackRegions-panePos-*` →`PageLayout--responsive-panePos-*`
- `PageLayout--variant-separateRegions-primary-*` →`PageLayout--responsive-primary-*`
- `PageLayout-region--hasDivider-*` → `PageLayout-region--dividerNarrow-*`

### Prop names
- `responsivePrimaryRegion` → `primaryRegion`
- `paneResponsivePosition` → `panePositionNarrow`
- `paneResponsiveDivider` → `paneDividerNarrow`
- `headerResponsiveDivider`→ `headerDividerNarrow`
- `footerResponsiveDivider`→ `footerDividerNarrow`

### Args
- `*DividerNarrow` props have new `inherit` value by default

* Create lemon-games-swim.md

* Update lemon-games-swim.md

* cleanup, header+footer dividers as local modifiers

* hasFooterDivider instead of footerDivider

* fix primaryRegion selector

Co-authored-by: Actions Auto Build <actions@github.com>
Co-authored-by: Katie Langerman <langermank@github.com>
  • Loading branch information
3 people committed Dec 21, 2021
1 parent 995d790 commit 6b4089d
Show file tree
Hide file tree
Showing 15 changed files with 2,091 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-games-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": minor
---

Adds new PageLayout component CSS with Storybook documentation
4 changes: 4 additions & 0 deletions docs/.storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
margin: -1rem;
}

.sb-main-fullscreen .theme-wrap .story-wrap {
padding: 0;
}

.sb-main-padded div:not(.theme-wrap) > [data-dark-theme] {
margin: -1rem;
padding: 1rem;
Expand Down
7 changes: 7 additions & 0 deletions docs/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import renderToHTML from '../src/stories/helpers/code-snippet-html-helper'
const customViewports = {
minXS: {
name: 'XS (min)',
styles: {
width: '320px',
height: '100%'
}
},
medXS: {
name: 'XS (med)',
styles: {
width: '375px',
height: '100%'
Expand Down
257 changes: 257 additions & 0 deletions docs/src/stories/components/ActionList/ActionListExamples.stories.jsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ NavWithSubItemsLeadingVisual16px.args = {
children={
<ListTemplate
subGroup
ariaLabel="Sub nav descrioption"
ariaLabel="Sub nav decription"
children={
<>
<ListItemTemplate subItem text="Sub Nav Item" href="/" listSemantic ariaLevel="2" />
Expand Down Expand Up @@ -236,7 +236,7 @@ NavWithSubItemsLeadingVisual20px.args = {
children={
<ListTemplate
subGroup
ariaLabel="Sub nav descrioption"
ariaLabel="Sub nav decription"
children={
<>
<ListItemTemplate subItem text="Sub Nav Item" href="/" listSemantic ariaLevel="2" />
Expand Down Expand Up @@ -328,7 +328,7 @@ NavWithSubItemsLeadingVisual24px.args = {
children={
<ListTemplate
subGroup
ariaLabel="Sub nav descrioption"
ariaLabel="Sub nav decription"
children={
<>
<ListItemTemplate subItem text="Sub Nav Item" href="/" listSemantic ariaLevel="2" />
Expand Down Expand Up @@ -671,7 +671,7 @@ NavWithSubItemsLeadingVisual16pxSubSections.args = {
<ListTemplate
subGroup
ariaLabelledBy="group-id-1"
ariaLabel="Sub nav descrioption"
ariaLabel="Sub nav decription"
children={
<>
<ListItemTemplate
Expand Down Expand Up @@ -701,7 +701,7 @@ NavWithSubItemsLeadingVisual16pxSubSections.args = {
containsSubItem
containsActiveSubItem
subGroup
ariaLabel="Sub nav descrioption"
ariaLabel="Sub nav decription"
children={
<>
<ListItemTemplate
Expand Down Expand Up @@ -740,7 +740,7 @@ NavWithSubItemsLeadingVisual16pxSubSections.args = {
children={
<ListTemplate
subGroup
ariaLabel="Sub nav descrioption"
ariaLabel="Sub nav decription"
ariaLabelledBy="group-id-2"
children={
<>
Expand Down
204 changes: 204 additions & 0 deletions docs/src/stories/components/Layout/LayoutAlpha.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import React from 'react'
import clsx from 'clsx'

export default {
title: 'Components/Layout/Alpha',
excludeStories: ['LayoutAlphaTemplate'],
argTypes: {
container: {
control: { type: 'select' },
options: ['fluid', 'md', 'lg', 'xl'],
control: {
type: 'inline-radio'
},
description: 'Wrapper around the entire component to define an optional maximum width.',
table: {
category: 'CSS'
}
},
hasDivider: {
control: { type: 'boolean' },
description: 'Whether to show a pane line divider.',
table: {
category: 'CSS'
}
},
gutter: {
options: ['default', 'none', 'condensed', 'spacious'],
control: {
type: 'inline-radio'
},
description: 'Sets the gap between columns.',
table: {
category: 'CSS'
}
},
sidebarPosition: {
options: ['start', 'end'],
control: {
type: 'inline-radio'
},
description: 'Sets the position of the sidebar.',
table: {
category: 'CSS'
}
},
sidebarWidth: {
options: ['default', 'narrow', 'wide'],
control: {
type: 'inline-radio'
},
description: 'Sets the width of the sidebar.',
table: {
category: 'CSS'
}
},
mainWidth: {
options: ['fluid', 'md', 'lg', 'xl'],
control: {
type: 'inline-radio'
},
description: 'Sets the width of the main content area.',
table: {
category: 'CSS'
}
},
flowRowUntil: {
options: ['sm', 'md', 'lg'],
control: {
type: 'inline-radio',
},
description: 'Sets the maximum breakpoint at which the layout will flow as row.',
table: {
category: 'CSS'
}
},
mainChildren: {
description: 'creates a slot for main children',
table: {
category: 'HTML'
}
},
sidebarChildren: {
description: 'creates a slot for sidebar children',
table: {
category: 'HTML'
}
},
}
}

// build every component case here in the template (private api)
export const LayoutAlphaTemplate = ({
container,
hasDivider,
gutter,
sidebarPosition,
sidebarWidth,
mainWidth,
flowRowUntil,
mainChildren,
sidebarChildren
}) => {

// Default values
container = container ?? 'xl';
hasDivider = hasDivider ?? false;
gutter = gutter ?? 'default';
sidebarPosition = sidebarPosition ?? 'end';
sidebarWidth = sidebarWidth ?? 'default';
mainWidth = mainWidth ?? 'full';
flowRowUntil = flowRowUntil ?? 'md';

// Leave `null` values for states that don't require a modifier class
container = (container === 'full') ? null : container;
hasDivider = (hasDivider === false) ? null : hasDivider;
gutter = (gutter === 'default') ? null : gutter;
sidebarWidth = (sidebarWidth === 'default') ? null : sidebarWidth;
mainWidth = (mainWidth === 'full') ? null : mainWidth;
flowRowUntil = (flowRowUntil === 'sm') ? null : flowRowUntil;

return (
<div
// use clsx for multiple classnames
className={clsx(
'Layout',
container && 'container-' + `${container}`,
gutter && 'Layout--gutter-' + `${gutter}`,
sidebarPosition && 'Layout--sidebarPosition-' + `${sidebarPosition}`,
sidebarWidth && 'Layout--sidebar-' + `${sidebarWidth}`,
hasDivider && 'Layout--divided',
flowRowUntil && '' + 'Layout--flowRow-until-' + `${flowRowUntil}`
)}
// use undefined for values that shouldn't be set if false
aria-hidden={hasDivider ? 'true' : undefined}
>
{/* use {children} for wrapper component templates */}
<>
<div className="Layout-main">
{mainWidth ? (
<>
<div className={'Layout-main-centered-' + mainWidth}>
<div className={clsx( mainWidth && 'container-' + mainWidth)}>
{mainChildren}
</div>
</div>
</>
) : (
<>
{mainChildren}
</>
)}
</div>
<div className="Layout-divider"></div>
<div className="Layout-sidebar">{sidebarChildren}</div>
</>
</div>
);
};

const sidebarPlaceholder =
<>
<div style={
{
width: '100%',
height: '100%',
backgroundColor: '#DDF4FF',
border: '1px solid #80CCFF',
padding: '16px',
borderRadius: '6px'
}
}>
sidebar
</div>
</>;

const mainPlaceholder =
<>
<div style={
{
width: '100%',
height: '100%',
backgroundColor: '#FFEFF7',
border: '1px solid #FFADDA',
padding: '16px',
borderRadius: '6px'
}
}>
main
</div>
</>;

// create a "playground" demo page that may set some defaults and allow story to access component controls
export const Playground = LayoutAlphaTemplate.bind({})
Playground.args = {
container: 'full',
hasDivider: false,
gutter: 'default',
sidebarPosition: 'end',
sidebarWidth: 'default',
mainWidth: 'full',
flowRowUntil: 'md',
mainChildren: mainPlaceholder,
sidebarChildren: sidebarPlaceholder
}
Loading

0 comments on commit 6b4089d

Please sign in to comment.