Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for Global Palette Key Extension Support for All Component Props #45479

Open
erufan opened this issue Mar 4, 2025 · 2 comments
Open
Labels
customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature typescript v7.x

Comments

@erufan
Copy link

erufan commented Mar 4, 2025

Summary

I'm currently using Material UI v6.4.6 with TypeScript, and I have encountered an issue when trying to add a custom color to my palette and use it across various components. While extending the palette interface to include custom keys is straightforward, I find it cumbersome to have to manually extend each component's props (e.g., ButtonPropsColorOverrides, IconButtonPropsColorOverrides, etc.) to accept the custom color for type safty.

Examples

Create a theme with a custom palette key (e.g., accent).

Attempt to use the custom palette key in a component, such as .

Note the TypeScript error indicating that the accent key is not allowed for the color prop.

import { createTheme } from "@mui/material";

declare module "@mui/material/styles" {
  interface Palette {
    accent: Palette["primary"];
  }

  interface PaletteOptions {
    accent?: PaletteOptions["primary"];
  }
}

let muiTheme = createTheme({
  palette: {
    primary: {
      main: "#E7FAFE",
    },
    secondary: {
      main: "#fff",
    },
  },
});

muiTheme = createTheme(muiTheme, {
  palette: {
    accent: muiTheme.palette.augmentColor({
      color: {
        main: "#000",
      },
      name: "accent",
    }),
  },
});

export default muiTheme;

as documantation says

Motivation

I understand that the current workaround involves augmenting the props interface for each individual component, as shown below for the Button component:

declare module '@mui/material/Button' {
  interface ButtonPropsColorOverrides {
    accent: true;
  }
}

However, this approach is repetitive and error-prone, especially in larger codebases where multiple components need to be extended.

I propose adding support for globally extending all component props to accept custom palette keys. This could be achieved through a single configuration or utility that ensures type safety without needing repetitive manual declarations for each component.

This enhancement would significantly reduce boilerplate code and improve the developer experience, making it easier to maintain and utilize custom palette keys across the entire component library.

Thank you for considering this request. I look forward to any feedback or suggestions from the maintainers and community.

Search keywords: Global-Palette,color-Palette,custome-color,type-safety,typescript-custome-color

@erufan erufan added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 4, 2025
@siriwatknp siriwatknp added typescript customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 5, 2025
@siriwatknp
Copy link
Member

siriwatknp commented Mar 5, 2025

Thanks for the feedback!
It's quite a common use case, so I mark as v7 to consider it.

@siriwatknp siriwatknp added the v7.x label Mar 5, 2025
@erufan
Copy link
Author

erufan commented Mar 5, 2025

I'm appreciated.
interested in potentially contributing. However, I'm not yet sure if I can successfully implement this feature.

If a community contribution for this feature is welcome, then I would like to request a 7-day period to investigate the codebase and assess the feasibility of my implementing it. After this assessment, and assuming contribution is welcome, I will follow up with more specific questions regarding architectural/design guidelines and workflow.

Sincerely,
Thank you for your time and consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature typescript v7.x
Projects
None yet
Development

No branches or pull requests

2 participants