-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Layout foundations] Add alpha ContentBlock component
#7255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chazdean
merged 10 commits into
layout-foundations-prototype
from
feat/add-contentblock
Sep 26, 2022
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f283f62
Add `ContentBlock`
chazdean 653d044
Update `ContentBlock` & add alpha page
chazdean 252d052
Update ContentBlock.scss
chazdean eb54120
Revert changes to `PolarisExampleWrapper`
chazdean c05a7b4
Run `get-props` script
chazdean 9afbfb0
Fix typos
chazdean 2d40291
Add changeset
chazdean dba8ce0
Add changeset for alpha component
laurkim addf054
Update ContentBlock.test.tsx
chazdean 1f1ce7b
Merge branch 'feat/add-contentblock' of https://github.com/Shopify/po…
chazdean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
polaris-react/src/components/ContentBlock/ContentBlock.scss
This file contains hidden or 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,11 @@ | ||
| .ContentBlock { | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| .medium { | ||
| max-width: 41.375rem; | ||
| } | ||
|
|
||
| .large { | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| max-width: 62.375rem; | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
polaris-react/src/components/ContentBlock/ContentBlock.stories.tsx
This file contains hidden or 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,40 @@ | ||
| import React from 'react'; | ||
| import type {ComponentMeta} from '@storybook/react'; | ||
| import {ContentBlock, Box, Text} from '@shopify/polaris'; | ||
|
|
||
| export default { | ||
| component: ContentBlock, | ||
| } as ComponentMeta<typeof ContentBlock>; | ||
|
|
||
| const placeHolder = { | ||
| background: 'var(--p-background-selected)', | ||
| borderRadius: 'var(--p-border-radius-05)', | ||
| border: '1px solid var(--p-surface-dark)', | ||
| padding: 'var(--p-space-4)', | ||
| width: '100%', | ||
| height: 'var(--p-space-32)', | ||
| }; | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export function Medium() { | ||
| return ( | ||
| <ContentBlock width="medium"> | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Box background="surface" borderRadius="2" padding="5" shadow="card"> | ||
| <Text variant="bodySm" as="h3" alignment="center"> | ||
| medium | ||
| </Text> | ||
| </Box> | ||
| </ContentBlock> | ||
| ); | ||
| } | ||
|
|
||
| export function Large() { | ||
| return ( | ||
| <ContentBlock width="large"> | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Box background="surface" borderRadius="2" padding="5" shadow="card"> | ||
| <Text variant="bodySm" as="h3" alignment="center"> | ||
| large | ||
| </Text> | ||
| </Box> | ||
| </ContentBlock> | ||
| ); | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
polaris-react/src/components/ContentBlock/ContentBlock.tsx
This file contains hidden or 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,20 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {classNames} from '../../utilities/css'; | ||
|
|
||
| import styles from './ContentBlock.scss'; | ||
|
|
||
| type Width = 'medium' | 'large'; | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export interface ContentBlockProps { | ||
| /** Elements to display inside container */ | ||
| children?: React.ReactNode; | ||
| /** Adjust maximum width of container */ | ||
| width: Width; | ||
| } | ||
|
|
||
| export const ContentBlock = ({children, width}: ContentBlockProps) => { | ||
| const className = classNames(styles.ContentBlock, styles[width]); | ||
|
|
||
| return <div className={className}>{children}</div>; | ||
| }; | ||
This file contains hidden or 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 @@ | ||
| export * from './ContentBlock'; |
27 changes: 27 additions & 0 deletions
27
polaris-react/src/components/ContentBlock/tests/ContentBlock.test.tsx
This file contains hidden or 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,27 @@ | ||
| import React from 'react'; | ||
| import {mountWithApp} from 'tests/utilities'; | ||
|
|
||
| import {ContentBlock} from '../ContentBlock'; | ||
|
|
||
| const text = 'This is a stack'; | ||
| const children = <p>{text}</p>; | ||
|
|
||
| describe('<ContentBlock />', () => { | ||
| it('renders children', () => { | ||
| const contentBlock = mountWithApp( | ||
| <ContentBlock width="medium">{children}</ContentBlock>, | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| expect(contentBlock).toContainReactComponent('p', {children: text}); | ||
| }); | ||
|
|
||
| it('renders custom properties', () => { | ||
| const contentBlock = mountWithApp( | ||
| <ContentBlock width="large">{children}</ContentBlock>, | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| expect(contentBlock).toContainReactComponent('div', { | ||
| className: expect.stringContaining('large'), | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
polaris.shopify.com/content/components/content-block/index.md
This file contains hidden or 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,15 @@ | ||
| --- | ||
| title: Content block | ||
| description: Use to create a container that centers and sets the maximum width of the content within. | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| category: Structure | ||
| keywords: | ||
| - layout | ||
| status: | ||
| value: Alpha | ||
| message: This component is in development. There could be breaking changes made to it in a non-major release of Polaris. Please use with caution. | ||
| examples: | ||
| - fileName: content-block-width.tsx | ||
| title: Width | ||
| description: >- | ||
| Use to set maximum width. | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --- | ||
28 changes: 28 additions & 0 deletions
28
polaris.shopify.com/pages/examples/content-block-width.tsx
This file contains hidden or 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,28 @@ | ||
| import React from 'react'; | ||
| import {ContentBlock, Box, Text} from '@shopify/polaris'; | ||
|
|
||
| import {withPolarisExample} from '../../src/components/PolarisExampleWrapper'; | ||
|
|
||
| function ContentBlockWidthExample() { | ||
| return ( | ||
| <div style={{width: '500px'}}> | ||
| <ContentBlock width="medium"> | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Box background="surface" borderRadius="2" padding="5" shadow="card"> | ||
| <Text variant="bodySm" as="h3" alignment="center"> | ||
| medium | ||
| </Text> | ||
| </Box> | ||
| </ContentBlock> | ||
| <br /> | ||
| <ContentBlock width="large"> | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Box background="surface" borderRadius="2" padding="5" shadow="card"> | ||
| <Text variant="bodySm" as="h3" alignment="center"> | ||
| large | ||
| </Text> | ||
| </Box> | ||
| </ContentBlock> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default withPolarisExample(ContentBlockWidthExample); | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.