Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Add a new color to Materail UI button with a custom theme

I have been using Materail UI v5 in my next js project with typescript.

theme.ts

import { createTheme, Theme } from "@mui/material/styles";
import { blue, orange, pink, purple, red, yellow } from "@mui/material/colors";

export const theme = createTheme({
  palette: {
    primary: {
      main: red[300],
    },
    success: {
      main: blue[200],
    },
    secondary: {
      main: yellow[200],
    },
  },
});

i made a component for button which is

import React from "react";
import { Button as BaseButton } from "@mui/material";
import {ButtonProps} from "@mui/material/Button"

export type IButton = ButtonProps | "qwer";

export const Button:  React.FC<IButton> = ({ ...rest }) => {
  return <BaseButton {...rest} />;
};

and then use it like

<Button
            type="submit"
            fullWidth
            variant="contained"
            color="secondary"   //primary or success
            className={classes.submit}
          >

but now lets say if i want to add a new color name to my theme how do i add this ?

tried with

export const theme = createTheme({
  palette: {
   primary: {
   main: red[300],
   },
   xyz:{
     qwe:red[500]
  },
});

and then

<Button
            type="submit"
            fullWidth
            variant="contained"
            color={theme.palette.xyz.qwe}
            className={classes.submit}
          >

it throws error

Type '{ primary: { main: "#e57373"; }; xyz: { qwe: "#e57373"; }; }' is not assignable to type 'PaletteOptions'.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda