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
[TypeScript] Add CSS vars type augmentation for Material UI #33211
Merged
siriwatknp
merged 22 commits into
mui:master
from
siriwatknp:material-ui/css-vars-types
Jun 23, 2022
Merged
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ab4f78d
fix createPalette
siriwatknp 7d4a4a3
add theme augmentation
siriwatknp 39945ba
refactor to tsx
siriwatknp 09c0279
explicitly export types
siriwatknp db1ebbd
fix variable
siriwatknp 1951b84
ignore some palette variables
siriwatknp 636ab70
use inputUnderline variable
siriwatknp fb4aeab
refine types
siriwatknp ab6290e
add spec
siriwatknp a90f7d2
fix lint
siriwatknp 8432ce2
add more test
siriwatknp a1239ef
Merge branch 'master' of https://github.com/mui/material-ui into mate…
siriwatknp 30a7382
Merge branch 'master' of https://github.com/mui/material-ui into mate…
siriwatknp 4adf05c
add comments
siriwatknp 5b4a178
add comments
siriwatknp 7af5cc8
add typescript section to css-variables
siriwatknp 4a00ff7
add theme css variables spec
siriwatknp e6cd10d
remove duplicate content
siriwatknp ab3f288
add import
siriwatknp 5f3fa86
Merge branch 'master' of https://github.com/mui/material-ui into mate…
siriwatknp 5898750
add missing component palette types
siriwatknp 66258e4
remove non existing variable
siriwatknp File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as React from 'react'; | ||
import { | ||
experimental_extendTheme as extendTheme, | ||
Experimental_CssVarsProvider as CssVarsProvider, | ||
styled, | ||
useTheme, | ||
Overlays, | ||
} from '@mui/material/styles'; | ||
|
||
const customTheme = extendTheme({ | ||
colorSchemes: { | ||
light: { | ||
opacity: { | ||
inputPlaceholder: 0.1, | ||
inputUnderline: 0.1, | ||
}, | ||
overlays: Array(25).fill('') as Overlays, | ||
palette: { | ||
AppBar: { | ||
darkBg: '', | ||
darkColor: '', | ||
defaultBg: '', | ||
}, | ||
// @ts-expect-error | ||
mode: '', | ||
}, | ||
}, | ||
dark: { | ||
opacity: {}, | ||
palette: {}, | ||
}, | ||
}, | ||
components: { | ||
MuiButton: { | ||
styleOverrides: { | ||
root: ({ theme }) => ({ | ||
color: theme.vars.palette.primary.main, | ||
}), | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const TestStyled = styled('div')(({ theme }) => ({ | ||
color: theme.vars.palette.primary.main, | ||
[theme.getColorSchemeSelector('dark')]: { | ||
color: theme.vars.palette.common.onBackground, | ||
}, | ||
})); | ||
|
||
const TestUseTheme = () => { | ||
const theme = useTheme(); | ||
return <div style={{ background: theme.vars.palette.common.background }}>test</div>; | ||
}; | ||
|
||
<CssVarsProvider theme={customTheme}> | ||
<TestStyled | ||
sx={(theme) => ({ | ||
[theme.getColorSchemeSelector('dark')]: { | ||
border: '1px solid', | ||
borderColor: theme.vars.palette.divider, | ||
}, | ||
})} | ||
/> | ||
</CssVarsProvider>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 am a bit confused, how those the types work here?
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.
It tests that you can access
theme.vars
in styled. It would throw an error if it does not work. I will add a comment on this.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.
Done.
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 am a bit confused. In order for this to work developers need to import
How does it work here without importing it. This was my initial question.
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.
Got it. The module augmentation is a part of the repo so that's why it is included without the import. I can add it to make it explicit.
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.
Okay, let's do it :)