最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

material ui - React MUI: How to add a custom text property in MUI palette theme? - Stack Overflow

programmeradmin2浏览0评论

Is it possible to add a custom property to theme > palette > text? I want to add 'light' property.

I tried to extent the TypeText interface, but it's not working. There's an error: Property 'light' does not exist on type 'TypeText'.ts(2339)

import { createTheme, TypeText } from '@mui/material/styles';

interface TypeTextExt extends Partial<TypeText> {
  light: string;
}

export const theme = createTheme({
  palette: {
    text: {
      primary: '#111',
      secondary: '#222',
      disabled: '#333',
      light: '#444',
    } as TypeTextExt,
} ...

Is it possible to add a custom property to theme > palette > text? I want to add 'light' property.

I tried to extent the TypeText interface, but it's not working. There's an error: Property 'light' does not exist on type 'TypeText'.ts(2339)

import { createTheme, TypeText } from '@mui/material/styles';

interface TypeTextExt extends Partial<TypeText> {
  light: string;
}

export const theme = createTheme({
  palette: {
    text: {
      primary: '#111',
      secondary: '#222',
      disabled: '#333',
      light: '#444',
    } as TypeTextExt,
} ...
Share Improve this question asked Feb 7 at 7:42 adhinnaadhinna 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Found that it works perfectly declaring a module:

declare module '@mui/material/styles' {
  interface TypeText {
    light?: string;
  }
   interface Palette {
     text: TypeText;
   }
   interface PaletteOptions {
     text?: Partial<TypeText>;
   }
}
发布评论

评论列表(0)

  1. 暂无评论