-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs][material] Improve documentation about adding custom colors (#3…
- Loading branch information
1 parent
35291e7
commit 49989b1
Showing
31 changed files
with
1,087 additions
and
147 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
41 changes: 41 additions & 0 deletions
41
docs/data/material/customization/palette/AddingColorTokens.js
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,41 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import { blue } from '@mui/material/colors'; | ||
import { Box, Stack } from '@mui/system'; | ||
import { Typography } from '@mui/material'; | ||
|
||
const theme = createTheme({ | ||
palette: { | ||
primary: { | ||
light: blue[300], | ||
main: blue[500], | ||
dark: blue[700], | ||
darker: blue[900], | ||
}, | ||
}, | ||
}); | ||
|
||
export default function AddingColorTokens() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Stack direction="row" gap={1}> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">light</Typography> | ||
<Box sx={{ bgcolor: `primary.light`, width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">main</Typography> | ||
<Box sx={{ bgcolor: `primary.main`, width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">dark</Typography> | ||
<Box sx={{ bgcolor: `primary.dark`, width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">darker</Typography> | ||
<Box sx={{ bgcolor: `primary.darker`, width: 40, height: 20 }} /> | ||
</Stack> | ||
</Stack> | ||
</ThemeProvider> | ||
); | ||
} |
51 changes: 51 additions & 0 deletions
51
docs/data/material/customization/palette/AddingColorTokens.tsx
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,51 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import { blue } from '@mui/material/colors'; | ||
import { Box, Stack } from '@mui/system'; | ||
import { Typography } from '@mui/material'; | ||
|
||
declare module '@mui/material/styles' { | ||
interface PaletteColor { | ||
darker?: string; | ||
} | ||
|
||
interface SimplePaletteColorOptions { | ||
darker?: string; | ||
} | ||
} | ||
|
||
const theme = createTheme({ | ||
palette: { | ||
primary: { | ||
light: blue[300], | ||
main: blue[500], | ||
dark: blue[700], | ||
darker: blue[900], | ||
}, | ||
}, | ||
}); | ||
|
||
export default function AddingColorTokens() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Stack direction="row" gap={1}> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">light</Typography> | ||
<Box sx={{ bgcolor: `primary.light`, width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">main</Typography> | ||
<Box sx={{ bgcolor: `primary.main`, width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">dark</Typography> | ||
<Box sx={{ bgcolor: `primary.dark`, width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">darker</Typography> | ||
<Box sx={{ bgcolor: `primary.darker`, width: 40, height: 20 }} /> | ||
</Stack> | ||
</Stack> | ||
</ThemeProvider> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
docs/data/material/customization/palette/AddingColorTokens.tsx.preview
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,13 @@ | ||
import { createTheme } from '@mui/material/styles'; | ||
import { blue } from '@mui/material/colors'; | ||
|
||
const theme = createTheme({ | ||
palette: { | ||
primary: { | ||
light: blue[300], | ||
main: blue[500], | ||
dark: blue[700], | ||
darker: blue[900], | ||
}, | ||
}, | ||
}); |
43 changes: 43 additions & 0 deletions
43
docs/data/material/customization/palette/ContrastThreshold.js
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,43 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles'; | ||
import Button from '@mui/material/Button'; | ||
import { Stack } from '@mui/system'; | ||
|
||
const defaultContrastThresholdTheme = createTheme({}); | ||
|
||
const highContrastThresholdTheme = createTheme({ | ||
palette: { | ||
contrastThreshold: 4.5, | ||
}, | ||
}); | ||
|
||
function ContrastShowcase({ title }) { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Stack gap={1} alignItems="center"> | ||
<span> | ||
<b>{title}</b> | ||
</span> | ||
<span>{theme.palette.contrastThreshold}:1</span> | ||
<Stack direction="row" gap={1}> | ||
<Button variant="contained" color="warning"> | ||
Warning | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
); | ||
} | ||
|
||
export default function contrastThreshold() { | ||
return ( | ||
<Stack direction="row" gap={4}> | ||
<ThemeProvider theme={defaultContrastThresholdTheme}> | ||
<ContrastShowcase title="Default contrast threshold" /> | ||
</ThemeProvider> | ||
<ThemeProvider theme={highContrastThresholdTheme}> | ||
<ContrastShowcase title="Higher contrast threshold" /> | ||
</ThemeProvider> | ||
</Stack> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
docs/data/material/customization/palette/ContrastThreshold.tsx
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,43 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles'; | ||
import Button from '@mui/material/Button'; | ||
import { Stack } from '@mui/system'; | ||
|
||
const defaultContrastThresholdTheme = createTheme({}); | ||
|
||
const highContrastThresholdTheme = createTheme({ | ||
palette: { | ||
contrastThreshold: 4.5, | ||
}, | ||
}); | ||
|
||
function ContrastShowcase({ title }: { title: string }) { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Stack gap={1} alignItems="center"> | ||
<span> | ||
<b>{title}</b> | ||
</span> | ||
<span>{theme.palette.contrastThreshold}:1</span> | ||
<Stack direction="row" gap={1}> | ||
<Button variant="contained" color="warning"> | ||
Warning | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
); | ||
} | ||
|
||
export default function contrastThreshold() { | ||
return ( | ||
<Stack direction="row" gap={4}> | ||
<ThemeProvider theme={defaultContrastThresholdTheme}> | ||
<ContrastShowcase title="Default contrast threshold" /> | ||
</ThemeProvider> | ||
<ThemeProvider theme={highContrastThresholdTheme}> | ||
<ContrastShowcase title="Higher contrast threshold" /> | ||
</ThemeProvider> | ||
</Stack> | ||
); | ||
} |
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
42 changes: 42 additions & 0 deletions
42
docs/data/material/customization/palette/ManuallyProvideCustomColor.js
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,42 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import Button from '@mui/material/Button'; | ||
import { Box, Stack } from '@mui/system'; | ||
import { Typography } from '@mui/material'; | ||
|
||
const theme = createTheme({ | ||
palette: { | ||
ochre: { | ||
main: '#E3D026', | ||
light: '#E9DB5D', | ||
dark: '#A29415', | ||
contrastText: '#242105', | ||
}, | ||
}, | ||
}); | ||
|
||
export default function Palette() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Stack gap={2} alignItems="center"> | ||
<Button variant="contained" color="ochre"> | ||
Ochre | ||
</Button> | ||
<Stack direction="row" gap={1}> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">light</Typography> | ||
<Box sx={{ bgcolor: 'ochre.light', width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">main</Typography> | ||
<Box sx={{ bgcolor: 'ochre.main', width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">dark</Typography> | ||
<Box sx={{ bgcolor: 'ochre.dark', width: 40, height: 20 }} /> | ||
</Stack> | ||
</Stack> | ||
</Stack> | ||
</ThemeProvider> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
docs/data/material/customization/palette/ManuallyProvideCustomColor.tsx
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,60 @@ | ||
import * as React from 'react'; | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import Button from '@mui/material/Button'; | ||
import { Box, Stack } from '@mui/system'; | ||
import { Typography } from '@mui/material'; | ||
|
||
// Augment the palette to include an ochre color | ||
declare module '@mui/material/styles' { | ||
interface Palette { | ||
ochre: Palette['primary']; | ||
} | ||
|
||
interface PaletteOptions { | ||
ochre?: PaletteOptions['primary']; | ||
} | ||
} | ||
|
||
// Update the Button's color options to include an ochre option | ||
declare module '@mui/material/Button' { | ||
interface ButtonPropsColorOverrides { | ||
ochre: true; | ||
} | ||
} | ||
|
||
const theme = createTheme({ | ||
palette: { | ||
ochre: { | ||
main: '#E3D026', | ||
light: '#E9DB5D', | ||
dark: '#A29415', | ||
contrastText: '#242105', | ||
}, | ||
}, | ||
}); | ||
|
||
export default function Palette() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Stack gap={2} alignItems="center"> | ||
<Button variant="contained" color="ochre"> | ||
Ochre | ||
</Button> | ||
<Stack direction="row" gap={1}> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">light</Typography> | ||
<Box sx={{ bgcolor: 'ochre.light', width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">main</Typography> | ||
<Box sx={{ bgcolor: 'ochre.main', width: 40, height: 20 }} /> | ||
</Stack> | ||
<Stack alignItems="center"> | ||
<Typography variant="body2">dark</Typography> | ||
<Box sx={{ bgcolor: 'ochre.dark', width: 40, height: 20 }} /> | ||
</Stack> | ||
</Stack> | ||
</Stack> | ||
</ThemeProvider> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
docs/data/material/customization/palette/ManuallyProvideCustomColor.tsx.preview
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,12 @@ | ||
import { createTheme } from '@mui/material/styles'; | ||
|
||
const theme = createTheme({ | ||
palette: { | ||
ochre: { | ||
main: '#E3D026', | ||
light: '#E9DB5D', | ||
dark: '#A29415', | ||
contrastText: '#242105', | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.