/
grid.example.story.js
74 lines (70 loc) 路 2.08 KB
/
grid.example.story.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, select, number } from '@storybook/addon-knobs/react';
import styled from '@emotion/styled';
import { customProperties } from '@commercetools-uikit/design-system';
import Section from '../../../.storybook/decorators/section';
import Spacings from '../spacings';
import Text from '../typography/text';
import Readme from './README.md';
import Grid from './grid';
const createList = size =>
Array.from({ length: size }).map((_, index) => index + 1);
const Placeholder = styled.div`
display: flex;
align-items: center;
justify-content: center;
background-color: pink;
padding: ${customProperties.spacingM};
`;
const renderGridElements = () => {
const elems = select('Num. of grid elements', createList(20), 6);
return createList(elems).map((el, index) => (
<Grid.Item key={index}>
<Placeholder>{el}</Placeholder>
</Grid.Item>
));
};
storiesOf('Examples|Components/Grid', module)
.addDecorator(withKnobs)
.addParameters({
readme: {
// Show readme at the addons panel
sidebar: Readme,
},
})
.add('With fixed columns', () => (
<Section>
<Spacings.Stack scale="l">
<Text.Body tone="information">
{'馃拋 Try resizing the window to see how the grid layout behaves.'}
</Text.Body>
<Grid
gridGap="16px"
gridAutoColumns="1fr"
gridTemplateColumns="repeat(3, 1fr)"
>
{renderGridElements()}
</Grid>
</Spacings.Stack>
</Section>
))
.add('With auto-sizing columns', () => (
<Section>
<Spacings.Stack scale="l">
<Text.Body tone="information">
{'馃拋 Try resizing the window to see how the grid layout behaves.'}
</Text.Body>
<Grid
gridGap="16px"
gridAutoColumns="1fr"
gridTemplateColumns={`repeat(auto-fill, minmax(${number(
'min column width',
150
)}px, 1fr))`}
>
{renderGridElements()}
</Grid>
</Spacings.Stack>
</Section>
));