0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Storybook のすべての Story に MUI のテーマを適用したい

0
Posted at

やりたいこと

Storybook のすべての Story に MUI のテーマを適用したい。

実行結果

Story ごとに ThemeProvider を設定するとテーマが適用されました。

問題

ThemeProvider を設定していない Story には、MUI のテーマが適用されていませんでした。

原因調査

Story ごとに ThemeProvider を設定するとテーマが適用されることを確認しました。

Storybook 全体の設定を行う preview.tsx を確認しました。

原因

preview.tsx で MUI の ThemeProvider を設定していませんでした。

そのため、Story 全体にテーマが適用されていませんでした。

解決策

preview.tsxdecorators で Story 全体を ThemeProvider で囲みました。

import { ThemeProvider } from "@mui/material/styles";
import { theme } from "../src/theme";

const preview: Preview = {
  decorators: [
    (Story) => (
      <ThemeProvider theme={theme}>
        <Story />
      </ThemeProvider>
    ),
  ],
};

Story 全体を ThemeProvider で囲むことで、MUI のテーマが適用されました。

学んだこと

Storybook で全 Story に共通の Provider を適用する場合は、preview.tsxdecorators を使用できます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?