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

docs: TabBar の Story を見直し #4949

Merged
merged 7 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/smarthr-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ const config: StorybookConfig = {
options: {},
},
staticDirs: ['../public'],
docs: {
autodocs: true,
},
typescript: {
reactDocgen: 'react-docgen-typescript',
},
Expand Down
4 changes: 4 additions & 0 deletions packages/smarthr-ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const preview: Preview = {
<Stories includePrimary={false} />
</>
),
canvas: {
sourceState: 'shown',
},
},
chromatic: {
forcedColors: 'none',
Expand Down Expand Up @@ -102,6 +105,7 @@ const preview: Preview = {
)
},
],
tags: ['autodocs'],
}

export default preview
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import TabBarStories from './TabBar.stories'

import type { StoryObj } from '@storybook/react'

export default {
...TabBarStories,
title: 'Navigation(ナビゲーション)/TabBar/bordered',
tags: ['!autodocs'],
}

export const True: StoryObj = {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nits]

細かいですが、StoryObj は T にコンポーネントの型を渡してあげると props が型安全になるので書き心地が良くなります!

export const True: StoryObj<typeof TabBar> = {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

e2ee5ca で対応しました!
すべての Story に書くの面倒だなぁ、default に指定した型でよしなにやってほしいなぁ、と思ってました😇
雛形作る時に自動生成させても良さそうですね。

name: 'true',
args: {
bordered: true,
},
}

export const False = {
name: 'false',
args: {
bordered: false,
},
}
68 changes: 26 additions & 42 deletions packages/smarthr-ui/src/components/TabBar/TabBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,38 @@
import { action } from '@storybook/addon-actions'
import { StoryFn } from '@storybook/react'
import { userEvent } from '@storybook/test'
import React from 'react'

import { Badge } from '../Badge'
import { Stack } from '../Layout'

import { TabBar } from './TabBar'
import { TabItem } from './TabItem'

import type { Meta } from '@storybook/react'

export default {
title: 'Navigation(ナビゲーション)/TabBar',
component: TabBar,
subcomponents: { TabItem },
}

export const All: StoryFn = () => (
<Stack as="ul" className="shr-list-none">
<li>
<p>標準</p>
<Template subid={1} />
</li>
<li>
<p>下線なし</p>
<Template subid={2} bordered={false} />
</li>
</Stack>
)
render: (args) => (
<TabBar {...args}>
<TabItem id="tab1" onClick={action('tab1')} selected>
タブ1
</TabItem>
<TabItem id="tab2" onClick={action('tab2')}>
タブ2
</TabItem>
</TabBar>
),
parameters: {
chromatic: { disableSnapshot: true },
},
} as Meta<typeof TabBar>

const Template: StoryFn = ({ subid, ...props }) => (
<TabBar {...props}>
<TabItem id={`border-${subid}-1`} onClick={action('clicked')} selected>
基本情報
</TabItem>
<TabItem id={`border-${subid}-2`} onClick={action('clicked')} suffix={<Badge count={7} />}>
コメント
</TabItem>
<TabItem
id={`border-${subid}-3`}
onClick={action('clicked')}
disabled
disabledDetail={{ message: 'この機能は使用できません。' }}
>
分析対象
</TabItem>
</TabBar>
)

export const RegFocusBorder = All.bind({})
RegFocusBorder.play = () => userEvent.tab()
export const Default = {
args: {
bordered: true,
},
}

export const RegFocusNoBorder = All.bind({})
RegFocusNoBorder.play = () => [...Array(4)].forEach((_) => userEvent.tab())
export const Playground = {
args: {
bordered: true,
},
}
61 changes: 61 additions & 0 deletions packages/smarthr-ui/src/components/TabBar/TabItem.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { action } from '@storybook/addon-actions'
import React from 'react'

import { Badge } from '../Badge'

import { TabItem } from './TabItem'

import type { Meta } from '@storybook/react'

export default {
title: 'Navigation(ナビゲーション)/TabBar/TabItem',
component: TabItem,
render: (args) => <TabItem {...args} />,
args: {
children: 'タブ',
id: 'tab1',
onClick: action('clicked'),
},
parameters: {
chromatic: { disableSnapshot: true },
},
} as Meta<typeof TabItem>

export const TabItemControl = {
name: 'Playground',
args: {
selected: true,
disabled: false,
},
}

export const Selected = {
name: 'selected',
args: {
selected: true,
},
}

export const Suffix = {
name: 'suffix',
args: {
suffix: <Badge count={1} />,
},
}

export const Disabled = {
name: 'disabled',
args: {
disabled: true,
},
}

export const DisabledDetail = {
name: 'disabledDetail',
args: {
disabled: true,
disabledDetail: {
message: '無効な理由',
},
},
}
Loading