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

[Joy] Able to remove default tokens from theme types #36006

Merged
merged 14 commits into from
Feb 27, 2023

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jan 31, 2023

Context

While working on #35741, I noticed some types augmentation are wrong and missing.

Before

A lot of theme augmentation does not work correctly:

After

sandbox: https://codesandbox.io/s/joy-cra-typescript-forked-g7u3b5?file=/src/App.tsx

  • Able to remove default tokens and provide undefined to extendTheme() (before this, you have to use // @ts-ignore)
    declare module "@mui/joy/styles" {
      interface PalettePrimaryOverrides {
        50: false
      }
    }
    
    extendTheme({
      colorSchemes: { palette: { primary: {
        50: undefined,}}}
    })
  • theme.vars are sync with the module augmentation

@mui-bot
Copy link

mui-bot commented Jan 31, 2023

Netlify deploy preview

https://deploy-preview-36006--material-ui.netlify.app/

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against f7acf94

@siriwatknp siriwatknp marked this pull request as ready for review February 9, 2023 05:51
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 13, 2023
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 16, 2023
Comment on lines +22 to +23
100: false;
120: true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still not clear to me if this can really work, for example:

plainHoverBg: getCssVarColor(`palette-${color}-100`),

This variable will no longer point to a valid value. Should we expect developers to map all variables to point to this value to something new?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will also need to specify undefined as a value to the token (100: undefined).

That's the expected behavior. The goal is to let developers be able to customize the color range to match their design system needs (the tokens should not be limited to 50-900 range)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those lines only add/remove the theme typings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming a bit late to the party, but this was my comment: https://codesandbox.io/s/joy-cra-typescript-forked-2dfxd5?file=/src/App.tsx I know you can make it technically correct, but components will break. We need to make sure we give detailed instructions of what needs to be done after some specific palette value is removed, for e.g. some tokens will need to be redefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but components will break

In my point of view, this break is expected because you are changing the token structure. I agree with you that docs should address this clearly and I plan to add a page to the advanced section of Joy UI customization.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 20, 2023
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 21, 2023
@siriwatknp
Copy link
Member Author

@mnajdova @hbjORbj a little bump to your notifications 😅

Copy link
Member

@hbjORbj hbjORbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes much more solid typings. Looks good.

@siriwatknp siriwatknp merged commit 824984f into mui:master Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: joy-ui Specific to @mui/joy typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants