mui / mui/material-ui

[theme] Add theme color strong typing onto the sx color properties

Open
#32,656 2 comments 11 reactions 1 assignee View on GitHub

@siriwatknp is already working on this.

Since May 23, 2022.

customization: theme scope: all components type: new feature typescript
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Summary 💡

Add strong type checking onto the palette theme aware sx properties.

Examples 🌈

No response

Motivation 🔦

Since MUI v5, the suggested way to configure the color related sx props is to use string reference of the theme palette, making the implementation simpler: https://mui.com/system/the-sx-prop/#palette

However, with the moving from theme.palette to string reference, we loose the typescript strong checking of the available color.

The sx color prop for example, will only suggest css related values, not something like primary.main.

Because of that, I'm still preferring the theme.palette usage.

It would be a great addition to have type checking on the palette theme aware properties.

This was also something asked on StackOverflow: https://stackoverflow.com/q/69888051/1731473

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.