-
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
Refactor Storybook <Button /> #213
Changes from 11 commits
d90edab
e0244ce
44abff7
5093b89
73cb828
45e7d15
5eb9f5f
dc5aff1
b0617ad
7cd7799
022fff3
8507659
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 |
---|---|---|
|
@@ -61,19 +61,35 @@ describe("{{ input | pascal }} component testing", () => { | |
|
||
``` | ||
|
||
# `{{ input }}/{{ input }}.stories.tsx` | ||
# `{{ input | pascal }}/{{ input | pascal }}.stories.mdx` | ||
|
||
```typescript | ||
import * as React from "react"; | ||
import {{ input }} from "./index"; | ||
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks"; | ||
import {{ input | pascal }} from "./index"; | ||
|
||
export default { | ||
title: "{{ input }}", | ||
component: {{ input }}, | ||
}; | ||
<Meta | ||
title="{{ input | pascal }}" | ||
component={ {{ input | pascal }} } | ||
argTypes={ | ||
{ onClick: { action: "clicked" } } | ||
} | ||
Comment on lines
+73
to
+75
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. |
||
/> | ||
|
||
export const Overview = () => ( | ||
<{{ input }} /> | ||
); | ||
# {{ input | pascal }} | ||
|
||
<ArgsTable of={ {{ input | pascal }} } /> | ||
|
||
## Samples | ||
|
||
### Something | ||
|
||
<Canvas> | ||
<Story | ||
name="something" | ||
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. 実際に生成すると |
||
> | ||
{(args) => <{{ input | pascal }} {...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.
Buttonのやつみる限り、複数回 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. 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. なるほど、MDXCreateElementは |
||
</Story> | ||
</Canvas> | ||
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
module.exports = { | ||
stories: ["../src/components/**/*.stories.tsx"], | ||
stories: [ | ||
"../src/components/**/*.stories.tsx", | ||
"../src/components/**/*.stories.mdx", | ||
], | ||
addons: [ | ||
"@storybook/addon-actions", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-knobs", | ||
"@storybook/addon-notes", | ||
// TODO: Remove this addon after replace to `.mdx`. | ||
"@storybook/addon-storysource", | ||
], | ||
reactOptions: { | ||
fastRefresh: true, | ||
strictMode: true, | ||
// TODO: fix warn "Rendered more hooks than during the previous render." | ||
// knobを完全に排除できたタイミングで再度調査 | ||
// strictMode: true, | ||
Comment on lines
+14
to
+16
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. memo |
||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
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. |
||
|
||
|
||
const theme = createTheme(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
"deploy": "gh-pages -d example/build", | ||
"storybook": "start-storybook -s ./assets -p 6006", | ||
"build-storybook": "build-storybook", | ||
"lint": "eslint 'src/**/*.{ts,tsx}'", | ||
"lint": "eslint 'src/**/*.{ts,tsx,mdx}'", | ||
"generate": "yarn scaffdog generate", | ||
"format": "yarn lint --fix" | ||
}, | ||
|
@@ -40,10 +40,10 @@ | |
"styled-components": ">= 5.X" | ||
}, | ||
"devDependencies": { | ||
"@storybook/addon-actions": "^6.1.6", | ||
"@storybook/addon-knobs": "^6.1.6", | ||
"@storybook/addon-notes": "^5.3.21", | ||
"@storybook/addon-storysource": "^6.1.6", | ||
"@storybook/addon-console": "^1.2.2", | ||
"@storybook/addon-essentials": "^6.1.9", | ||
"@storybook/addon-knobs": "^6.1.9", | ||
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. そうですね。前のやつと互換を取るためです!
合ってます!がライブラリとしては別モノなので、一気に乗り換えるためには修正は必要でして。。。 いずれ全て変わるので、一気にやらなくても良いかなという判断です! 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. 👍 |
||
"@storybook/addon-storysource": "^6.1.10", | ||
"@storybook/react": "^6.1.6", | ||
"@svgr/rollup": "^2.4.1", | ||
"@testing-library/jest-dom": "^5.11.0", | ||
|
@@ -64,12 +64,15 @@ | |
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jest": "^24.1.3", | ||
"eslint-plugin-mdx": "^1.8.2", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"eslint-plugin-react": "^7.21.5", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"gh-pages": "^1.2.0", | ||
"jest": "^26.1.0", | ||
"prettier": "^2.1.2", | ||
"react": ">= 16.6.1", | ||
"react-dom": ">= 16.6.1", | ||
"rollup": "^2.33.3", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-imagemin": "^0.4.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ import Button from "../Button"; | |
export default { | ||
title: "Backdrop", | ||
component: Backdrop, | ||
parameters: { | ||
docs: { page: null }, | ||
}, | ||
Comment on lines
+10
to
+12
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. 現行の
ということで共通で見れないようにした。 |
||
}; | ||
|
||
export const Overview: React.FunctionComponent = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks"; | ||
import Button from "./Button"; | ||
|
||
<Meta | ||
title="Button" | ||
component={Button} | ||
argTypes={{ onClick: { action: "clicked" } }} | ||
/> | ||
|
||
# Button | ||
|
||
<ArgsTable of={Button} /> | ||
|
||
## Samples | ||
|
||
### Colors | ||
|
||
<Canvas> | ||
<Story | ||
name="primary" | ||
args={{ | ||
color: "primary", | ||
children: "primary", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
<Story | ||
name="secondary" | ||
args={{ | ||
color: "secondary", | ||
children: "secondary", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
Comment on lines
+18
to
+36
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 | ||
name="danger" | ||
args={{ | ||
color: "danger", | ||
children: "danger", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
</Canvas> | ||
|
||
### Sizes | ||
|
||
<Canvas> | ||
<Story | ||
name="small" | ||
args={{ | ||
size: "small", | ||
children: "small", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
<Story | ||
name="medium" | ||
args={{ | ||
size: "medium", | ||
children: "medium", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
<Story | ||
name="large" | ||
args={{ | ||
size: "large", | ||
children: "large", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
</Canvas> | ||
|
||
### Disabled | ||
|
||
<Canvas> | ||
<Story | ||
name="disabled" | ||
args={{ | ||
disabled: true, | ||
children: "disabled", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
</Canvas> | ||
|
||
### Use "href" props | ||
|
||
<Canvas> | ||
<Story | ||
name="Use href props" | ||
args={{ | ||
href: "https://google.com", | ||
children: "Link to google.com", | ||
}} | ||
> | ||
{(args) => <Button {...args} />} | ||
</Story> | ||
</Canvas> | ||
|
||
### Use with router library like "react-router" | ||
|
||
Here's an example code. | ||
|
||
But We have plan to change like [Material-UI](https://material-ui.com/guides/composition/#link). | ||
|
||
```tsx | ||
// Get "className" prop to enable <Button /> style. | ||
const LinkToHome = ({ className, children }) => ( | ||
// "href" prop defines not via <Button /> | ||
<Link className={className} href="/home"> | ||
{children} | ||
</Link> | ||
); | ||
|
||
const ButtonWithRouterLink = ({ children }) => ( | ||
<Button component={LinkToHome}>{children}</Button> | ||
); | ||
``` |
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.
めちゃくちゃ細かいんだけど
https://storybook.js.org/docs/react/writing-docs/mdx#writing-stories
のtitleのところを例えば
Component/{{ input | pascal }}
みたいにディレクトリ切る感じで書いていくとこんな感じ(ここだと
<Meta title="MDX/Badge">
)になるんだけど、分けていった方がみやすいかな?って思ったんだけどどうでしょう!とかくらいに分かれるかなーっていうイメージ
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.
ああ、全然良いと思います:+1:
別PRでやりましょうか !!
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.
そうしましょう!
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.
この辺にちょろっと書いた
#212 (comment)