1
1

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 3 years have passed since last update.

Material-UI 5 で Button のリップルエフェクトと AppBar の影を消す

Posted at

背景

Material-UI 5 になって Theme の書き方が変わりました

image.png

修正後

import { createTheme } from "@mui/material"

export const theme = createTheme({
  components: {
    MuiButtonBase: {
      defaultProps: {
        disableRipple: true
      },
    },
    MuiAppBar: {
      defaultProps: {
        elevation: 0
      },
    },
  },
})
  • props から components 内の defaultProps に変わりました
  • elevation を 0 にすると影を消せます

参考: https://mui.com/getting-started/faq/#heading-how-can-i-disable-the-ripple-effect-globally

おまけ

AppBar の下に罫線をつける

罫線にはパレットの divider の色を使いたいので、一度 palette だけで createTheme に渡してテーマを生成し、そのテーマを参照する形で再び createTheme でテーマを作成します。

スクリーンショット 2021-09-24 12.00.12.png

import { createTheme } from "@mui/material"

const baseTheme = createTheme({
  palette: {
    primary: {
      main: "#4f54f9",
    },
    secondary: {
      main: "#f50016",
    },
    background: {
      default: "#ffffff",
    },
  },
})

export const theme = createTheme(baseTheme, {
  components: {
    MuiButtonBase: {
      defaultProps: {
        disableRipple: true,
      },
    },
    MuiAppBar: {
      defaultProps: {
        color: "transparent",
        elevation: 0,
      },
      styleOverrides: {
        root: {
          borderBottom: `1px solid ${baseTheme.palette.divider}`,
        },
      },
    },
  },
})
1
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?