Skip to content
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

storybook v6 -> v7 #1214

Merged
merged 14 commits into from
Apr 24, 2023
23 changes: 23 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v7からは.babelrcを作ってそれを読むようになるっぽい

https://storybook.js.org/docs/react/configure/babel#v7-mode

"sourceType": "unambiguous",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": 100
}
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"plugins": [
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
}
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ module.exports = {
// I realize it's silly of me, but I'll turn it off here for the sake of specs for once.
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-static-element-interactions": "off",
"react-hooks/rules-of-hooks": "off",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reactに状態をもたせる際、renderプロパティ内に関数を書く必要があり、この中でhooksを利用すると上記のエラーが出る。
いちいちエラーを消すのは手間であるため、*.stories.tsxではこのルールをoffにした。

},
},
{
Expand Down
10 changes: 6 additions & 4 deletions .scaffdog/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ describe("{{ inputs.name | pascal }} component testing", () => {

```typescript
import * as React from "react";
import { Story } from "@storybook/react/types-6-0";
import { StoryObj } from "@storybook/react";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storyは非推奨、v7化以降はオブジェクトで書く。
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#story-type-deprecated

import {{ inputs.name | pascal }}, { {{ inputs.name | pascal }}Props } from "./{{ inputs.name | pascal }}";

export default {
title: "Components/〇〇/{{ inputs.name | pascal }}",
component: {{ inputs.name | pascal }},
};

export const Example: Story<{{ inputs.name | pascal }}Props> = (args) => (
<{{ inputs.name | pascal }} {...args} />
);
export const Example: StoryObj<{{ inputs.name | pascal }}Props> = {
render: (args) => (
<{{ inputs.name | pascal }} {...args} />
)
};
```
21 changes: 10 additions & 11 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ module.exports = {
"@storybook/addon-essentials",
"@storybook/addon-links",
"@storybook/addon-storysource",
"@storybook/addon-postcss",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v7では使えなさそう
storybookjs/storybook#20529

そもそもPostCSS使いたくていれたものじゃなさそう
https://github.com/voyagegroup/ingred-ui/blame/master/.storybook/main.js#L11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref: #1226

{
// MEMO: included in addon-essentials
name: "@storybook/addon-docs",
options: {
sourceLoaderOptions: {
csfPluginOptions: {
injectStoryParameters: false,
},
Comment on lines 14 to 17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
},
"@storybook/addon-mdx-gfm",
],
reactOptions: {
// TODO: fix warn "Rendered more hooks than during the previous render."
// strictMode: true,
features: {
babelModeV7: true,
},
babel: async (options) => ({
...options,
plugins: [["@babel/plugin-proposal-class-properties", { loose: true }]],
}),
core: {
builder: "webpack5",
framework: {
name: "@storybook/react-webpack5",
options: {},
},
docs: {
autodocs: true,
},
};
1 change: 0 additions & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from "react";
import { ThemeProvider, createTheme } from "../src/themes";
import "@storybook/addon-console";
Copy link
Contributor Author

@penicillin0 penicillin0 Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v7対応されなそう
storybookjs/storybook-addon-console#65

必要か判断した上で、代替手段を要調査

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const theme = createTheme();

Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"build": "NODE_ENV=production rollup -c",
"start": "rollup -c -w",
"playground": "yarn build && cd testEnv && yarn install && yarn start",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"lint": "tsc && eslint 'src/**/*.{ts,tsx}' && prettier --check 'src/**/*.{ts,tsx}'",
"format": "prettier --write 'src/**/*.{ts,tsx}'",
"generate": "yarn scaffdog generate"
Expand All @@ -39,18 +39,19 @@
"styled-components": ">= 5.X"
},
"devDependencies": {
"@babel/preset-env": "^7.21.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.4",
"@rollup/plugin-commonjs": "24.1.0",
"@rollup/plugin-node-resolve": "15.0.0",
"@rollup/plugin-typescript": "11.1.0",
"@rollup/plugin-url": "8.0.0",
"@storybook/addon-console": "1.2.3",
"@storybook/addon-essentials": "6.5.9",
"@storybook/addon-links": "6.5.9",
"@storybook/addon-postcss": "2.0.0",
"@storybook/addon-storysource": "6.5.9",
"@storybook/builder-webpack5": "6.5.12",
"@storybook/manager-webpack5": "6.5.12",
"@storybook/react": "6.5.9",
"@storybook/addon-essentials": "7.1.0-alpha.5",
"@storybook/addon-links": "7.1.0-alpha.5",
"@storybook/addon-mdx-gfm": "7.1.0-alpha.5",
"@storybook/addon-storysource": "7.1.0-alpha.5",
"@storybook/react": "7.1.0-alpha.5",
"@storybook/react-webpack5": "7.1.0-alpha.5",
"@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "14.0.0",
"@types/jest": "28.1.1",
Expand Down Expand Up @@ -81,6 +82,7 @@
"rollup-plugin-postcss": "4.0.2",
"rollup-plugin-terser": "7.0.2",
"scaffdog": "2.5.0",
"storybook": "7.1.0-alpha.5",
"styled-components": "5.3.5",
"ts-jest": "28.0.4",
"typescript": "4.9.3"
Expand Down
129 changes: 68 additions & 61 deletions src/components/Accordion/Accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { Story } from "@storybook/react/types-6-0";
import { StoryObj } from "@storybook/react";
import Accordion, { AccordionProps } from "./Accordion";

export default {
Expand All @@ -13,64 +13,22 @@ export default {
},
};

export const Example: Story<AccordionProps> = (args) => (
<>
export const Example: StoryObj<AccordionProps> = {
render: (args) => (
<Accordion
title={args.title}
disabled={args.disabled}
expanded={args.expanded}
>
<div style={{ padding: "4px 8px" }}>{args.children}</div>
</Accordion>
</>
);

export const Multiple: Story<AccordionProps> = () => (
<>
<Accordion title="title1">
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
augue, efficitur eget tincidunt non, accumsan et est. Aliquam lobortis
elit lorem, id ullamcorper libero elementum non. Sed rutrum porta enim,
et aliquet velit hendrerit ac. Morbi tincidunt eleifend elit.
</div>
</Accordion>
<Accordion title="title2">
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
augue, efficitur eget tincidunt non, accumsan et est. Aliquam lobortis
elit lorem, id ullamcorper libero elementum non. Sed rutrum porta enim,
et aliquet velit hendrerit ac. Morbi tincidunt eleifend elit.
</div>
</Accordion>
<Accordion disabled title="disabled">
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
augue, efficitur eget tincidunt non, accumsan et est. Aliquam lobortis
elit lorem, id ullamcorper libero elementum non. Sed rutrum porta enim,
et aliquet velit hendrerit ac. Morbi tincidunt eleifend elit.
</div>
</Accordion>
</>
);

export const Controlled: Story<AccordionProps> = () => {
const [expanded, setExpanded] = React.useState<string | false>(false);
const handleChange =
(panel: string) => (_: React.SyntheticEvent, newExpanded: boolean) => {
setExpanded(newExpanded ? panel : false);
};
),
};

return (
export const Multiple: StoryObj<AccordionProps> = {
render: () => (
<>
<Accordion
title="title1"
expanded={expanded === "title1"}
onChange={handleChange("title1")}
>
<Accordion title="title1">
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
Expand All @@ -79,11 +37,7 @@ export const Controlled: Story<AccordionProps> = () => {
enim, et aliquet velit hendrerit ac. Morbi tincidunt eleifend elit.
</div>
</Accordion>
<Accordion
title="title2"
expanded={expanded === "title2"}
onChange={handleChange("title2")}
>
<Accordion title="title2">
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
Expand All @@ -92,11 +46,7 @@ export const Controlled: Story<AccordionProps> = () => {
enim, et aliquet velit hendrerit ac. Morbi tincidunt eleifend elit.
</div>
</Accordion>
<Accordion
title="title3"
expanded={expanded === "title3"}
onChange={handleChange("title3")}
>
<Accordion disabled title="disabled">
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
Expand All @@ -106,5 +56,62 @@ export const Controlled: Story<AccordionProps> = () => {
</div>
</Accordion>
</>
);
),
};

export const Controlled: StoryObj<AccordionProps> = {
render: () => {
const [expanded, setExpanded] = React.useState<string | false>(false);
const handleChange =
(panel: string) => (_: React.SyntheticEvent, newExpanded: boolean) => {
setExpanded(newExpanded ? panel : false);
};

return (
<>
<Accordion
title="title1"
expanded={expanded === "title1"}
onChange={handleChange("title1")}
>
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
augue, efficitur eget tincidunt non, accumsan et est. Aliquam
lobortis elit lorem, id ullamcorper libero elementum non. Sed rutrum
porta enim, et aliquet velit hendrerit ac. Morbi tincidunt eleifend
elit.
</div>
</Accordion>
<Accordion
title="title2"
expanded={expanded === "title2"}
onChange={handleChange("title2")}
>
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
augue, efficitur eget tincidunt non, accumsan et est. Aliquam
lobortis elit lorem, id ullamcorper libero elementum non. Sed rutrum
porta enim, et aliquet velit hendrerit ac. Morbi tincidunt eleifend
elit.
</div>
</Accordion>
<Accordion
title="title3"
expanded={expanded === "title3"}
onChange={handleChange("title3")}
>
<div style={{ padding: "4px 8px" }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc velit
magna, dictum vel elementum ac, fermentum quis lorem. Aliquam sapien
augue, efficitur eget tincidunt non, accumsan et est. Aliquam
lobortis elit lorem, id ullamcorper libero elementum non. Sed rutrum
porta enim, et aliquet velit hendrerit ac. Morbi tincidunt eleifend
elit.
</div>
</Accordion>
</>
);
},
};
26 changes: 15 additions & 11 deletions src/components/ActionButton/ActionButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action } from "@storybook/addon-actions";
import { ArgsTable, Description, Stories, Title } from "@storybook/addon-docs";
import { Story } from "@storybook/react/types-6-0";
import { StoryObj } from "@storybook/react";
import React from "react";
import ActionButton, { ActionButtonProps } from "./ActionButton";

Expand All @@ -14,7 +14,7 @@ export default {
},
parameters: {
docs: {
source: { type: "code" },
source: { language: "tsx" },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: "code"の場合、オブジェクトがそのまま表示されてしまい、docとしての役割としては実装サンプルが見えているはずなので、language: "tsx"にする。
ref: https://storybook.js.org/docs/angular/api/doc-block-source#language

page: () => (
<>
<Title />
Expand All @@ -27,16 +27,20 @@ export default {
},
};

const Template: Story<ActionButtonProps> = (args) => <ActionButton {...args} />;

export const Primary = Template.bind({});
export const Primary: StoryObj<ActionButtonProps> = {
args: {
color: "primary",
},
};

export const Warning = Template.bind({});
Warning.args = {
color: "warning",
export const Warning: StoryObj<ActionButtonProps> = {
args: {
color: "warning",
},
};

export const Disabled = Template.bind({});
Disabled.args = {
disabled: true,
export const Disabled: StoryObj<ActionButtonProps> = {
args: {
disabled: true,
},
};
Loading