Skip to content

Commit

Permalink
Merge pull request #4520 from kobotoolbox/bugfix/storybook-typescript-5
Browse files Browse the repository at this point in the history
Get Storybook compatible with TypeScript 5.x
  • Loading branch information
bufke committed Jun 30, 2023
2 parents f692299 + 547773c commit 098dc0e
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ module.exports = {
core: {
builder: '@storybook/builder-webpack5',
},
typescript: {
reactDocgen: 'react-docgen-typescript-plugin',
},
webpackFinal: async (config, {configType}) => {
config.plugins.push(new webpack.ProvidePlugin({$: 'jquery'}));
config.module.rules.push({
Expand Down
2 changes: 1 addition & 1 deletion jsapp/js/components/common/checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
} as ComponentMeta<typeof Checkbox>;

const Template: ComponentStory<typeof Checkbox> = (args) => (
<Checkbox {...args} />
<Checkbox {...args} onChange={() => {}} />
);

export const Primary = Template.bind({});
Expand Down
20 changes: 15 additions & 5 deletions jsapp/js/components/common/radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useState} from 'react';
import type {ComponentStory, ComponentMeta} from '@storybook/react';
import Radio from './radio';
import type {RadioOption} from './radio';
Expand Down Expand Up @@ -29,9 +29,19 @@ export default {
argTypes: {},
} as ComponentMeta<typeof Radio>;

const Template: ComponentStory<typeof Radio> = (args) => (
<Radio {...args} options={defaultOptions} />
);
const Template: ComponentStory<typeof Radio> = (args) => {
const [selected, setSelected] = useState('');
return (
<Radio
{...args}
selected={selected}
onChange={(newSelectedValue) => setSelected(newSelectedValue)}
options={defaultOptions}
/>
);
};

export const Primary = Template.bind({});
Primary.args = {title: 'Pick your favourite food'};
Primary.args = {
title: 'Pick your favourite food',
};
217 changes: 217 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"postcss": "^7.0.30",
"postcss-loader": "^4.2.0",
"prettier": "^2.7.1",
"react-docgen-typescript-plugin": "^1.0.5",
"react-hot-loader": "3.1.0",
"react-refresh": "^0.14.0",
"replace-in-file": "^6.0.0",
Expand Down

0 comments on commit 098dc0e

Please sign in to comment.