Skip to content

Commit a2f8e49

Browse files
committed
Add storybook
1 parent 99762ad commit a2f8e49

17 files changed

+5534
-103
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
["@babel/preset-env", { "loose": true }]
66
],
77
"plugins": [
8-
"@babel/plugin-proposal-class-properties",
8+
["@babel/plugin-proposal-class-properties", { "loose": true }],
99
"transform-es2015-modules-commonjs",
1010
"dynamic-import-node"
1111
]

.github/CONTRIBUTING.md

+32
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,46 @@
33
Want to contribute to VTEX Styleguide? There are a few things you need to know.
44

55
### Release Schedule
6+
67
Thursday release: patch version weekly on each Thursday for routine bug fix (anytime for urgent bug fix).
78

89
Tuesday release: minor version at the Tuesday of every week for new features.
910

1011
Major version releases are not included in this schedule.
1112

1213
### Open Development
14+
1315
All work on VTEX Styleguide happens directly on GitHub. Both core team members and external contributors send pull requests which go through the same review process.
1416

1517
### Branch Organization
18+
1619
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`.
20+
21+
### Storybook Organization
22+
23+
#### Story file location
24+
25+
Our stories are located alongside with the components they document and the Playground are located in `react/playground`.
26+
27+
Example:
28+
29+
```
30+
31+
└── react
32+
└── components
33+
└── Button
34+
├── index.tsx
35+
├── index.test.tsx
36+
└── button.stories.tsx
37+
```
38+
39+
#### Conventions
40+
41+
1. The `Default` stories must allow to edit all the component props through Knobs.
42+
2. The name of the stories that shows different states or variations should start with `with`. Examples: `withTitle`, `withCustomColor`.
43+
3. Don't use external images in the stories, prefer to add images in the `.storybook/public/` folder.
44+
4. Component stories must be in a single file with the name `{componentName}.stories.tsx`. Examples: `button.stories.tsx`, `modal.stories.tsx`.
45+
5. Try not to add custom CSS in the stories.
46+
6. The stories must be written in typescript.
47+
48+
Help us add the missing component stories through this [issue](https://github.com/vtex/styleguide/issues/1157).

.github/PULL_REQUEST_TEMPLATE.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
<!--- Describe your changes in detail. -->
44

55
#### What problem is this solving?
6-
[Running workspace](http://link)
76

7+
[Running workspace](http://link)
88

99
<!--- What is the motivation and context for this change? -->
1010

1111
#### How should this be manually tested?
1212

13+
<!-- Add the code that is necessary to test your change in the Playground-->
14+
<details>
15+
<summary>Add this code in <code>react/playground/Playground.tsx</code>:</summary>
16+
17+
```jsx
18+
import React from 'react'
19+
import PageHeader from '../PageHeader'
20+
import Layout from '../Layout'
21+
const Playground = () => (
22+
<Layout fullWidth pageHeader={<PageHeader title="Playground" />}>
23+
{/* Add your code here, don't forget to delete after */}
24+
</Layout>
25+
)
26+
export default Playground
27+
```
28+
29+
</details>
30+
1331
#### Screenshots or example usage
1432

1533
#### Types of changes

.storybook/main.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require('path')
2+
3+
const custom = require('../config/webpack.config.js')
4+
5+
module.exports = {
6+
stories: [
7+
'../react/playground/stories.tsx',
8+
'../react/components/**/*.stories.tsx',
9+
],
10+
addons: [
11+
'@storybook/addon-viewport',
12+
'@storybook/addon-knobs/register',
13+
'@storybook/addon-actions/register',
14+
'@storybook/addon-a11y/register',
15+
],
16+
webpackFinal: config => {
17+
config.resolve.extensions.push('.ts', '.tsx')
18+
return {
19+
...config,
20+
module: { ...config.module, rules: custom.module.rules },
21+
}
22+
},
23+
}

.storybook/manager.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
brandTitle: 'VTEX Styleguide',
21+
brandUrl: '/',
22+
brandImage: null,
23+
}),
24+
})

.storybook/preview.tsx

+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,
10+
},
11+
})
12+
13+
addDecorator(story => <div style={{ padding: '10px' }}>{story()}</div>)

README.md

+12
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:
@@ -120,6 +130,7 @@ yarn deploy
120130
The `icon` components supports customization through the `<use>` element available in SVG. [Read more](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use)
121131

122132
**How to use:** In the same page that has a icon, load in any place inside the `<html>` a SVG with the following structure:
133+
123134
```svg
124135
<svg class="dn" height="0" version="1.1" width="0" xmlns="http://www.w3.org/2000/svg">
125136
<defs>
@@ -133,5 +144,6 @@ The `icon` components supports customization through the `<use>` element availab
133144
</defs>
134145
</svg>
135146
```
147+
136148
- The ID must match the ID of the icon you want to replace. To see all available options, [view icons folder](https://github.com/vtex/styleguide/tree/master/react/components/icon).
137149
- Inside one SVG you can have more than one `<g id="">`, one for each icon you want to update.

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
['@babel/preset-env', { loose: true }],
77
],
88
plugins: [
9-
'@babel/plugin-proposal-class-properties',
9+
['@babel/plugin-proposal-class-properties', { loose: true }],
1010
'transform-es2015-modules-commonjs',
1111
'dynamic-import-node',
1212
],

config/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module.exports = {
128128
// its runtime that would otherwise processed through "file" loader.
129129
// Also exclude `html` and `json` extensions so they get processed
130130
// by webpacks internal loaders.
131-
exclude: [/\.(js|jsx|mjs|ts|tsx)$/, /\.css$/, /\.html$/, /\.json$/],
131+
exclude: [/\.(js|jsx|mjs|ts|tsx|ejs)$/, /\.css$/, /\.html$/, /\.json$/],
132132
loader: require.resolve('file-loader'),
133133
options: {
134134
name: 'static/media/[name].[hash:8].[ext]',

package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"postreleasy": "vtex publish --public --verbose",
2323
"lint-fix": "eslint react --ext js,jsx,ts,tsx --fix --max-warnings 0",
2424
"prettier-conflict-check": "eslint --print-config .eslintrc | eslint-config-prettier-check",
25-
"build": "run-s compile styleguide:build"
25+
"build": "run-s compile styleguide:build",
26+
"storybook": "start-storybook -p 6006",
27+
"build-storybook": "build-storybook"
2628
},
2729
"main": "./lib/index.js",
2830
"files": [
@@ -47,6 +49,15 @@
4749
"@babel/preset-env": "^7.5.5",
4850
"@babel/preset-react": "^7.0.0",
4951
"@babel/preset-typescript": "^7.3.3",
52+
"@storybook/addon-a11y": "^6.0.19",
53+
"@storybook/addon-actions": "^6.0.19",
54+
"@storybook/addon-console": "^1.2.1",
55+
"@storybook/addon-essentials": "^6.0.19",
56+
"@storybook/addon-knobs": "^6.0.19",
57+
"@storybook/addon-links": "^6.0.19",
58+
"@storybook/addon-viewport": "^6.0.19",
59+
"@storybook/addons": "^6.0.19",
60+
"@storybook/react": "^6.0.19",
5061
"@testing-library/jest-dom": "^5.1.1",
5162
"@testing-library/react": "^9.5.0",
5263
"@testing-library/react-hooks": "^3.2.1",
@@ -84,6 +95,7 @@
8495
"react-app-polyfill": "^1.0.1",
8596
"react-dev-utils": "^9.0.1",
8697
"react-dom": "^16.12.0",
98+
"react-is": "^16.13.1",
8799
"react-styleguidist": "^9.1.12",
88100
"react-test-renderer": "^16.13.0",
89101
"style-loader": "^0.23.1",
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
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'
5+
6+
import Button from '.'
7+
8+
export default {
9+
title: 'Components/Button',
10+
component: Button,
11+
decorators: [withA11y, withKnobs],
12+
}
13+
14+
const variations = [
15+
'primary',
16+
'secondary',
17+
'tertiary',
18+
'danger',
19+
'danger-tertiary',
20+
'inverted-tertiary',
21+
]
22+
const sizes = ['small', 'regular', 'large']
23+
24+
export const Default = () => (
25+
<Button
26+
type="button"
27+
variation={select('Variation', variations, 'primary')}
28+
isLoading={boolean('Is loading', false)}
29+
disabled={boolean('Disabled', false)}
30+
block={boolean('Block', false)}
31+
size={select('Size', sizes, 'regular')}
32+
onClick={action('button-click')}
33+
onFocus={action('button-focus')}>
34+
{text('Label', 'With a text')}
35+
</Button>
36+
)
37+
38+
export const withLoadingState = () => (
39+
<Button type="button" isLoading>
40+
Loading
41+
</Button>
42+
)
43+
44+
export const withDiffentVariations = () => (
45+
<>
46+
{variations.map(variation => (
47+
<>
48+
<Button type="button" variation={variation}>
49+
{variation}
50+
</Button>
51+
<br />
52+
<br />
53+
</>
54+
))}
55+
</>
56+
)
57+
58+
export const withOnMouseEvents = () => (
59+
<Button
60+
type="button"
61+
onFocus={() => null}
62+
onBlur={() => null}
63+
onMouseDown={action('button-on-mouse-down')}
64+
onMouseEnter={action('button-on-mouse-enter')}
65+
onMouseOver={action('button-on-mouse-over')}
66+
onMouseLeave={action('button-on-mouse-leave')}
67+
onMouseOut={action('button-on-mouse-out')}
68+
onMouseUp={action('button-on-mouse-up')}>
69+
Button
70+
</Button>
71+
)
72+
73+
export const withDifferentSizes = () => (
74+
<>
75+
{sizes.map(size => (
76+
<>
77+
<Button type="button" size={size}>
78+
{size}
79+
</Button>
80+
<br />
81+
<br />
82+
</>
83+
))}
84+
</>
85+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { withKnobs, text, select, number } from '@storybook/addon-knobs'
3+
4+
import { Position } from './TooltipPopup'
5+
import Tooltip from '.'
6+
import Button from '../Button'
7+
8+
export default {
9+
title: 'Components/Tooltip',
10+
component: Tooltip,
11+
decorators: [withKnobs],
12+
}
13+
14+
const positions: Position[] = ['top', 'left', 'right', 'bottom']
15+
16+
export const Default = () => (
17+
<Tooltip
18+
label={text('Label', 'Tooltip Label')}
19+
trigger={select('Trigger', ['click', 'hover', 'focus'], 'hover')}
20+
wordBreak={select(
21+
'Word Break',
22+
['normal', 'break-all', 'keep-all', 'break-word'],
23+
'normal'
24+
)}
25+
position={select('Position', positions, 'left')}
26+
delay={number('Delay(ms)', 0)}
27+
fallbackPosition={select('Fallback Position', positions, 'right')}>
28+
<Button type="button">Hover me</Button>
29+
</Tooltip>
30+
)

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

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