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

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

Open
2 tasks done
soullivaneuh opened this issue May 6, 2022 · 2 comments
Open
2 tasks done
Assignees
Labels
customization: theme Centered around the theming features new feature New feature or request typescript

Comments

@soullivaneuh
Copy link

soullivaneuh commented May 6, 2022

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

@soullivaneuh soullivaneuh added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 6, 2022
@danilo-leal danilo-leal changed the title Add theme color strong typing onto the sx color properties [theme] Add theme color strong typing onto the sx color properties May 10, 2022
@danilo-leal danilo-leal added customization: theme Centered around the theming features new feature New feature or request labels May 10, 2022
@siriwatknp siriwatknp added typescript and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 25, 2022
@mitoihs
Copy link

mitoihs commented Sep 6, 2023

I've just encountered the need for that feature when using NextJs SSR feature. I can't use
backgroundColor: theme => theme.palette.primary.black because Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
It works fine with backgroundColor: "primary.black" but then I'm losing strong typing.

@CalebJamesStevens
Copy link

I've just encountered the need for that feature when using NextJs SSR feature. I can't use backgroundColor: theme => theme.palette.primary.black because Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". It works fine with backgroundColor: "primary.black" but then I'm losing strong typing.

i'm running into the same issue right now

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 new feature New feature or request typescript
Projects
None yet
Development

No branches or pull requests

5 participants