-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PageBlock: Add new component (#1307)
- Loading branch information
1 parent
e5e671f
commit 042b841
Showing
13 changed files
with
323 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
'braid-design-system': minor | ||
--- | ||
|
||
--- | ||
new: | ||
- PageBlock | ||
--- | ||
|
||
**PageBlock:** Add new component | ||
|
||
Provides a top-level page container, constraining the content width (using `ContentBlock`) while establishing common screen gutters on smaller devices. | ||
|
||
**EXAMPLE USAGE:** | ||
```jsx | ||
<PageBlock width="large"> | ||
... | ||
</PageBlock> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/braid-design-system/src/lib/components/PageBlock/PageBlock.docs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React, { Fragment } from 'react'; | ||
import type { ComponentDocs } from 'site/types'; | ||
import { Placeholder } from '../private/Placeholder/Placeholder'; | ||
import { Box, PageBlock, TextLink } from '../'; | ||
import source from '../../utils/source.macro'; | ||
import { Strong } from '../Strong/Strong'; | ||
import { Text } from '../Text/Text'; | ||
import { gutters, validPageBlockComponents } from './PageBlock'; | ||
|
||
const docs: ComponentDocs = { | ||
category: 'Layout', | ||
migrationGuide: true, | ||
Example: () => | ||
source( | ||
<PageBlock width="medium"> | ||
<Placeholder height={100} /> | ||
</PageBlock>, | ||
), | ||
description: ( | ||
<Text> | ||
Provides a top-level page container, constraining the content width (using{' '} | ||
<TextLink href="/components/ContentBlock">ContentBlock</TextLink>) while | ||
establishing common screen gutters on smaller devices. | ||
</Text> | ||
), | ||
alternatives: [ | ||
{ | ||
name: 'ContentBlock', | ||
description: 'For controlled width layout blocks', | ||
}, | ||
], | ||
additional: [ | ||
{ | ||
label: 'Maximum width', | ||
description: ( | ||
<Text> | ||
Use the <Strong>width</Strong> prop to adjust the maximum width of the | ||
page container. Choose from either <Strong>medium</Strong> or{' '} | ||
<Strong>large</Strong>. | ||
</Text> | ||
), | ||
Example: () => | ||
source( | ||
<PageBlock width="medium"> | ||
<Placeholder height={100} /> | ||
</PageBlock>, | ||
), | ||
}, | ||
{ | ||
label: 'Screen gutters', | ||
description: ( | ||
<> | ||
<Text> | ||
Establishes consistent responsive gutters between the content and | ||
the screen edge. | ||
</Text> | ||
<Text> | ||
Uses <Strong>{gutters.mobile}</Strong> space on{' '} | ||
<TextLink href="/css/breakpoints">mobile</TextLink> and the semantic{' '} | ||
<Strong>{gutters.tablet}</Strong> on{' '} | ||
<TextLink href="/css/breakpoints">tablet</TextLink> and above. | ||
</Text> | ||
</> | ||
), | ||
playroom: false, | ||
code: false, | ||
Example: () => | ||
source( | ||
<Box background="formAccent"> | ||
<PageBlock width="medium"> | ||
<Box background="surface"> | ||
<Placeholder height={100} /> | ||
</Box> | ||
</PageBlock> | ||
</Box>, | ||
), | ||
}, | ||
|
||
{ | ||
label: 'Custom semantics', | ||
description: ( | ||
<Text> | ||
The HTML tag can be customised to ensure the underlying document | ||
semantics are meaningful. This can be done using the{' '} | ||
<Strong>component</Strong> prop and supports{' '} | ||
{validPageBlockComponents.map((c, i) => { | ||
const notLastTwo = validPageBlockComponents.length - 2; | ||
const joiningLastElements = i === notLastTwo ? ' and ' : '.'; | ||
|
||
return ( | ||
<Fragment key={c}> | ||
<Strong>{c}</Strong> | ||
{c === 'div' ? ' (default)' : ''} | ||
{i < notLastTwo ? ', ' : joiningLastElements} | ||
</Fragment> | ||
); | ||
})} | ||
</Text> | ||
), | ||
}, | ||
], | ||
}; | ||
|
||
export default docs; |
26 changes: 26 additions & 0 deletions
26
packages/braid-design-system/src/lib/components/PageBlock/PageBlock.gallery.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import type { ComponentExample } from 'site/types'; | ||
import { Placeholder } from '../private/Placeholder/Placeholder'; | ||
import { PageBlock } from '../'; | ||
import source from '../../utils/source.macro'; | ||
|
||
export const galleryItems: ComponentExample[] = [ | ||
{ | ||
label: 'Medium width', | ||
Example: () => | ||
source( | ||
<PageBlock width="medium"> | ||
<Placeholder height={100} /> | ||
</PageBlock>, | ||
), | ||
}, | ||
{ | ||
label: 'Large width', | ||
Example: () => | ||
source( | ||
<PageBlock width="large"> | ||
<Placeholder height={100} /> | ||
</PageBlock>, | ||
), | ||
}, | ||
]; |
34 changes: 34 additions & 0 deletions
34
packages/braid-design-system/src/lib/components/PageBlock/PageBlock.screenshots.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import type { ComponentScreenshot } from 'site/types'; | ||
import { Placeholder } from '../private/Placeholder/Placeholder'; | ||
import { PageBlock } from '../'; | ||
|
||
export const screenshots: ComponentScreenshot = { | ||
screenshotWidths: [320, 1200], | ||
examples: [ | ||
{ | ||
label: 'Default', | ||
Example: () => ( | ||
<PageBlock> | ||
<Placeholder height={100} /> | ||
</PageBlock> | ||
), | ||
}, | ||
{ | ||
label: 'Medium', | ||
Example: () => ( | ||
<PageBlock width="medium"> | ||
<Placeholder height={100} /> | ||
</PageBlock> | ||
), | ||
}, | ||
{ | ||
label: 'Large', | ||
Example: () => ( | ||
<PageBlock width="large"> | ||
<Placeholder height={100} /> | ||
</PageBlock> | ||
), | ||
}, | ||
], | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/braid-design-system/src/lib/components/PageBlock/PageBlock.snippets.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import type { Snippets } from '../private/Snippets'; | ||
import { PageBlock, Placeholder } from '../../playroom/components'; | ||
import source from '../../utils/source.macro'; | ||
|
||
export const snippets: Snippets = [ | ||
{ | ||
name: 'Medium', | ||
code: source( | ||
<PageBlock width="medium"> | ||
<Placeholder height={100} /> | ||
</PageBlock>, | ||
), | ||
}, | ||
{ | ||
name: 'Large', | ||
code: source( | ||
<PageBlock width="large"> | ||
<Placeholder height={100} /> | ||
</PageBlock>, | ||
), | ||
}, | ||
]; |
50 changes: 50 additions & 0 deletions
50
packages/braid-design-system/src/lib/components/PageBlock/PageBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { type ReactNode } from 'react'; | ||
import { | ||
ContentBlock, | ||
type ContentBlockProps, | ||
} from '../ContentBlock/ContentBlock'; | ||
import { Box } from '../Box/Box'; | ||
import buildDataAttributes, { | ||
type DataAttributeMap, | ||
} from '../private/buildDataAttributes'; | ||
|
||
export const validPageBlockComponents = [ | ||
'div', | ||
'article', | ||
'aside', | ||
'main', | ||
'section', | ||
'nav', | ||
] as const; | ||
|
||
export const gutters = { mobile: 'xsmall', tablet: 'gutter' } as const; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
width?: Extract<ContentBlockProps['width'], 'medium' | 'large'>; | ||
component?: (typeof validPageBlockComponents)[number]; | ||
data?: DataAttributeMap; | ||
} | ||
|
||
export const PageBlock = ({ | ||
children, | ||
width = 'large', | ||
component: componentProp, | ||
data, | ||
...restProps | ||
}: Props) => { | ||
const component = | ||
componentProp && validPageBlockComponents.includes(componentProp) | ||
? componentProp | ||
: 'div'; | ||
|
||
return ( | ||
<Box | ||
component={component} | ||
paddingX={gutters} | ||
{...buildDataAttributes({ data, validateRestProps: restProps })} | ||
> | ||
<ContentBlock width={width}>{children}</ContentBlock> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.