Skip to content

Commit e60a748

Browse files
authored
Merge pull request #133 from DaleStudy/62-storybook-docs-dark-mode
์Šคํ† ๋ฆฌ๋ถ ๋ฌธ์„œ ๋‹คํฌ๋ชจ๋“œ ์ ์šฉ
2 parents 5d94813 + edb04dd commit e60a748

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

โ€Ž.storybook/main.tsโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const config: StorybookConfig = {
99
"@storybook/addon-interactions",
1010
"@storybook/addon-a11y",
1111
"@storybook/addon-themes",
12+
"@storybook/theming",
1213
],
1314
framework: {
1415
name: "@storybook/react-vite",

โ€Ž.storybook/preview.tsโ€Ž

Lines changed: 0 additions & 29 deletions
This file was deleted.

โ€Ž.storybook/preview.tsxโ€Ž

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "../src/index.css";
2+
import React from "react";
3+
import { withThemeByClassName } from "@storybook/addon-themes";
4+
import { DocsContainer } from "@storybook/blocks";
5+
import { themes } from "@storybook/theming";
6+
import type { Preview, ReactRenderer } from "@storybook/react";
7+
import type { DocsContainerProps } from "@storybook/blocks";
8+
9+
const preview: Preview = {
10+
parameters: {
11+
controls: {
12+
matchers: {
13+
color: /(background|color)$/i,
14+
date: /Date$/i,
15+
},
16+
},
17+
docs: {
18+
toc: true,
19+
container: (props: DocsContainerProps<ReactRenderer>) => {
20+
try {
21+
const { getStoryContext, storyById } = props.context;
22+
23+
const globals = getStoryContext(storyById()).globals;
24+
const theme = globals.theme === "dark" ? themes.dark : themes.light;
25+
return <DocsContainer {...props} theme={theme} />;
26+
} catch {
27+
return <DocsContainer {...props} />;
28+
}
29+
},
30+
},
31+
},
32+
decorators: [
33+
withThemeByClassName<ReactRenderer>({
34+
themes: {
35+
light: "",
36+
dark: "dark",
37+
},
38+
defaultTheme: "light",
39+
}),
40+
],
41+
tags: ["autodocs"],
42+
};
43+
44+
export default preview;

โ€Žbun.lockโ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€Žpackage.jsonโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@storybook/react-vite": "^8.6.12",
4848
"@storybook/test": "^8.6.12",
4949
"@storybook/test-runner": "^0.22.0",
50+
"@storybook/theming": "^8.6.11",
5051
"@testing-library/jest-dom": "^6.6.3",
5152
"@testing-library/react": "^16.2.0",
5253
"@testing-library/user-event": "^14.6.1",

0 commit comments

Comments
ย (0)