Skip to content

Commit 3b80724

Browse files
authored
docs(storybook): chartsのストーリーをsmarthr-uiのStorybookに統合する (#6249)
1 parent 2637cfd commit 3b80724

9 files changed

Lines changed: 50 additions & 24 deletions

File tree

packages/charts/src/components/BarChart/BarChart.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { chartJsOptionsExamples, multiSmall, singleSmall } from '../__stories__/
22

33
import { BarChart } from './BarChart'
44

5-
import type { Meta, StoryObj } from '@storybook/react-webpack5'
5+
import type { Meta, StoryObj } from '@storybook/react-vite'
66

77
const meta: Meta<typeof BarChart> = {
8-
title: 'BarChart',
8+
title: 'Charts/BarChart',
99
component: BarChart,
1010
decorators: [
1111
(Story) => (

packages/charts/src/components/BarChart/VRTBarChart.stories.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line smarthr/require-barrel-import
12
import { Stack } from '../../../../smarthr-ui/src/components/Layout'
23
import {
34
chartJsOptionsExamples,
@@ -8,11 +9,9 @@ import {
89

910
import { BarChart } from './BarChart'
1011

11-
import type { StoryObj } from '@storybook/react-webpack5'
12-
1312
export default {
14-
title: 'BarChart/VRT',
15-
render: (args: any) => (
13+
title: 'Charts/BarChart/VRT',
14+
render: (args) => (
1615
<Stack {...args}>
1716
{/* パターン1: 単一データセット、タイトルなし、ラベルなし、標準サイズ、少データ */}
1817
<div className="shr-h-[400px]">
@@ -71,7 +70,7 @@ export default {
7170

7271
export const VRT = {}
7372

74-
export const VRTForcedColors: StoryObj = {
73+
export const VRTForcedColors = {
7574
...VRT,
7675
parameters: {
7776
chromatic: { forcedColors: 'active' },

packages/charts/src/components/Chart/Chart.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { chartJsOptionsExamples, multiSmall, singleSmall } from '../__stories__/
22

33
import { Chart } from './Chart'
44

5-
import type { Meta, StoryObj } from '@storybook/react-webpack5'
5+
import type { Meta, StoryObj } from '@storybook/react-vite'
66

77
const meta: Meta<typeof Chart> = {
8-
title: 'Chart',
8+
title: 'Charts/Chart',
99
component: Chart,
1010
decorators: [
1111
(Story) => (

packages/charts/src/components/Chart/VRTChart.stories.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
// eslint-disable-next-line smarthr/require-barrel-import
12
import { Stack } from '../../../../smarthr-ui/src/components/Layout'
23
import { multiSmall, singleSmall } from '../__stories__/testData'
34

45
import { Chart } from './Chart'
56

6-
import type { StoryObj } from '@storybook/react-webpack5'
7-
87
export default {
9-
title: 'Chart/VRT',
10-
render: (args: any) => (
8+
title: 'Charts/Chart/VRT',
9+
render: (args) => (
1110
<Stack {...args}>
1211
{/* Bar型 パターン1: 単一データセット、タイトルあり、標準サイズ */}
1312
<div className="shr-h-[400px]">
@@ -38,7 +37,7 @@ export default {
3837

3938
export const VRT = {}
4039

41-
export const VRTForcedColors: StoryObj = {
40+
export const VRTForcedColors = {
4241
...VRT,
4342
parameters: {
4443
chromatic: { forcedColors: 'active' },

packages/charts/src/components/LineChart/LineChart.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { chartJsOptionsExamples, multiSmall, singleSmall } from '../__stories__/
22

33
import { LineChart } from './LineChart'
44

5-
import type { Meta, StoryObj } from '@storybook/react-webpack5'
5+
import type { Meta, StoryObj } from '@storybook/react-vite'
66

77
const meta: Meta<typeof LineChart> = {
8-
title: 'LineChart',
8+
title: 'Charts/LineChart',
99
component: LineChart,
1010
decorators: [
1111
(Story) => (

packages/charts/src/components/LineChart/VRTLineChart.stories.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line smarthr/require-barrel-import
12
import { Stack } from '../../../../smarthr-ui/src/components/Layout'
23
import {
34
chartJsOptionsExamples,
@@ -8,11 +9,9 @@ import {
89

910
import { LineChart } from './LineChart'
1011

11-
import type { StoryObj } from '@storybook/react-webpack5'
12-
1312
export default {
14-
title: 'LineChart/VRT',
15-
render: (args: any) => (
13+
title: 'Charts/LineChart/VRT',
14+
render: (args) => (
1615
<Stack {...args}>
1716
{/* パターン1: 単一データセット、タイトルなし、ラベルなし、標準サイズ、少データ */}
1817
<div className="shr-h-[400px]">
@@ -71,7 +70,7 @@ export default {
7170

7271
export const VRT = {}
7372

74-
export const VRTForcedColors: StoryObj = {
73+
export const VRTForcedColors = {
7574
...VRT,
7675
parameters: {
7776
chromatic: { forcedColors: 'active' },

packages/smarthr-ui/.storybook/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import tailwindcss from 'tailwindcss'
66
import type { StorybookConfig } from '@storybook/react-vite'
77

88
export default {
9-
stories: ['../src/**/*.stories.tsx'],
9+
stories: ['../src/**/*.stories.tsx', '../../charts/src/**/*.stories.tsx'],
1010
addons: [
1111
'@storybook/addon-docs',
1212
'storybook-addon-pseudo-states',
@@ -52,7 +52,10 @@ export default {
5252
},
5353
css: {
5454
postcss: {
55-
plugins: [tailwindcss, autoprefixer],
55+
plugins: [
56+
tailwindcss({ config: join(__dirname, 'tailwind.storybook.config.ts') }),
57+
autoprefixer,
58+
],
5659
},
5760
},
5861
}),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// eslint-disable-next-line smarthr/require-barrel-import -- Storybook 専用。本番の tailwind.config と同じプリセットを参照する。
2+
import preset from '../src/smarthr-ui-preset'
3+
4+
import type { Config } from 'tailwindcss'
5+
6+
/**
7+
* Storybook のみ。`@smarthr/smarthr-ui-charts` のストーリー用クラスを含め、本番 `smarthr-ui.css` の content には含めない。
8+
*
9+
* `content.relative: true` がないと、`../src` 等が **カレントディレクトリ**基準で解決され、
10+
* `packages/smarthr-ui` で起動したとき `../src` → `packages/src`(存在しない)となり JIT がファイルを一切見つけられない。
11+
* `true` にするとパスは **この設定ファイルのあるディレクトリ**(`.storybook/`)基準になる。
12+
*
13+
* @see https://tailwindcss.com/docs/content-configuration
14+
*/
15+
export default {
16+
presets: [preset],
17+
content: {
18+
relative: true,
19+
files: ['../src/**/*.{js,jsx,ts,tsx}', '../../charts/src/**/*.{js,jsx,ts,tsx}'],
20+
},
21+
} satisfies Config

packages/smarthr-ui/knip.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"$schema": "https://unpkg.com/knip@6/schema.json",
33
"vitest": false,
44
"storybook": {
5-
"entry": [".storybook/main.ts", ".storybook/preview.tsx", ".storybook/manager.ts"]
5+
"entry": [
6+
".storybook/main.ts",
7+
".storybook/preview.tsx",
8+
".storybook/manager.ts",
9+
".storybook/tailwind.storybook.config.ts"
10+
]
611
},
712
"entry": ["scripts/**/*.ts"],
813
"ignore": ["**/*.stories.tsx", "rollup.*.config.js", "vitest.config.ts", "vitest-setup.js"],

0 commit comments

Comments
 (0)