-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update react-with-storybook template for Storybook v6 (#805)
- remove `@storybook/addon-actions`, `@storybook/addon-docs`, `react-docgen-typescript-loader`, and `ts-loader` - add`@storybook/addon-essentials` - significantly simplify Storybook config - add JS/JSX support - fix a now deprecated globbing pattern - update the example Story to v6 usage - add JSDoc comments to example component to display Storybook docs generation - add a `preview.js` to automatically turn on all actions for event handlers - update/fix file structure in README
- Loading branch information
1 parent
4966edd
commit 51e47a7
Showing
6 changed files
with
39 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,4 @@ | ||
module.exports = { | ||
stories: ['../stories/**/*.stories.(ts|tsx)'], | ||
addons: ['@storybook/addon-actions', '@storybook/addon-links', '@storybook/addon-docs'], | ||
webpackFinal: async (config) => { | ||
config.module.rules.push({ | ||
test: /\.(ts|tsx)$/, | ||
use: [ | ||
{ | ||
loader: require.resolve('ts-loader'), | ||
options: { | ||
transpileOnly: true, | ||
}, | ||
}, | ||
{ | ||
loader: require.resolve('react-docgen-typescript-loader'), | ||
}, | ||
], | ||
}); | ||
|
||
config.resolve.extensions.push('.ts', '.tsx'); | ||
|
||
return config; | ||
}, | ||
stories: ['../stories/**/*.stories.@(ts|tsx|js|jsx)'], | ||
addons: ['@storybook/addon-links', '@storybook/addon-essentials'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// https://storybook.js.org/docs/react/writing-stories/parameters#global-parameters | ||
export const parameters = { | ||
// https://storybook.js.org/docs/react/essentials/actions#automatically-matching-args | ||
actions: { argTypesRegex: '^on.*' }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import React, { FC, HTMLAttributes, ReactChild } from 'react'; | ||
|
||
export interface Props extends HTMLAttributes<HTMLDivElement> { | ||
/** custom content, defaults to 'the snozzberries taste like snozzberries' */ | ||
children?: ReactChild; | ||
} | ||
|
||
// Please do not use types off of a default export module or else Storybook Docs will suffer. | ||
// see: https://github.com/storybookjs/storybook/issues/9556 | ||
/** | ||
* A custom Thing component. Neat! | ||
*/ | ||
export const Thing: FC<Props> = ({ children }) => { | ||
return <div>{children || `the snozzberries taste like snozzberries`}</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import React from 'react'; | ||
import { Meta, Story } from '@storybook/react'; | ||
import { Thing, Props } from '../src'; | ||
|
||
export default { | ||
const meta: Meta = { | ||
title: 'Welcome', | ||
component: Thing, | ||
argTypes: { | ||
children: { | ||
control: { | ||
type: 'text', | ||
}, | ||
}, | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
}, | ||
}; | ||
|
||
// By passing optional props to this story, you can control the props of the component when | ||
// you consume the story in a test. | ||
export const Default = (props?: Partial<Props>) => <Thing {...props} />; | ||
export default meta; | ||
|
||
const Template: Story<Props> = args => <Thing {...args} />; | ||
|
||
// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test | ||
// https://storybook.js.org/docs/react/workflows/unit-testing | ||
export const Default = Template.bind({}); | ||
|
||
Default.args = {}; |
51e47a7
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.
Successfully deployed to the following URLs: