Skip to content

Commit aaeb41c

Browse files
committed
add storybook guide in readme and contributing, customize storybook theme and add stories eexamples
1 parent 9a56903 commit aaeb41c

14 files changed

+339
-18
lines changed

.github/CONTRIBUTING.md

+29
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,32 @@ All work on VTEX Styleguide happens directly on GitHub. Both core team members a
1414

1515
### Branch Organization
1616
According to our [release schedule](#release-schedule), we maintain two branches: `master` and `features`. Bug fixes should have `master` as it base branch, while new features should be merged into `features`.
17+
18+
### Storybook Organization
19+
20+
#### Story file location
21+
22+
Our stories are located alongside with the components they document and the Playground are located in `react/playground`.
23+
24+
Example:
25+
26+
```
27+
28+
└── react
29+
└── components
30+
└── Button
31+
├── index.tsx
32+
└── button.stories.tsx
33+
34+
```
35+
36+
#### Conventions
37+
38+
1. The `Default` stories must allow to edit all the component props through Knobs.
39+
2. The name of the stories that shows different states or variations should start with `with`. Examples: `withTitle`, `withCustomColor`.
40+
3. Don't use external images in the stories, prefer to add images in the `.storybook/public/` folder.
41+
4. Component stories must be in a single file with the name `{componentName}.stories.tsx`. Examples: `button.stories.tsx`, `modal.stories.tsx`.
42+
5. Try not to add custom CSS in the stories.
43+
44+
45+
Help us add the missing component stories through this [issue](https://github.com/vtex/styleguide/issues/1157).

.storybook/config.js

-1
This file was deleted.

.storybook/main.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ const path = require('path');
33
const custom = require('../config/webpack.config.js')
44

55
module.exports = {
6-
stories: ['../react/components/**/*.stories.tsx'],
6+
stories: ['../react/playground/stories.tsx', '../react/components/**/*.stories.tsx'],
7+
addons: [
8+
'@storybook/addon-viewport',
9+
'@storybook/addon-knobs/register',
10+
'@storybook/addon-actions/register',
11+
'@storybook/addon-a11y/register'
12+
],
713
webpackFinal: (config) => {
814
config.resolve.extensions.push('.ts', '.tsx')
915
return { ...config, module: { ...config.module, rules: custom.module.rules } }

.storybook/manager.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {addons} from '@storybook/addons';
2+
import {create} from '@storybook/theming';
3+
4+
addons.setConfig({
5+
panelPosition: 'bottom',
6+
7+
theme: create({
8+
base: 'light',
9+
10+
// UI
11+
appBorderRadius: 4,
12+
appBg: '#FFFFFF',
13+
contentBg: '#FFFFFF',
14+
textColor: '#3f3f40',
15+
16+
// Typography
17+
fontBase: '"Fabriga", sans-serif',
18+
fontCode: 'monospace',
19+
20+
21+
brandTitle: 'VTEX Styleguide',
22+
brandUrl: '/',
23+
brandImage: null,
24+
}),
25+
});

.storybook/preview.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { addParameters, addDecorator } from '@storybook/react'
3+
import '@storybook/addon-console'
4+
import 'vtex-tachyons'
5+
6+
addParameters({
7+
options: {
8+
showNav: true,
9+
showPanel: true, // show the code panel by default
10+
},
11+
})
12+
13+
addDecorator(story => (<div style={{padding: '10px'}}>{story()}</div>)) // Add padding in the canvas

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ yarn install
2828
yarn styleguide
2929
```
3030

31+
### Storybook
32+
33+
We use [Storybook](https://storybook.js.org/) environment to help us build and test our components in real time. You can edit the Playground file and add the components you are working on, after this run the command below to see your changes in http://localhost:6006/ :
34+
35+
```shell
36+
yarn storybook
37+
```
38+
39+
If you want to change or add stories, take a look at this [guide](https://github.com/vtex/styleguide/blob/master/.github/CONTRIBUTING.md#storybook-organization) before.
40+
3141
## Developing using `npm link`
3242

3343
Run this in this repo:

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@
3939
"@babel/preset-env": "^7.5.5",
4040
"@babel/preset-react": "^7.0.0",
4141
"@babel/preset-typescript": "^7.3.3",
42+
"@storybook/addon-a11y": "^5.3.18",
4243
"@storybook/addon-actions": "^5.3.18",
44+
"@storybook/addon-console": "^1.2.1",
45+
"@storybook/addon-knobs": "^5.3.18",
4346
"@storybook/addon-links": "^5.3.18",
47+
"@storybook/addon-viewport": "^5.3.18",
4448
"@storybook/addons": "^5.3.18",
4549
"@storybook/react": "^5.3.18",
4650
"@testing-library/jest-dom": "^5.1.1",
+51-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,61 @@
11
import React from 'react'
2+
import { withA11y } from '@storybook/addon-a11y'
3+
import { withKnobs, text, boolean, select } from "@storybook/addon-knobs"
4+
import { action } from '@storybook/addon-actions'
25

36
import Button from '.'
47

58
export default {
6-
title: 'Button',
9+
title: 'Components|Button',
710
component: Button,
11+
decorators: [withA11y, withKnobs]
812
}
913

10-
export const withText = () => (
11-
<Button type="primary">
12-
With a text
14+
const variations = ['primary', 'secondary', 'tertiary', 'danger', 'danger-tertiary', 'inverted-tertiary']
15+
16+
export const Default = () => (
17+
<Button
18+
variation={select('Variation', variations, 'primary')}
19+
isLoading={boolean('Is loading', false)}
20+
disabled={boolean('Disabled', false)}
21+
block={boolean('Block', false)}
22+
size={select('Size', ['small', 'regular', 'large'], 'regular')}
23+
onClick={action('button-click')}
24+
onFocus={action('button-focus')}
25+
>
26+
{text("Label", "With a text")}
27+
</Button>
28+
)
29+
30+
export const withLoadingState = () => (
31+
<Button
32+
isLoading={true}
33+
>
34+
Loading
35+
</Button>
36+
)
37+
38+
export const withDiffentVariations = () => (
39+
<>
40+
{variations.map(variation => (
41+
<>
42+
<Button variation={variation}>{variation}</Button>
43+
<br/>
44+
<br/>
45+
</>
46+
))}
47+
</>
48+
)
49+
50+
export const withOnMouseEvents = () => (
51+
<Button
52+
onMouseDown={action('button-on-mouse-down')}
53+
onMouseEnter={action('button-on-mouse-enter')}
54+
onMouseOver={action('button-on-mouse-over')}
55+
onMouseLeave={action('button-on-mouse-leave')}
56+
onMouseOut={action('button-on-mouse-out')}
57+
onMouseUp={action('button-on-mouse-up')}
58+
>
59+
Button
1360
</Button>
1461
)
+18-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
import React from 'react'
2+
import { withKnobs, text, boolean, select } from "@storybook/addon-knobs"
23

34
import Tooltip from '.'
5+
import Button from '../Button'
46

57
export default {
6-
title: 'Tooltip',
8+
title: 'Components|Tooltip',
79
component: Tooltip,
10+
decorators: [withKnobs]
811
}
912

10-
export const tooltipTop = () => (
11-
<Tooltip label="tooltip text">
12-
<span>oi</span>
13+
export const Default = () => (
14+
<Tooltip
15+
label={text('Label', 'Tooltip Label')}
16+
trigger={select('Trigger', ['click', 'hover', 'focus'], 'hover')}
17+
wordBreak={select('Word Break', ['normal', 'break-all', 'keep-all', 'break-word'], 'normal')}
18+
position={select('Position', ['top', 'left', 'right', 'bottom'], 'left')}
19+
>
20+
<Button>Button</Button>
21+
</Tooltip>
22+
)
23+
24+
export const AlwaysVisible = () => (
25+
<Tooltip label="Tooltip Label" trigger="focus">
26+
<Button autoFocus={true}>Button with focus</Button>
1327
</Tooltip>
1428
)

react/playground/All.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
/*
3+
This story should contain all our components.
4+
*/
5+
const All = () => (<h1>Under construction</h1>)
6+
7+
export default All

react/playground/ExamplePage.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react'
2+
3+
/*
4+
This story should have an example page using our components.
5+
*/
6+
const ExamplePage = () => (<h1>Under construction</h1>)
7+
8+
export default ExamplePage

react/playground/Playground.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import PageHeader from '../PageHeader'
3+
import PageBlock from '../PageBlock'
4+
import Layout from '../Layout'
5+
6+
const Playground = () => (
7+
<Layout
8+
fullWidth
9+
pageHeader={<PageHeader title="Playground"/>}
10+
>
11+
<PageBlock>
12+
{/* Add your code here, don't forget to delete after */}
13+
</PageBlock>
14+
</Layout>
15+
)
16+
17+
export default Playground

react/playground/stories.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Playground from './Playground'
2+
import ExamplePage from './ExamplePage'
3+
import All from './All'
4+
5+
export default {
6+
title: 'Playground|Playground'
7+
}
8+
9+
export { Playground, ExamplePage, All }

0 commit comments

Comments
 (0)