Skip to content

Commit c7606ce

Browse files
thayannevlsestacioneto
authored andcommitted
Add storybook
1 parent 8980e14 commit c7606ce

18 files changed

+5477
-106
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

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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-essentials',
12+
'@storybook/addon-a11y',
13+
'@storybook/addon-links',
14+
],
15+
webpackFinal: config => {
16+
config.resolve.extensions.push('.ts', '.tsx')
17+
return {
18+
...config,
19+
module: { ...config.module, rules: custom.module.rules },
20+
}
21+
},
22+
}

.storybook/manager.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
textColor: '#3f3f40',
14+
15+
// Typography
16+
fontBase: '"Fabriga", sans-serif',
17+
fontCode: 'monospace',
18+
19+
brandTitle: 'VTEX Styleguide',
20+
brandUrl: '/',
21+
brandImage: null,
22+
}),
23+
})

.storybook/preview.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import '@storybook/addon-console'
2+
import 'vtex-tachyons'
3+
4+
export const parameters = {
5+
actions: { argTypesRegex: '^on[A-Z].*' },
6+
}

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

+16-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,14 @@
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.21",
53+
"@storybook/addon-actions": "^6.0.21",
54+
"@storybook/addon-console": "^1.2.1",
55+
"@storybook/addon-essentials": "^6.0.21",
56+
"@storybook/addon-links": "^6.0.21",
57+
"@storybook/addon-viewport": "^6.0.21",
58+
"@storybook/addons": "^6.0.21",
59+
"@storybook/react": "^6.0.21",
5060
"@testing-library/jest-dom": "^5.1.1",
5161
"@testing-library/react": "^9.5.0",
5262
"@testing-library/react-hooks": "^3.2.1",
@@ -84,6 +94,7 @@
8494
"react-app-polyfill": "^1.0.1",
8595
"react-dev-utils": "^9.0.1",
8696
"react-dom": "^16.12.0",
97+
"react-is": "^16.13.1",
8798
"react-styleguidist": "^9.1.12",
8899
"react-test-renderer": "^16.13.0",
89100
"style-loader": "^0.23.1",
@@ -119,6 +130,10 @@
119130
"react-dom": "^16.8.0",
120131
"recharts": "^2.0.0-beta.1"
121132
},
133+
"resolutions": {
134+
"react": "^16.12.0",
135+
"react-dom": "^16.12.0"
136+
},
122137
"husky": {
123138
"hooks": {
124139
"pre-push": "npm run prettier-conflict-check && npm run lint"
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Story, Meta } from '@storybook/react'
4+
import { action } from '@storybook/addon-actions'
5+
6+
import Button, { propTypes } from '.'
7+
8+
type ButtonProps = PropTypes.InferProps<typeof propTypes>
9+
10+
const variations = [
11+
'primary',
12+
'secondary',
13+
'tertiary',
14+
'danger',
15+
'danger-tertiary',
16+
'inverted-tertiary',
17+
]
18+
const sizes = ['small', 'regular', 'large']
19+
20+
export default {
21+
title: 'Components/Button',
22+
component: Button,
23+
argTypes: {
24+
variation: {
25+
control: {
26+
type: 'select',
27+
options: variations,
28+
},
29+
},
30+
size: {
31+
control: {
32+
type: 'inline-radio',
33+
options: sizes,
34+
},
35+
},
36+
onClick: {
37+
action: 'button-click',
38+
},
39+
},
40+
} as Meta
41+
42+
const Template: Story<ButtonProps> = args => <Button {...args} type="button" />
43+
44+
export const Default = Template.bind({})
45+
Default.args = {
46+
variation: 'primary',
47+
isLoading: false,
48+
disabled: false,
49+
block: false,
50+
size: 'regular',
51+
children: 'Button',
52+
}
53+
54+
export const withLoadingState = Template.bind({})
55+
withLoadingState.args = {
56+
...Default.args,
57+
isLoading: true,
58+
}
59+
60+
export const withDifferentVariations = () => (
61+
<>
62+
{variations.map(variation => (
63+
<>
64+
<Button type="button" variation={variation}>
65+
{variation}
66+
</Button>
67+
<br />
68+
<br />
69+
</>
70+
))}
71+
</>
72+
)
73+
74+
export const withOnMouseEvents = Template.bind({})
75+
withOnMouseEvents.args = {
76+
...Default.args,
77+
onMouseDown: action('button-on-mouse-down'),
78+
onMouseEnter: action('button-on-mouse-enter'),
79+
onMouseOver: action('button-on-mouse-over'),
80+
onMouseLeave: action('button-on-mouse-leave'),
81+
onMouseOut: action('button-on-mouse-out'),
82+
onMouseUp: action('button-on-mouse-up'),
83+
}
84+
85+
export const withDifferentSizes = () => (
86+
<>
87+
{sizes.map(size => (
88+
<>
89+
<Button type="button" size={size}>
90+
{size}
91+
</Button>
92+
<br />
93+
<br />
94+
</>
95+
))}
96+
</>
97+
)

react/components/Tooltip/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const propTypes = {
3939
]),
4040
}
4141

42-
type Props = PropTypes.InferProps<typeof propTypes>
42+
export type Props = PropTypes.InferProps<typeof propTypes>
4343

4444
const defaultProps: Props = {
4545
trigger: 'hover',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react'
2+
import { Story, Meta } from '@storybook/react'
3+
4+
import { Position } from './TooltipPopup'
5+
import Tooltip, { Props } from '.'
6+
import Button from '../Button'
7+
8+
const positions: Position[] = ['top', 'left', 'right', 'bottom']
9+
10+
export default {
11+
title: 'Components/Tooltip',
12+
component: Tooltip,
13+
argTypes: {
14+
position: {
15+
control: {
16+
type: 'select',
17+
options: positions,
18+
},
19+
},
20+
fallbackPosition: {
21+
control: {
22+
type: 'select',
23+
options: positions,
24+
},
25+
},
26+
trigger: {
27+
control: {
28+
type: 'inline-radio',
29+
options: ['click', 'hover', 'focus'],
30+
},
31+
},
32+
wordBreak: {
33+
control: {
34+
type: 'select',
35+
options: ['normal', 'break-all', 'keep-all', 'break-word'],
36+
},
37+
},
38+
},
39+
} as Meta
40+
41+
const Template: Story<Props> = args => <Tooltip {...args} />
42+
43+
export const Default = Template.bind({})
44+
Default.args = {
45+
label: 'Tooltip Label',
46+
trigger: 'hover',
47+
wordBreak: 'normal',
48+
position: 'bottom',
49+
delay: 0,
50+
fallbackPosition: 'right',
51+
children: <Button type="button">Button</Button>,
52+
size: 'small',
53+
}

0 commit comments

Comments
 (0)