-
Notifications
You must be signed in to change notification settings - Fork 10
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
storybook v6 -> v7 #1214
Changes from 7 commits
8f223db
e163e8a
c296170
a9d43dd
c4cb735
26539a3
9343a2f
0046dcd
d35f9c5
95aca61
8beb2c1
99f1d5f
79fd3fa
a2be965
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"sourceType": "unambiguous", | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"chrome": 100 | ||
} | ||
} | ||
], | ||
"@babel/preset-typescript", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
[ | ||
"@babel/plugin-proposal-class-properties", | ||
{ | ||
"loose": true | ||
} | ||
] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
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. Reactに状態をもたせる際、renderプロパティ内に関数を書く必要があり、この中でhooksを利用すると上記のエラーが出る。 |
||
}, | ||
}, | ||
{ | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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"; | ||||||
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. Storyは非推奨、v7化以降はオブジェクトで書く。 |
||||||
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: StoryStoryObj<{{ inputs.name | pascal }}Props> = { | ||||||
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.
Suggested change
|
||||||
render: (args) => ( | ||||||
<{{ inputs.name | pascal }} {...args} /> | ||||||
) | ||||||
}; | ||||||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,26 +8,25 @@ module.exports = { | |
"@storybook/addon-essentials", | ||
"@storybook/addon-links", | ||
"@storybook/addon-storysource", | ||
"@storybook/addon-postcss", | ||
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. v7では使えなさそう そもそもPostCSS使いたくていれたものじゃなさそう 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. ref: #1226 |
||
{ | ||
// MEMO: included in addon-essentials | ||
name: "@storybook/addon-docs", | ||
options: { | ||
sourceLoaderOptions: { | ||
csfPluginOptions: { | ||
injectStoryParameters: false, | ||
}, | ||
Comment on lines
14
to
17
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. 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. @takurinton |
||
}, | ||
}, | ||
"@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, | ||
}, | ||
}; |
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"; | ||
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. v7対応されなそう 必要か判断した上で、代替手段を要調査 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. |
||
|
||
const theme = createTheme(); | ||
|
||
|
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"; | ||
|
||
|
@@ -14,7 +14,7 @@ export default { | |
}, | ||
parameters: { | ||
docs: { | ||
source: { type: "code" }, | ||
source: { language: "tsx" }, | ||
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.
|
||
page: () => ( | ||
<> | ||
<Title /> | ||
|
@@ -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, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import React from "react"; | ||
import { Story } from "@storybook/react/types-6-0"; | ||
import { Title, Subtitle, ArgsTable, Stories } from "@storybook/addon-docs"; | ||
import Badge, { BadgeProps } from "./Badge"; | ||
import { StoryObj } from "@storybook/react"; | ||
import { Title, ArgsTable, Stories } from "@storybook/addon-docs"; | ||
import Badge from "./Badge"; | ||
|
||
export default { | ||
title: "Components/Data Display/Badge", | ||
components: Badge, | ||
parameters: { | ||
docs: { | ||
source: { type: "code" }, | ||
source: { language: "tsx" }, | ||
page: () => ( | ||
<> | ||
<Title /> | ||
<Subtitle /> | ||
<ArgsTable of={Badge} /> | ||
<Stories includePrimary title="Stories" /> | ||
</> | ||
|
@@ -21,34 +20,45 @@ export default { | |
}, | ||
}; | ||
|
||
const Template: Story<BadgeProps> = (args) => <Badge {...args} />; | ||
|
||
export const Primary = Template.bind({}); | ||
Primary.args = { | ||
color: "primary", | ||
children: "primary", | ||
const Template: StoryObj<typeof Badge> = { | ||
render: (args) => <Badge {...args} />, | ||
}; | ||
|
||
export const Secondary = Template.bind({}); | ||
Secondary.args = { | ||
color: "secondary", | ||
children: "secondary", | ||
export const Primary: StoryObj<typeof Badge> = { | ||
...Template, | ||
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. これまでTemplateはこんな感じに書く ref: https://storybook.js.org/docs/react/writing-stories/introduction#using-args |
||
args: { | ||
color: "primary", | ||
children: "primary", | ||
}, | ||
}; | ||
|
||
export const Success = Template.bind({}); | ||
Success.args = { | ||
color: "success", | ||
children: "success", | ||
export const Secondary: StoryObj<typeof Badge> = { | ||
...Template, | ||
args: { | ||
color: "secondary", | ||
children: "secondary", | ||
}, | ||
}; | ||
export const Success: StoryObj<typeof Badge> = { | ||
...Template, | ||
args: { | ||
color: "success", | ||
children: "success", | ||
}, | ||
}; | ||
|
||
export const Warning = Template.bind({}); | ||
Warning.args = { | ||
color: "warning", | ||
children: "warning", | ||
export const Warning: StoryObj<typeof Badge> = { | ||
...Template, | ||
args: { | ||
color: "warning", | ||
children: "warning", | ||
}, | ||
}; | ||
|
||
export const Danger = Template.bind({}); | ||
Danger.args = { | ||
color: "danger", | ||
children: "danger", | ||
export const Danger: StoryObj<typeof Badge> = { | ||
...Template, | ||
args: { | ||
color: "danger", | ||
children: "danger", | ||
}, | ||
}; |
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.
v7からは.babelrcを作ってそれを読むようになるっぽい
https://storybook.js.org/docs/react/configure/babel#v7-mode