-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[pickers] Support theme.vars
#6778
Conversation
These are the results for the performance tests:
|
@siriwatknp I'm not sure about how to extend the theme types. For now, I put the import type {} from '@mui/material/themeCssVarsAugmentation'; Into the root |
backgroundColor: alpha(theme.palette.primary.light, 0.6), | ||
color: (theme.vars || theme).palette.primary.contrastText, | ||
backgroundColor: theme.vars | ||
? `rgba(${theme.vars.palette.primary.lightChannel} / ${0.6})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? `rgba(${theme.vars.palette.primary.lightChannel} / ${0.6})` | |
? `rgba(${theme.vars.palette.primary.lightChannel} / 0.6)` |
The curry bracket is not needed (x the others).
@@ -1,3 +1,5 @@ | |||
import type {} from '@mui/material/themeCssVarsAugmentation'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import type {} from '@mui/material/themeCssVarsAugmentation'; |
This should not be enabled by the library, it should be done by the consumer instead.
Can you try importing it into the MUI X global project instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by
importing it into the MUI X global project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it, TypeScript complains about theme.vars
as it's not available on the standard Theme
interface.
Can we solve it somehow without importing themeCssVarsAugmentation
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we fix it on our side, make sure to test a bundled version of our package with skipLIbCheck: false
because I suspect it will fail without this import.
Doesn't it make sense for @mui/x-date-pickers
to import the module augmentation that it uses internally ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it make sense for @mui/x-date-pickers to import the module augmentation that it uses internally
I am open to any option but the developers have to opt-in to get the type. Meaning when they install @mui/x-date-pickers
and @mui/material
, they should not see theme.vars
.
If they want to have theme.vars
, they have to opt-in (either import from @mui/material
or @mui/x-date-pickers
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggle to understand how we could use theme.vars
in our files, and hide the theme.vars
type from users
color: theme.palette.getContrastText( | ||
theme.vars | ||
? `rgba(${theme.vars.palette.primary.lightChannel} / ${0.6})` | ||
: alpha(theme.palette.primary.light, 0.6), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
color: theme.palette.getContrastText( | |
theme.vars | |
? `rgba(${theme.vars.palette.primary.lightChannel} / ${0.6})` | |
: alpha(theme.palette.primary.light, 0.6), | |
), | |
color: theme.vars ? theme.vars.palette.text.primary : theme.palette.getContrastText(alpha(theme.palette.primary.light, 0.6)), |
I think this is the closest result because alpha(theme.palette.primary.light, 0.6)
mostly gives very light color.
|
||
export type ExtendedTheme = Theme | CssVarsTheme; | ||
|
||
export const getThemePalette = (theme: ExtendedTheme): Theme['palette'] | ThemeVars['palette'] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like this solution a lot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@siriwatknp If you're good with this solution I will do the same in the data-grid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I don't want to go that way because the issue is just about typings. I found a way to make TypeScript happy by adding the themeCssVarsAugmentation
to tsconfig.json
.
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"types": ["react", "mocha", "node"],
"noImplicitAny": true
},
"include": [
"src/**/*",
"../../../node_modules/@mui/monorepo/test/utils/initMatchers.ts",
+ "../../../node_modules/@mui/material/themeCssVarsAugmentation"
]
}
Note: you will need to add it to all tsconfig.json
and tsconfig.build.json
in all packages/*
.
@alexfauquette @flaviendelangle What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed, you need to add it to tsconfig.build.json
too, otherwise, yarn build
fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearly less hacky, and I confirm yarn release:build
succeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like apps using @mui/x-date-pickers
with this approach also works and don't have access to theme.vars
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
c75d68d
to
42e515f
Compare
packages/x-date-pickers-pro/src/DateRangePickerDay/DateRangePickerDay.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one last comment, the rest looks good.
…ckerDay.tsx Co-authored-by: Siriwat K <siriwatkunaporn@gmail.com> Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩 Can't wait for this!
Fix #6711