Skip to content

Commit 3a7427f

Browse files
author
Andrey Okonetchnikov
committed
Flatten components structure and provide components to styleguide examples
1 parent 6822fcb commit 3a7427f

36 files changed

+39
-51
lines changed

src/components/primitives/Box/Box.md renamed to src/components/primitives/Box.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Box allows controlling its whitespace, layout, colors, etc. using design tokens.
44

55
Following example should render a `div` that has `width: 25%`, `padding`, `margin`, and `background-color` values set.
66

7-
```jsx harmony
7+
```jsx
88
<Box p={4} m={3} width={1 / 4} bg="muted">
99
Box content
1010
</Box>

src/components/primitives/Box/index.js

-1
This file was deleted.

src/components/primitives/Button/Button.md renamed to src/components/primitives/Button.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ Button as a link:
2828
Full width button:
2929

3030
```js padded
31-
import Flex from '../Flex';
3231
<>
3332
<Flex flexDirection="column" mb={4}>
3433
<Button>Loooongcat is long</Button>
3534
</Flex>
3635
<Flex flexDirection="column">
3736
<Button variant="primary">Loooongcat is long</Button>
3837
</Flex>
39-
</>;
38+
</>
4039
```

src/components/primitives/Button/index.js

-1
This file was deleted.

src/components/primitives/Flex/Flex.js renamed to src/components/primitives/Flex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import styled from 'styled-components';
2-
import Box from '../Box';
2+
import Box from './Box';
33

44
export const Flex = styled(Box)({
55
display: 'flex',

src/components/primitives/Flex/Flex.md renamed to src/components/primitives/Flex.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ See https://styled-system.com/api#flexbox for more information.
44

55
Using Flex we can create a simple columns layout:
66

7-
```jsx harmony
8-
import Box from '../Box';
9-
7+
```jsx
108
<Flex>
119
<Box flex="1 1 auto" p={3} bg="grey.3">
1210
Column 1
@@ -17,14 +15,12 @@ import Box from '../Box';
1715
<Box flex="1 1 auto" p={3} bg="grey.5">
1816
Column 3
1917
</Box>
20-
</Flex>;
18+
</Flex>
2119
```
2220

2321
or rows:
2422

25-
```jsx harmony
26-
import Box from '../Box';
27-
23+
```jsx
2824
<Flex flexDirection="column">
2925
<Box p={3} bg="grey.3">
3026
Column 1
@@ -35,5 +31,5 @@ import Box from '../Box';
3531
<Box p={3} bg="grey.5">
3632
Column 3
3733
</Box>
38-
</Flex>;
34+
</Flex>
3935
```

src/components/primitives/Flex/index.js

-1
This file was deleted.

src/components/primitives/Grid/Grid.js renamed to src/components/primitives/Grid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import styled from 'styled-components';
2-
import Box from '../Box';
2+
import Box from './Box';
33

44
export const Grid = styled(Box)({
55
display: 'grid',

src/components/primitives/Grid/Grid.md renamed to src/components/primitives/Grid.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ See https://styled-system.com/api#grid for more information.
44

55
Using Grid we can create a complex grid layouts:
66

7-
```jsx harmony
8-
import Box from '../Box';
9-
7+
```jsx
108
<Grid gridTemplateColumns="repeat(auto-fit, minmax(200px, 1fr))">
119
<Box p={4} bg="grey.1">
1210
Grid Item
@@ -20,5 +18,5 @@ import Box from '../Box';
2018
<Box p={4} bg="grey.4">
2119
Grid Item
2220
</Box>
23-
</Grid>;
21+
</Grid>
2422
```

src/components/primitives/Grid/index.js

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
```jsx harmony
1+
```jsx
22
<Input type="text" />
33
```
44

55
Disabled input:
66

7-
```jsx harmony
7+
```jsx
88
<Input type="text" disabled />
99
```

src/components/primitives/Input/index.js

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
Normal link:
22

3-
```jsx harmony
3+
```jsx
44
<Link href="/">Normal link</Link>
55
```
66

77
Shy link. Use for secondary content like footers or small copy.
88

9-
```jsx harmony
10-
import Text from '../Text';
9+
```jsx
1110
<Text>
1211
By using our site you agree to the following{' '}
1312
<Link href="/" shy>
1413
Terms of Service
1514
</Link>
1615
.
17-
</Text>;
16+
</Text>
1817
```

src/components/primitives/Link/index.js

-1
This file was deleted.

src/components/primitives/Stack/Stack.js renamed to src/components/primitives/Stack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types';
22
import styled from 'styled-components';
33
import { system } from 'styled-system';
4-
import Grid from '../Grid';
4+
import Grid from './Grid';
55

66
const px = value => (typeof value === 'number' ? `${value}px` : value);
77

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
Stack is a layout primitive that adds space around their children.
22

3-
```javascript
4-
import Button from '../Button';
5-
3+
```jsx
64
<Stack gridGap={4}>
75
<Button>Button</Button>
86
<Button>Button</Button>
97
<Button>Button</Button>
10-
</Stack>;
8+
</Stack>
119
```
1210

1311
Since Stack is based on [Grid](/#/Primitives?id=grid), all of `Grid` props are available:
1412

15-
```javascript
16-
import Button from '../Button';
17-
13+
```jsx
1814
<Stack gridGap={3} gridAutoFlow="column">
1915
<Button>Button</Button>
2016
<Button>Button</Button>
@@ -23,5 +19,5 @@ import Button from '../Button';
2319
<Button>Button</Button>
2420
<Button>Button</Button>
2521
<Button>Button</Button>
26-
</Stack>;
22+
</Stack>
2723
```

src/components/primitives/Stack/index.js

-1
This file was deleted.

src/components/primitives/Text/Text.js renamed to src/components/primitives/Text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
22
import styled from 'styled-components';
33
import { color, typography, space, layout, variant } from 'styled-system';
44
import { css } from '@styled-system/css';
5-
import theme from '../../../theme';
5+
import theme from '../../theme';
66

77
/**
88
* A component to render all text in the app.

src/components/primitives/Text/index.js

-1
This file was deleted.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Default button:
22

3-
```jsx harmony
3+
```jsx
44
<Button>Push me</Button>
55
```
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Default button:
22

3-
```jsx harmony
3+
```jsx
44
<Button>Push me</Button>
55
```

src/exercises/3-Basic_Primitives/Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ As you can see, there is a lot of repetition going on. Also this method doesn’
3232

3333
The result should allow rendering such text:
3434

35-
```jsx harmony
35+
```jsx
3636
import { Text } from '../../components';
3737

3838
<Text color="error" fontWeight="bold">

src/exercises/3-Basic_Primitives/Text.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
```jsx harmony
1+
```jsx
22
<Text>
33
Lithe and leggy, Salukis are the supermodels of the canine world.
44
Their looks are legendary: this ancient breed can be traced back to

src/exercises/4-Layout_Primitives/Box.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
```jsx harmony
1+
```jsx
22
<Box p={2} m={3} width={1 / 4} bg="primary">
33
Box content
44
</Box>

src/exercises/4-Layout_Primitives/Flex.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
```jsx harmony
1+
```jsx
22
import Box from './Box';
33

44
<Flex flexDirection="column">

src/exercises/4-Layout_Primitives/Grid.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
```jsx harmony
1+
```jsx
22
import Box from './Box';
33
<Grid
44
gridGap={2}

src/exercises/4-Layout_Primitives/Stack.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
```jsx harmony
1+
```jsx
22
import Box from './Box';
33
<Stack gridGap={2} numColumns={[1, 2, 3]}>
44
<Box p={4} bg="grey.2">

src/exercises/5-Patterns/Footer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
```jsx harmony
1+
```jsx
22
<Footer />
33
```

src/exercises/5-Patterns/LoginPage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
```jsx harmony
1+
```jsx
22
<LoginPage />
33
```

styleguide.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const config = {
2424
exampleMode: 'expand',
2525
usageMode: 'expand',
2626
webpackConfig,
27+
require: [path.join(__dirname, 'styleguide.setup.js')],
2728
updateExample(props, exampleFilePath) {
2829
const { settings, lang } = props;
2930
if (typeof settings.file === 'string') {

styleguide.setup.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as components from './src/components';
2+
3+
// Expose all components to the global scope for styleguide examples
4+
// so it behaves more like Playroom without the need to import components
5+
Object.entries(components).forEach(([key, value]) => {
6+
global[key] = value;
7+
});

0 commit comments

Comments
 (0)