1
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?

More than 1 year has passed since last update.

【小ネタ】MUI の SvgIcon の色を Theme で変更する

Last updated at Posted at 2022-10-21

はじめに

たまにハマって調べるので備忘録として。

対応バージョン

  • MUI > v5.10.10 (たぶん、5系なら大丈夫)

やり方

import { ThemeProvider } from "@mui/material/styles";
import { createTheme } from "@mui/material/styles";
import { createRoot } from "react-dom/client";
import App from "./app";

const theme = createTheme({
  components: {
    MuiSvgIcon: {
      styleOverrides: {
        colorPrimary: {
          "& path": {
            color: "#67C23A",
          },
        },
      },
    },
  }
});

const container = document.getElementById("root");
const root = createRoot(container as Element);
root.render(
  <ThemeProvider>
    <App />
  </ThemeProvider>
);

軽く説明

SvgIcon は、 svg タグの子要素として path タグがあり、アイコンはその path タグで描いているため、
色を変える場合は path タグを指定する必要がある。

1
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
1
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?