Skip to content

Commit ae7c77b

Browse files
chazdeanlaurkim
andcommitted
[Layout foundations] Add Tile component (#7092)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Fixes #6898 <!-- link to issue if one exists --> <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? Adds a new alpha `Tile` component <details> <summary><code>Tile</code> component preview</summary> <img width="1032" alt="Screen Shot 2022-09-08 at 4 48 11 PM" src="https://user-images.githubusercontent.com/59836805/189224294-93c54b0a-ba93-4651-88e8-3de3e76ad3c4.png"> </details> <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {Page, Tile, Box, Text} from '../src'; export function Playground() { return ( <Page title="Playground"> <Tile spacing="3" columns="2"> <Box background="surface" borderRadius="2" padding="5" shadow="card"> <Text as="h2" variant="headingMd"> Sales </Text> <Text as="p" variant="bodyMd"> View a summary of your online store’s sales. </Text> </Box> <Box background="surface" borderRadius="2" padding="5" shadow="card"> <Text as="h2" variant="headingMd"> Sales </Text> <Text as="p" variant="bodyMd"> View a summary of your online store’s sales. </Text> </Box> <Box background="surface" borderRadius="2" padding="5" shadow="card"> <Text as="h2" variant="headingMd"> Sales </Text> <Text as="p" variant="bodyMd"> View a summary of your online store’s sales. </Text> </Box> <Box background="surface" borderRadius="2" padding="5" shadow="card"> <Text as="h2" variant="headingMd"> Sales </Text> <Text as="p" variant="bodyMd"> View a summary of your online store’s sales. </Text> </Box> </Tile> </Page> ); } ``` </details> ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide Co-authored-by: Lo Kim <[email protected]>
1 parent 42268be commit ae7c77b

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import '../../styles/common';
2+
3+
.Tile {
4+
display: grid;
5+
grid-template-columns: var(--pc-tile-column-number);
6+
gap: var(--pc-tile-spacing);
7+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import type {ComponentMeta} from '@storybook/react';
3+
import {Box, Tile, Text} from '@shopify/polaris';
4+
5+
export default {
6+
component: Tile,
7+
} as ComponentMeta<typeof Tile>;
8+
9+
const styles = {
10+
background: 'var(--p-surface)',
11+
border: 'var(--p-border-base)',
12+
borderRadius: 'var(--p-border-radius-2)',
13+
padding: 'var(--p-space-4)',
14+
};
15+
16+
const children = Array.from(Array(4)).map((ele, index) => (
17+
<div key={index} style={styles}>
18+
<Text as="h2" variant="headingMd">
19+
Sales
20+
</Text>
21+
<Text as="p" variant="bodyMd">
22+
View a summary of your online store’s sales.
23+
</Text>
24+
</div>
25+
));
26+
27+
export function Default() {
28+
return (
29+
<Tile spacing="1" columns="2">
30+
{children}
31+
</Tile>
32+
);
33+
}
34+
35+
export function LargeSpacing() {
36+
return (
37+
<Tile spacing="10" columns="2">
38+
{children}
39+
</Tile>
40+
);
41+
}
42+
43+
export function ManyColumns() {
44+
const children = Array.from(Array(10)).map((ele, index) => (
45+
<div key={index} style={styles}>
46+
<Text as="h2" variant="headingMd">
47+
Sales
48+
</Text>
49+
<Text as="p" variant="bodyMd">
50+
View a summary of your online store’s sales.
51+
</Text>
52+
</div>
53+
));
54+
55+
return (
56+
<Tile spacing="3" columns="5">
57+
{children}
58+
</Tile>
59+
);
60+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react';
2+
import type {spacing} from '@shopify/polaris-tokens';
3+
4+
import styles from './Tile.scss';
5+
6+
type SpacingTokenName = keyof typeof spacing;
7+
8+
// TODO: Bring this logic into tokens
9+
type Spacing = SpacingTokenName extends `space-${infer Scale}` ? Scale : never;
10+
11+
type Columns =
12+
| '1'
13+
| '2'
14+
| '3'
15+
| '4'
16+
| '5'
17+
| '6'
18+
| '7'
19+
| '8'
20+
| '9'
21+
| '10'
22+
| '11'
23+
| '12';
24+
25+
export interface TileProps {
26+
/** Elements to display inside tile */
27+
children: React.ReactNode;
28+
/** Adjust spacing between elements */
29+
spacing: Spacing;
30+
/** Adjust number of columns */
31+
columns: Columns;
32+
}
33+
34+
export const Tile = ({children, spacing, columns}: TileProps) => {
35+
const style = {
36+
'--pc-tile-column-number': `repeat(${columns}, 1fr)`,
37+
'--pc-tile-spacing': `var(--p-space-${spacing})`,
38+
} as React.CSSProperties;
39+
40+
return (
41+
<div className={styles.Tile} style={style}>
42+
{children}
43+
</div>
44+
);
45+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Tile';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import {mountWithApp} from 'tests/utilities';
3+
4+
import {Tile} from '../Tile';
5+
6+
const Children = () => <p>This is a tile</p>;
7+
8+
describe('<Tile />', () => {
9+
it('renders children', () => {
10+
const tile = mountWithApp(
11+
<Tile spacing="1" columns="1">
12+
<Children />
13+
</Tile>,
14+
);
15+
16+
expect(tile).toContainReactComponent(Children);
17+
});
18+
19+
it('uses custom properties when passed in', () => {
20+
const tile = mountWithApp(
21+
<Tile spacing="1" columns="2">
22+
<Children />
23+
</Tile>,
24+
);
25+
26+
expect(tile).toContainReactComponent('div', {
27+
style: {
28+
'--pc-tile-column-number': 'repeat(2, 1fr)',
29+
'--pc-tile-spacing': 'var(--p-space-1)',
30+
} as React.CSSProperties,
31+
});
32+
});
33+
});

polaris-react/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ export type {TextStyleProps} from './components/TextStyle';
366366
export {Thumbnail} from './components/Thumbnail';
367367
export type {ThumbnailProps} from './components/Thumbnail';
368368

369+
export {Tile} from './components/Tile';
370+
export type {TileProps} from './components/Tile';
371+
369372
export {Toast} from './components/Toast';
370373
export type {ToastProps} from './components/Toast';
371374

0 commit comments

Comments
 (0)