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

mdx 形式で Story の Docs を書くようにする #53

Merged
merged 3 commits into from
Oct 6, 2022
Merged

Conversation

yamish123
Copy link
Collaborator

@yamish123 yamish123 commented Oct 3, 2022

表題の通りです。
スマパタの Storybook の Docs から、各プロダクトの実装のリンクや、その他自由にマークダウンでドキュメンテーションするために、mdx 形式で Story の Docs を書くようにしてみました。

書きっぷりはこの辺を参考にしました。
https://github.com/storybookjs/storybook/blob/next/code/addons/docs/docs/recipes.md#csf-stories-with-mdx-docs

とりあえず「よくあるテーブル」の Story で試してみたので、良さそうであれば scaffold の作成と、他 Story への適用も行おうと思っています。

relates #6

@yamish123 yamish123 self-assigned this Oct 3, 2022
@yamish123 yamish123 requested a review from uknmr as a code owner October 3, 2022 01:19
@yamish123 yamish123 requested review from taconasu and kgsi October 3, 2022 01:19
@@ -10,7 +10,6 @@ const Template: Story<ComponentProps<typeof CommonTable>> = (props) => (
)

export const Default = Template.bind({})
Default.storyName = '基本'
Copy link
Collaborator

Choose a reason for hiding this comment

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

これは <Story story={Default} name="基本" /> が代替してくれる認識であってますか?

Copy link
Collaborator

Choose a reason for hiding this comment

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

名前は Story の近くに合ったほうが管理しやすいかも。Docs にすべてを記述しない場合もありそう。

Comment on lines 21 to 51
<Heading>パターン</Heading>

<Subheading>基本</Subheading>

<Canvas>
<Story story={Default} name="基本" />
</Canvas>

<Subheading>初期状態</Subheading>

<Canvas>
<Story story={InitialState} name="初期状態" />
</Canvas>

<Subheading>検索結果なし</Subheading>

<Canvas>
<Story story={NoSearchResult} name="検索結果なし" />
</Canvas>

<Subheading>1ページ未満</Subheading>

<Canvas>
<Story story={LessThanOnePage} name="1ページ未満" />
</Canvas>

<Subheading>テーブルの説明なし</Subheading>

<Canvas>
<Story story={NoDescription} name="テーブルの説明なし" />
</Canvas>
Copy link
Collaborator

Choose a reason for hiding this comment

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

見た目は Canvas の方で確認した方が良いもするので、一旦各プロダクトへのリンクだけでも良い気がしました!

Copy link
Collaborator Author

@yamish123 yamish123 left a comment

Choose a reason for hiding this comment

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

@uknmr
より簡便に書ける方法を見つけたので、再度確認お願いします!
d149728

Comment on lines 1 to 15
import { Canvas, Story, Title, Primary, Stories, Heading, Subheading } from '@storybook/addon-docs'

<Title />
<br />
<Heading>プロダクトごとの実装</Heading>

<Subheading>従業員サーベイ</Subheading>

- [コード](https://github.com/kufu/meyasu/blob/staging/client/src/app/components/presentations/blocks/CommonTable/CommonTable.tsx)
- [Storybook](https://staging--618dc41b452a67003aa1fedb.chromatic.com/?path=/story/blocks-commontable--default)

<Heading>Story</Heading>

<Primary />
<Stories />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

各コンポーネントの役割

  • Title
    • Story のタイトルを自動で表示してくれる(.stories.tsxexport default で指定している title の値)
  • Heading, Subheading
    • markdown の #, ## と同等だが、見出しごとにハッシュ付きのリンクを生成してくれる
  • Primary
    • 先頭の Story を表示
  • Stories
    • 戦闘以外の Story を列挙して表示

Comment on lines +90 to +94
parameters: {
docs: {
page: mdx,
},
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mdx で docs を書く場合はこんな感じで .mdx ファイルを定義しつつ、story 側で取り込む

Copy link
Collaborator

Choose a reason for hiding this comment

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

よさそう

@yamish123 yamish123 requested a review from uknmr October 4, 2022 06:03
Copy link
Collaborator

@uknmr uknmr left a comment

Choose a reason for hiding this comment

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

よさそう!
1点だけ細かいんですが消したいのがあります!

Comment on lines +90 to +94
parameters: {
docs: {
page: mdx,
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

よさそう

import { Canvas, Story, Title, Primary, Stories, Heading, Subheading } from '@storybook/addon-docs'

<Title />
<br />
Copy link
Collaborator

Choose a reason for hiding this comment

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

HTML でレイアウト調整したくないので、消したい!
やるなら CSS あてたい。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

スマセン、消しました!
2f16c69

Comment on lines +14 to +15
<Primary />
<Stories />
Copy link
Collaborator

Choose a reason for hiding this comment

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

便利〜!

@yamish123 yamish123 requested a review from uknmr October 5, 2022 08:46
Copy link
Collaborator

@uknmr uknmr left a comment

Choose a reason for hiding this comment

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

LGTM!

@yamish123 yamish123 merged commit 6a1223f into main Oct 6, 2022
@yamish123 yamish123 deleted the use-mdx branch October 6, 2022 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants