Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions polaris-react/src/components/ContentBlock/ContentBlock.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.ContentBlock {
margin: 0 auto;
}

.medium {
max-width: 41.375rem;
}

.large {
max-width: 62.375rem;
}
40 changes: 40 additions & 0 deletions polaris-react/src/components/ContentBlock/ContentBlock.stories.tsx
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)',
};

export function Medium() {
return (
<ContentBlock width="medium">
<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">
<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 polaris-react/src/components/ContentBlock/ContentBlock.tsx
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';

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>;
};
1 change: 1 addition & 0 deletions polaris-react/src/components/ContentBlock/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ContentBlock';
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>,
);

expect(contentBlock).toContainReactComponent('p', {children: text});
});

it('renders custom properties', () => {
const contentBlock = mountWithApp(
<ContentBlock width="large">{children}</ContentBlock>,
);

expect(contentBlock).toContainReactComponent('div', {
className: expect.stringContaining('large'),
});
});
});
3 changes: 3 additions & 0 deletions polaris-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export type {ComboboxProps} from './components/Combobox';
export {Connected} from './components/Connected';
export type {ConnectedProps} from './components/Connected';

export {ContentBlock} from './components/ContentBlock';
export type {ContentBlockProps} from './components/ContentBlock';

export {ContextualSaveBar} from './components/ContextualSaveBar';
export type {ContextualSaveBarProps} from './components/ContextualSaveBar';

Expand Down
15 changes: 15 additions & 0 deletions polaris.shopify.com/content/components/content-block/index.md
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.
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.
---
28 changes: 28 additions & 0 deletions polaris.shopify.com/pages/examples/content-block-width.tsx
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">
<Box background="surface" borderRadius="2" padding="5" shadow="card">
<Text variant="bodySm" as="h3" alignment="center">
medium
</Text>
</Box>
</ContentBlock>
<br />
<ContentBlock width="large">
<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.
Loading