-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeScript] Add CSS vars type augmentation for Material UI (#33211)
- Loading branch information
1 parent
76e2ef6
commit 9cfcd8c
Showing
16 changed files
with
471 additions
and
187 deletions.
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 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,72 @@ | ||
import * as React from 'react'; | ||
import { | ||
experimental_extendTheme as extendTheme, | ||
Experimental_CssVarsProvider as CssVarsProvider, | ||
styled, | ||
useTheme, | ||
Overlays, | ||
} from '@mui/material/styles'; | ||
import type {} from '@mui/material/themeCssVarsAugmentation'; | ||
|
||
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: '', | ||
getContrastText: () => '', | ||
tonalOffset: 1, | ||
}, | ||
}, | ||
dark: { | ||
opacity: {}, | ||
palette: {}, | ||
}, | ||
}, | ||
components: { | ||
MuiButton: { | ||
styleOverrides: { | ||
root: ({ theme }) => ({ | ||
color: theme.vars.palette.primary.main, | ||
}), | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const TestStyled = styled('div')(({ theme }) => ({ | ||
// test that `theme.vars` works | ||
color: theme.vars.palette.primary.main, | ||
// test that `theme.getColorSchemeSelector` works | ||
[theme.getColorSchemeSelector('dark')]: { | ||
color: theme.vars.palette.common.onBackground, | ||
}, | ||
})); | ||
|
||
const TestUseTheme = () => { | ||
const theme = useTheme(); | ||
// test that `theme` from useTheme has access to CSS vars | ||
return <div style={{ background: theme.vars.palette.common.background }}>test</div>; | ||
}; | ||
|
||
<CssVarsProvider theme={customTheme}> | ||
<TestStyled | ||
sx={(theme) => ({ | ||
// test that `theme` in sx has access to CSS vars | ||
[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.