-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(#1216): storybook config #2310
Changes from 7 commits
a3ffa62
76aca03
ae0a1f7
1c3748d
602505e
abab128
7eccdd8
87df250
26c0102
6b73804
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
/** @type { import('@storybook/react-webpack5').StorybookConfig } */ | ||
const config = { | ||
stories: ['../client/**/*.stories.(jsx|mdx)'], | ||
addons: [ | ||
'@storybook/addon-actions', | ||
'@storybook/addon-docs', | ||
'@storybook/addon-knobs', | ||
'@storybook/addon-links', | ||
'storybook-addon-theme-playground/dist/register' | ||
'@storybook/addon-essentials', | ||
'@storybook/addon-interactions' | ||
], | ||
webpackFinal: async config => { | ||
// do mutation to the config | ||
|
||
const rules = config.module.rules; | ||
|
||
// modify storybook's file-loader rule to avoid conflicts with svgr | ||
const fileLoaderRule = rules.find(rule => rule.test.test('.svg')); | ||
fileLoaderRule.exclude = path.resolve(__dirname, '../client'); | ||
framework: { | ||
name: '@storybook/react-webpack5', | ||
options: {} | ||
}, | ||
docs: { | ||
autodocs: 'tag' | ||
}, | ||
async webpackFinal(config) { | ||
// https://storybook.js.org/docs/react/builders/webpack | ||
// this modifies the existing image rule to exclude .svg files | ||
// since we want to handle those files with @svgr/webpack | ||
const imageRule = config.module.rules.find(rule => rule.test.test('.svg')) | ||
imageRule.exclude = /\.svg$/ | ||
|
||
// use svgr for svg files | ||
rules.push({ | ||
// configure .svg files to be loaded with @svgr/webpack | ||
config.module.rules.push({ | ||
test: /\.svg$/, | ||
use: ["@svgr/webpack"], | ||
use: ['@svgr/webpack'] | ||
}) | ||
|
||
return config; | ||
return config | ||
}, | ||
}; | ||
|
||
export default config; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
import React from 'react'; | ||
import { addDecorator, addParameters } from '@storybook/react'; | ||
import { withKnobs } from "@storybook/addon-knobs"; | ||
import { withThemePlayground } from 'storybook-addon-theme-playground'; | ||
import { ThemeProvider } from "styled-components"; | ||
import { Provider } from 'react-redux'; | ||
|
||
import theme, { Theme } from '../client/theme'; | ||
import ThemeProvider from '../client/modules/App/components/ThemeProvider'; | ||
import configureStore from '../client/store'; | ||
import '../client/styles/build/css/main.css' | ||
|
||
addDecorator(withKnobs); | ||
const initialState = window.__INITIAL_STATE__; | ||
|
||
const themeConfigs = Object.values(Theme).map( | ||
name => { | ||
return { name, theme: theme[name] }; | ||
} | ||
); | ||
const store = configureStore(initialState); | ||
|
||
addDecorator(withThemePlayground({ | ||
theme: themeConfigs, | ||
provider: ThemeProvider | ||
})); | ||
export const decorators = [ | ||
(Story) => ( | ||
<Provider store={store}> | ||
<ThemeProvider> | ||
<Story /> | ||
</ThemeProvider> | ||
</Provider> | ||
), | ||
] | ||
|
||
addParameters({ | ||
options: { | ||
/** | ||
* display the top-level grouping as a "root" in the sidebar | ||
*/ | ||
showRoots: true, | ||
}, | ||
}) | ||
|
||
// addDecorator(storyFn => <ThemeProvider theme={theme}>{storyFn()}</ThemeProvider>); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import React from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { boolean, text } from '@storybook/addon-knobs'; | ||
|
||
import Button from './Button'; | ||
import { GithubIcon, DropdownArrowIcon, PlusIcon } from './icons'; | ||
|
||
export default { | ||
title: 'Common/Button', | ||
component: Button | ||
component: Button, | ||
args: { | ||
children: 'this is the button', | ||
label: 'submit', | ||
disabled: false | ||
} | ||
}; | ||
|
||
export const AllFeatures = () => ( | ||
<Button | ||
disabled={boolean('disabled', false)} | ||
type="submit" | ||
label={text('label', 'submit')} | ||
> | ||
{text('children', 'this is the button')} | ||
export const AllFeatures = (args) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The controls on this story don't seem to do anything because we aren't passing down all of the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for investigating linting... I mistakenly thought these were linting issues on the main branch. I wasn't giving them much thought. I'll try your suggestion later today and see if I can revert them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah with stories you can set some defaults for all stories. Customise default args per story. Or present them with fixed values too if you like. Previously this This is a button story from a personal project where args were overridden.
|
||
<Button disabled={args.disabled} type="submit" label={args.label}> | ||
{args.children} | ||
</Button> | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import React from 'react'; | ||
import { select } from '@storybook/addon-knobs'; | ||
|
||
import * as icons from './icons'; | ||
|
||
export default { | ||
title: 'Common/Icons', | ||
component: icons | ||
component: icons, | ||
argTypes: { | ||
variant: { | ||
options: Object.keys(icons), | ||
control: { type: 'select' }, | ||
default: icons.CircleFolderIcon | ||
} | ||
} | ||
}; | ||
|
||
export const AllIcons = () => { | ||
const names = Object.keys(icons); | ||
|
||
const SelectedIcon = icons[select('name', names, names[0])]; | ||
export const Icons = (args) => { | ||
const SelectedIcon = icons[args.variant || 'CircleInfoIcon']; | ||
return <SelectedIcon />; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that you removed some packages from the
addons
array here but kept them in thepackage.json
. Do they need to be kept as dependencies or should they be removed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should be removed now. They've been deprecated https://www.npmjs.com/package/@storybook/addon-knobs
Actions are built in by default. And knobs have been replaced with
args
andargTypes
where you can configure controls to play with. I've updated Buttons and Icons stories to use these rather than the knobs that were there.