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

[website] Migrate /core page to use CSS variables #35366

Merged
merged 56 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b95669f
fix theme toggle on system mode
siriwatknp Nov 19, 2022
ccc6353
add useCssThemeVars
siriwatknp Nov 21, 2022
f7a160e
refactor styles
siriwatknp Nov 21, 2022
ab06cf1
fix mode and colorScheme
siriwatknp Nov 21, 2022
b1ab089
update AppSearch
siriwatknp Nov 21, 2022
a6fb6c9
fix proptypes to receive array
siriwatknp Nov 22, 2022
aadc4ac
add ttp ignore
siriwatknp Nov 22, 2022
b16d85b
extract useCssThemeVars
siriwatknp Nov 22, 2022
231a5e3
Merge branch 'master' of https://github.com/mui/material-ui into syst…
siriwatknp Nov 23, 2022
3f81fb3
reexport useCssThemeVars from Material UI and Joy UI
siriwatknp Nov 23, 2022
67c9c62
simplify selector
siriwatknp Nov 23, 2022
c688c64
Revert "fix proptypes to receive array"
siriwatknp Nov 23, 2022
c965aa3
set default theme
siriwatknp Nov 23, 2022
a4b24f1
add NestedCssVarsProvider
siriwatknp Nov 23, 2022
f43d41d
add textfield
siriwatknp Nov 23, 2022
4fcb60b
refactor
siriwatknp Nov 24, 2022
4144805
create demos
siriwatknp Nov 24, 2022
16c8175
create new object
siriwatknp Nov 24, 2022
8f8c2d3
fix bug
siriwatknp Nov 24, 2022
6f71f9c
Merge branch 'master' of https://github.com/mui/material-ui into syst…
siriwatknp Nov 25, 2022
676d109
make code review easier
siriwatknp Nov 25, 2022
24fef70
run error-codes
siriwatknp Nov 25, 2022
155b2ee
flatten param
siriwatknp Nov 25, 2022
e85f37a
run prettier
siriwatknp Nov 25, 2022
aa7e3f8
fix logic
siriwatknp Nov 25, 2022
874fbbd
Merge branch 'master' of https://github.com/mui/material-ui into docs…
siriwatknp Nov 25, 2022
7ccfd39
Merge branch 'system/use-css-theme-vars' into docs/core-css
siriwatknp Nov 25, 2022
048204a
revert changes
siriwatknp Nov 25, 2022
89840c1
support function in NestedCssVarsProvider
siriwatknp Nov 25, 2022
39b7086
update core page
siriwatknp Nov 25, 2022
1b0a6be
update data-grid to latest
siriwatknp Nov 25, 2022
598d091
update DatePicker to latest
siriwatknp Nov 25, 2022
58f9a58
fix x page and components
siriwatknp Nov 25, 2022
f978d94
add flags
siriwatknp Nov 28, 2022
a23a75a
fix demos
siriwatknp Nov 28, 2022
5eefa72
Merge branch 'master' of https://github.com/mui/material-ui into syst…
siriwatknp Dec 2, 2022
3a0e36d
fix logic
siriwatknp Dec 2, 2022
4041321
add regressions
siriwatknp Dec 2, 2022
08979bd
remove experiment
siriwatknp Dec 2, 2022
bb8b29b
Merge branch 'master' of https://github.com/mui/material-ui into docs…
siriwatknp Dec 2, 2022
e367f55
restore
siriwatknp Dec 2, 2022
ec4a560
Merge branch 'system/disable-style-sheet' into docs/core-css
siriwatknp Dec 2, 2022
2e37967
revert
siriwatknp Dec 2, 2022
c4417f5
update core page
siriwatknp Dec 2, 2022
7ef0152
update x page
siriwatknp Dec 2, 2022
5448300
update component
siriwatknp Dec 3, 2022
b83768c
replace with gap
siriwatknp Dec 3, 2022
6f3f468
Merge branch 'master' of https://github.com/mui/material-ui into docs…
siriwatknp Dec 6, 2022
d892ea2
prevent chrome autofill
siriwatknp Dec 6, 2022
d374060
improve demo
siriwatknp Dec 6, 2022
618fced
remove experiments
siriwatknp Dec 6, 2022
8aba53c
update DatePickers and DataGrid to v6
siriwatknp Dec 6, 2022
efb42ed
update ThemeDatePicker
siriwatknp Dec 6, 2022
e386915
revert x page
siriwatknp Dec 6, 2022
12d3b7b
fix lint
siriwatknp Dec 6, 2022
6914ee2
Update docs/src/components/productCore/CoreComponents.tsx
siriwatknp Dec 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update component
  • Loading branch information
siriwatknp committed Dec 3, 2022
commit 5448300ee68dacf51143215471dc5db2025deb52
51 changes: 31 additions & 20 deletions docs/src/components/home/MaterialDesignComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as React from 'react';
import {
styled,
ThemeProvider,
Theme,
ThemeOptions,
alpha,
useCssThemeVars,
experimental_extendTheme as extendTheme,
Experimental_CssVarsProvider as CssVarsProvider,
} from '@mui/material/styles';
import GlobalStyles from '@mui/material/GlobalStyles';
import { capitalize } from '@mui/material/utils';
import Alert from '@mui/material/Alert';
import Box from '@mui/material/Box';
Expand Down Expand Up @@ -36,7 +34,7 @@ import VerifiedUserRounded from '@mui/icons-material/VerifiedUserRounded';
import HelpCenterRounded from '@mui/icons-material/HelpCenterRounded';
import ROUTES from 'docs/src/route';
import Link from 'docs/src/modules/components/Link';
import { getThemedComponents } from 'docs/src/modules/brandingTheme';
import { getDesignTokens, getThemedComponents } from 'docs/src/modules/brandingTheme';

const Grid = styled('div')(({ theme }) => [
{
Expand Down Expand Up @@ -126,7 +124,7 @@ function Demo({
...props
}: {
name: string;
theme: Theme;
theme: Theme | undefined;
children: React.ReactElement;
control?: { prop: string; values: Array<string>; defaultValue?: string };
}) {
Expand Down Expand Up @@ -174,13 +172,21 @@ function Demo({
className="mui-default-theme"
sx={{ flexGrow: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}
>
<ThemeProvider theme={props.theme}>
{React.cloneElement(children, {
{props.theme ? (
<CssVarsProvider disableStyleSheetGeneration theme={props.theme}>
{React.cloneElement(children, {
...(control && {
[control.prop]: propValue,
}),
})}
</CssVarsProvider>
) : (
React.cloneElement(children, {
...(control && {
[control.prop]: propValue,
}),
})}
</ThemeProvider>
})
)}
</Box>
<Typography fontWeight="semiBold" variant="body2">
{name}
Expand Down Expand Up @@ -478,23 +484,28 @@ export function buildTheme(): ThemeOptions {
};
}

const defaultTheme = extendTheme();
const { palette: lightPalette, typography, ...designTokens } = getDesignTokens('light');
const { palette: darkPalette } = getDesignTokens('dark');
export const customTheme = extendTheme({
cssVarPrefix: 'muidocs',
colorSchemes: {
light: {
palette: lightPalette,
},
dark: {
palette: darkPalette,
},
},
...designTokens,
...buildTheme(),
});

export default function MaterialDesignComponents() {
const [anchor, setAnchor] = React.useState<HTMLElement | null>(null);
const [customized, setCustomized] = React.useState(false);
const { theme: scopedTheme, styles } = useCssThemeVars(defaultTheme, {
selector: {
root: '.mui-default-theme',
defaultColorScheme: (key) =>
`.mui-default-theme, [data-mui-color-scheme="${key}"] .mui-default-theme`,
scopedColorScheme: (key) => `[data-mui-color-scheme="${key}"] .mui-default-theme`,
},
});
const theme = customized ? (buildTheme() as Theme) : scopedTheme;
const theme = customized ? customTheme : undefined;
return (
<div>
<GlobalStyles styles={styles} />
<Box
sx={{
mt: { xs: 2, md: 4 },
Expand Down
10 changes: 2 additions & 8 deletions docs/src/components/productCore/CoreComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import * as React from 'react';
import {
Experimental_CssVarsProvider as CssVarsProvider,
experimental_extendTheme as extendTheme,
styled,
} from '@mui/material/styles';
import { Experimental_CssVarsProvider as CssVarsProvider, styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Alert from '@mui/material/Alert';
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -32,7 +28,7 @@ import Item, { Group } from 'docs/src/components/action/Item';
import Highlighter from 'docs/src/components/action/Highlighter';
import More from 'docs/src/components/action/More';
import Frame from 'docs/src/components/action/Frame';
import { buildTheme } from 'docs/src/components/home/MaterialDesignComponents';
import { customTheme } from 'docs/src/components/home/MaterialDesignComponents';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
import MarkdownElement from 'docs/src/components/markdown/MarkdownElement';
import StylingInfo from 'docs/src/components/action/StylingInfo';
Expand Down Expand Up @@ -135,8 +131,6 @@ const CODES = {
`,
};

const customTheme = extendTheme(buildTheme());

export default function CoreComponents() {
const [demo, setDemo] = React.useState<typeof DEMOS[number]>(DEMOS[0]);
const [customized, setCustomized] = React.useState(false);
Expand Down