index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/how-to-customize/StyledCustomization.js
import * as React from 'react'; import Slider from '@mui/material/Slider'; import { alpha, styled } from '@mui/material/styles'; const SuccessSlider = styled(Slider)(({ theme }) => ({ width: 300, color: theme.palette.success.main, '& .MuiSlider-thumb': { '&:hover, &.Mui-focusVisible': { boxShadow: `0px 0px 0px 8px ${alpha(theme.palette.success.main, 0.16)}`, }, '&.Mui-active': { boxShadow: `0px 0px 0px 14px ${alpha(theme.palette.success.main, 0.16)}`, }, }, })); export default function StyledCustomization() { return <SuccessSlider defaultValue={30} />; }
3,400
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/how-to-customize/StyledCustomization.tsx
import * as React from 'react'; import Slider, { SliderProps } from '@mui/material/Slider'; import { alpha, styled } from '@mui/material/styles'; const SuccessSlider = styled(Slider)<SliderProps>(({ theme }) => ({ width: 300, color: theme.palette.success.main, '& .MuiSlider-thumb': { '&:hover, &.Mui-focusVisible': { boxShadow: `0px 0px 0px 8px ${alpha(theme.palette.success.main, 0.16)}`, }, '&.Mui-active': { boxShadow: `0px 0px 0px 14px ${alpha(theme.palette.success.main, 0.16)}`, }, }, })); export default function StyledCustomization() { return <SuccessSlider defaultValue={30} />; }
3,401
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/how-to-customize/StyledCustomization.tsx.preview
<SuccessSlider defaultValue={30} />
3,402
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/how-to-customize/SxProp.js
import * as React from 'react'; import Slider from '@mui/material/Slider'; export default function SxProp() { return ( <Slider defaultValue={30} sx={{ width: 300, color: 'success.main', }} /> ); }
3,403
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/how-to-customize/SxProp.tsx
import * as React from 'react'; import Slider from '@mui/material/Slider'; export default function SxProp() { return ( <Slider defaultValue={30} sx={{ width: 300, color: 'success.main', }} /> ); }
3,404
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/how-to-customize/SxProp.tsx.preview
<Slider defaultValue={30} sx={{ width: 300, color: 'success.main', }} />
3,405
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/how-to-customize/how-to-customize.md
--- productId: material-ui components: GlobalStyles --- # How to customize <p class="description">Learn how to customize Material UI components by taking advantage of different strategies for specific use cases.</p> Material UI provides several different ways to customize a component's styles. Your specific context will determine which one is ideal. From narrowest to broadest use case, here are the options: 1. [One-off customization](#1-one-off-customization) 1. [Reusable component](#2-reusable-component) 1. [Global theme overrides](#3-global-theme-overrides) 1. [Global CSS override](#4-global-css-override) ## 1. One-off customization To change the styles of _one single instance_ of a component, you can use one of the following options: ### The `sx` prop The [`sx` prop](/system/getting-started/the-sx-prop/) is the best option for adding style overrides to a single instance of a component in most cases. It can be used with all Material UI components. {{"demo": "SxProp.js"}} ### Overriding nested component styles To customize a specific part of a component, you can use the class name provided by Material UI inside the `sx` prop. As an example, let's say you want to change the `Slider` component's thumb from a circle to a square. First, use your browser's dev tools to identify the class for the component slot you want to override. The styles injected into the DOM by Material UI rely on class names that all [follow a standard pattern](/system/styles/advanced/#class-names): `[hash]-Mui[Component name]-[name of the slot]`. In this case, the styles are applied with `.css-ae2u5c-MuiSlider-thumb` but you only really need to target the `.MuiSlider-thumb`, where `Slider` is the component and `thumb` is the slot. Use this class name to write a CSS selector within the `sx` prop (`& .MuiSlider-thumb`), and add your overrides. <img src="/static/images/customization/dev-tools.png" alt="dev-tools" style="margin-bottom: 16px;" width="2400" height="800" /> {{"demo": "DevTools.js"}} :::warning These class names can't be used as CSS selectors because they are unstable. ::: ### Overriding styles with class names If you want to override a component's styles using custom classes, you can use the `className` prop, available on each component. To override the styles of a specific part of the component, use the global classes provided by Material UI, as described in the previous section **"Overriding nested component styles"** under the [`sx` prop section](#the-sx-prop). Visit the [Style library interoperability](/material-ui/guides/interoperability/) guide to find examples of this approach using different styling libraries. ### State classes States like _hover_, _focus_, _disabled_ and _selected_, are styled with a higher CSS specificity. To customize them, you'll need to **increase specificity**. Here is an example with the _disabled_ state and the `Button` component using a pseudo-class (`:disabled`): ```css .Button { color: black; } /* Increase the specificity */ .Button:disabled { color: white; } ``` ```jsx <Button disabled className="Button"> ``` You can't always use a CSS pseudo-class, as the state doesn't exist in the web specification. Let's take the `MenuItem` component and its _selected_ state as an example. In this situation, you can use Material UI's **state classes**, which act just like CSS pseudo-classes. Target the `.Mui-selected` global class name to customize the special state of the `MenuItem` component: ```css .MenuItem { color: black; } /* Increase the specificity */ .MenuItem.Mui-selected { color: blue; } ``` ```jsx <MenuItem selected className="MenuItem"> ``` If you'd like to learn more about this topic, we recommend checking out [the MDN Web Docs on CSS Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity). #### Why do I need to increase specificity to override one component state? CSS pseudo-classes have a high level of specificity. For consistency with native elements, Material UI's state classes have the same level of specificity as CSS pseudo-classes, making it possible to target an individual component's state. #### What custom state classes are available in Material UI? You can rely on the following [global class names](/system/styles/advanced/#class-names) generated by Material UI: | State | Global class name | | :------------ | :------------------ | | active | `.Mui-active` | | checked | `.Mui-checked` | | completed | `.Mui-completed` | | disabled | `.Mui-disabled` | | error | `.Mui-error` | | expanded | `.Mui-expanded` | | focus visible | `.Mui-focusVisible` | | focused | `.Mui-focused` | | readOnly | `.Mui-readOnly` | | required | `.Mui-required` | | selected | `.Mui-selected` | :::error Never apply styles directly to state class names. This will impact all components with unclear side-effects. Always target a state class together with a component. ::: ```css /* ❌ NOT OK */ .Mui-error { color: red; } /* ✅ OK */ .MuiOutlinedInput-root.Mui-error { color: red; } ``` ## 2. Reusable component To reuse the same overrides in different locations across your application, create a reusable component using the [`styled()`](/system/styled/) utility: {{"demo": "StyledCustomization.js", "defaultCodeOpen": true}} ### Dynamic overrides The `styled()` utility lets you add dynamic styles based on a component's props. You can do this with **dynamic CSS** or **CSS variables**. #### Dynamic CSS :::warning If you are using TypeScript, you will need to update the prop's types of the new component. ::: {{"demo": "DynamicCSS.js", "defaultCodeOpen": false}} ```tsx import * as React from 'react'; import { styled } from '@mui/material/styles'; import Slider, { SliderProps } from '@mui/material/Slider'; interface StyledSliderProps extends SliderProps { success?: boolean; } const StyledSlider = styled(Slider, { shouldForwardProp: (prop) => prop !== 'success', })<StyledSliderProps>(({ success, theme }) => ({ ...(success && { // the overrides added when the new prop is used }), })); ``` #### CSS variables {{"demo": "DynamicCSSVariables.js"}} ## 3. Global theme overrides Material UI provides theme tools for managing style consistency between all components across your user interface. Visit the [Component theming customization](/material-ui/customization/theme-components/) page for more details. ## 4. Global CSS override To add global baseline styles for some of the HTML elements, use the `GlobalStyles` component. Here is an example of how you can override styles for the `h1` elements: {{"demo": "GlobalCssOverride.js", "iframe": true, "height": 100}} If you are already using the [CssBaseline](/material-ui/react-css-baseline/) component for setting baseline styles, you can also add these global styles as overrides for this component. Here is how you can achieve the same by using this approach. {{"demo": "OverrideCssBaseline.js", "iframe": true, "height": 100}} The `styleOverrides` key in the `MuiCssBaseline` component slot also supports callback from which you can access the theme. Here is how you can achieve the same by using this approach. {{"demo": "OverrideCallbackCssBaseline.js", "iframe": true, "height": 100}} :::success It is a good practice to hoist the `<GlobalStyles />` to a static constant, to avoid rerendering. This will ensure that the `<style>` tag generated would not recalculate on each render. ::: ```diff import * as React from 'react'; import GlobalStyles from '@mui/material/GlobalStyles'; +const inputGlobalStyles = <GlobalStyles styles={...} />; function Input(props) { return ( <React.Fragment> - <GlobalStyles styles={...} /> + {inputGlobalStyles} <input {...props} /> </React.Fragment> ) } ```
3,406
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/AddingColorTokens.js
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> ); }
3,407
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/AddingColorTokens.tsx
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> ); }
3,408
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ContrastThreshold.js
import * as React from 'react'; import PropTypes from 'prop-types'; 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(props) { const { title } = props; 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> ); } ContrastShowcase.propTypes = { title: PropTypes.string.isRequired, }; 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> ); }
3,409
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ContrastThreshold.tsx
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(props: { title: string }) { const { title } = props; 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> ); }
3,410
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ContrastThreshold.tsx.preview
<ThemeProvider theme={defaultContrastThresholdTheme}> <ContrastShowcase title="Default contrast threshold" /> </ThemeProvider> <ThemeProvider theme={highContrastThresholdTheme}> <ContrastShowcase title="Higher contrast threshold" /> </ThemeProvider>
3,411
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/CustomColor.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ palette: { neutral: { light: '#838fa2', main: '#64748b', dark: '#465161', contrastText: '#fff', }, }, }); export default function CustomColor() { return ( <ThemeProvider theme={theme}> <Button color="neutral" variant="contained"> neutral </Button> </ThemeProvider> ); }
3,412
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/CustomColor.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ palette: { neutral: { light: '#838fa2', main: '#64748b', dark: '#465161', contrastText: '#fff', }, }, }); declare module '@mui/material/styles' { interface Palette { neutral: Palette['primary']; } // allow configuration using `createTheme` interface PaletteOptions { neutral?: PaletteOptions['primary']; } } // @babel-ignore-comment-in-output Update the Button's color prop options declare module '@mui/material/Button' { interface ButtonPropsColorOverrides { neutral: true; } } export default function CustomColor() { return ( <ThemeProvider theme={theme}> <Button color="neutral" variant="contained"> neutral </Button> </ThemeProvider> ); }
3,413
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/CustomColor.tsx.preview
<ThemeProvider theme={theme}> <Button color="neutral" variant="contained"> neutral </Button> </ThemeProvider>
3,414
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/Intentions.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Grid from '@mui/material/Grid'; import Typography from '@mui/material/Typography'; import { createTheme, ThemeProvider, useTheme, rgbToHex, styled, } from '@mui/material/styles'; const Group = styled(Typography)(({ theme }) => ({ marginTop: theme.spacing(3), })); const Color = styled(Grid)(({ theme }) => ({ display: 'flex', alignItems: 'center', '& div:first-of-type': { width: theme.spacing(6), height: theme.spacing(6), marginRight: theme.spacing(1), borderRadius: theme.shape.borderRadius, boxShadow: 'inset 0 2px 4px 0 rgba(0, 0, 0, .06)', }, })); function IntentionsInner() { const theme = useTheme(); const item = (color, name) => ( <Color item xs={12} sm={6} md={4}> <div style={{ backgroundColor: color }} /> <div> <Typography variant="body2">{name}</Typography> <Typography variant="body2" color="text.secondary"> {rgbToHex(color)} </Typography> </div> </Color> ); return ( <Box sx={{ width: '100%' }}> <Group gutterBottom>Primary</Group> <Grid container spacing={2}> {item(theme.palette.primary.light, 'palette.primary.light')} {item(theme.palette.primary.main, 'palette.primary.main')} {item(theme.palette.primary.dark, 'palette.primary.dark')} </Grid> <Group gutterBottom>Secondary</Group> <Grid container spacing={2}> {item(theme.palette.secondary.light, 'palette.secondary.light')} {item(theme.palette.secondary.main, 'palette.secondary.main')} {item(theme.palette.secondary.dark, 'palette.secondary.dark')} </Grid> <Group gutterBottom>Error</Group> <Grid container spacing={2}> {item(theme.palette.error.light, 'palette.error.light')} {item(theme.palette.error.main, 'palette.error.main')} {item(theme.palette.error.dark, 'palette.error.dark')} </Grid> <Group gutterBottom>Warning</Group> <Grid container spacing={2}> {item(theme.palette.warning.light, 'palette.warning.light')} {item(theme.palette.warning.main, 'palette.warning.main')} {item(theme.palette.warning.dark, 'palette.warning.dark')} </Grid> <Group gutterBottom>Info</Group> <Grid container spacing={2}> {item(theme.palette.info.light, 'palette.info.light')} {item(theme.palette.info.main, 'palette.info.main')} {item(theme.palette.info.dark, 'palette.info.dark')} </Grid> <Group gutterBottom>Success</Group> <Grid container spacing={2}> {item(theme.palette.success.light, 'palette.success.light')} {item(theme.palette.success.main, 'palette.success.main')} {item(theme.palette.success.dark, 'palette.success.dark')} </Grid> </Box> ); } export default function Intentions() { const theme = useTheme(); return ( <ThemeProvider theme={createTheme({ palette: { mode: theme.palette.mode, }, })} > <IntentionsInner /> </ThemeProvider> ); }
3,415
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ManuallyProvideCustomColor.js
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 // Update the Button's color options to include an ochre option const theme = createTheme({ palette: { ochre: { main: '#E3D026', light: '#E9DB5D', dark: '#A29415', contrastText: '#242105', }, }, }); export default function ManuallyProvideCustomColor() { 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> ); }
3,416
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ManuallyProvideCustomColor.tsx
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 ManuallyProvideCustomColor() { 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> ); }
3,417
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ManuallyProvidePaletteColor.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; import { Box, Stack } from '@mui/system'; import { unstable_capitalize as capitalize } from '@mui/utils'; import { Typography } from '@mui/material'; const theme = createTheme({ palette: { primary: { main: '#FF5733', // light: will be calculated from palette.primary.main, // dark: will be calculated from palette.primary.main, // contrastText: will be calculated to contrast with palette.primary.main }, secondary: { main: '#E0C2FF', light: '#F5EBFF', // dark: will be calculated from palette.secondary.main, contrastText: '#47008F', }, }, }); function ColorShowcase({ color }) { return ( <Stack gap={2} alignItems="center"> <Button variant="contained" color={color}> {capitalize(color)} </Button> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: `${color}.light`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: `${color}.main`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: `${color}.dark`, width: 40, height: 20 }} /> </Stack> </Stack> </Stack> ); } ColorShowcase.propTypes = { color: PropTypes.oneOf(['primary', 'secondary']).isRequired, }; export default function ManuallyProvidePaletteColor() { return ( <ThemeProvider theme={theme}> <Stack direction="row" gap={8}> <ColorShowcase color="primary" /> <ColorShowcase color="secondary" /> </Stack> </ThemeProvider> ); }
3,418
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ManuallyProvidePaletteColor.tsx
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 { unstable_capitalize as capitalize } from '@mui/utils'; import { Typography } from '@mui/material'; const theme = createTheme({ palette: { primary: { main: '#FF5733', // light: will be calculated from palette.primary.main, // dark: will be calculated from palette.primary.main, // contrastText: will be calculated to contrast with palette.primary.main }, secondary: { main: '#E0C2FF', light: '#F5EBFF', // dark: will be calculated from palette.secondary.main, contrastText: '#47008F', }, }, }); function ColorShowcase({ color }: { color: 'primary' | 'secondary' }) { return ( <Stack gap={2} alignItems="center"> <Button variant="contained" color={color}> {capitalize(color)} </Button> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: `${color}.light`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: `${color}.main`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: `${color}.dark`, width: 40, height: 20 }} /> </Stack> </Stack> </Stack> ); } export default function ManuallyProvidePaletteColor() { return ( <ThemeProvider theme={theme}> <Stack direction="row" gap={8}> <ColorShowcase color="primary" /> <ColorShowcase color="secondary" /> </Stack> </ThemeProvider> ); }
3,419
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ManuallyProvidePaletteColor.tsx.preview
<ThemeProvider theme={theme}> <Stack direction="row" gap={8}> <ColorShowcase color="primary" /> <ColorShowcase color="secondary" /> </Stack> </ThemeProvider>
3,420
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/Palette.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { purple } from '@mui/material/colors'; import Button from '@mui/material/Button'; const theme = createTheme({ palette: { primary: { // Purple and green play nicely together. main: purple[500], }, secondary: { // This is green.A700 as hex. main: '#11cb5f', }, }, }); export default function Palette() { return ( <ThemeProvider theme={theme}> <Button>Primary</Button> <Button color="secondary">Secondary</Button> </ThemeProvider> ); }
3,421
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/Palette.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { purple } from '@mui/material/colors'; import Button from '@mui/material/Button'; const theme = createTheme({ palette: { primary: { // Purple and green play nicely together. main: purple[500], }, secondary: { // This is green.A700 as hex. main: '#11cb5f', }, }, }); export default function Palette() { return ( <ThemeProvider theme={theme}> <Button>Primary</Button> <Button color="secondary">Secondary</Button> </ThemeProvider> ); }
3,422
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/Palette.tsx.preview
<ThemeProvider theme={theme}> <Button>Primary</Button> <Button color="secondary">Secondary</Button> </ThemeProvider>
3,423
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/ToggleColorMode.tsx.preview
<ColorModeContext.Provider value={colorMode}> <ThemeProvider theme={theme}> <MyApp /> </ThemeProvider> </ColorModeContext.Provider>
3,424
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/TonalOffset.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles'; import { blue } from '@mui/material/colors'; import { Box, Stack } from '@mui/system'; import { Typography } from '@mui/material'; const defaultTonalOffsetTheme = createTheme({ palette: { primary: { main: blue[500], }, }, }); const higherTonalOffsetTheme = createTheme({ palette: { primary: { main: blue[500], }, tonalOffset: 0.5, }, }); const asymmetricTonalOffsetTheme = createTheme({ palette: { primary: { main: blue[500], }, tonalOffset: { light: 0.1, dark: 0.9, }, }, }); function ColorShowcase({ title, color }) { const { palette: { tonalOffset }, } = useTheme(); let caption; if (typeof tonalOffset === 'number') { caption = tonalOffset; } else { caption = `{ light: ${tonalOffset.light}, dark: ${tonalOffset.dark} }`; } return ( <Stack gap={1} alignItems="center"> <span> <b>{title}</b> </span> <span>{caption}</span> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: `${color}.light`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: `${color}.main`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: `${color}.dark`, width: 40, height: 20 }} /> </Stack> </Stack> </Stack> ); } ColorShowcase.propTypes = { color: PropTypes.string.isRequired, title: PropTypes.string.isRequired, }; export default function TonalOffset() { return ( <Stack direction={{ xs: 'column', sm: 'row' }} gap={8}> <ThemeProvider theme={defaultTonalOffsetTheme}> <ColorShowcase title="Default tonal offset" color="primary" /> </ThemeProvider> <ThemeProvider theme={higherTonalOffsetTheme}> <ColorShowcase title="Higher tonal offset" color="primary" /> </ThemeProvider> <ThemeProvider theme={asymmetricTonalOffsetTheme}> <ColorShowcase title="Asymmetric tonal offset" color="primary" /> </ThemeProvider> </Stack> ); }
3,425
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/TonalOffset.tsx
import * as React from 'react'; import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles'; import { blue } from '@mui/material/colors'; import { Box, Stack } from '@mui/system'; import { Typography } from '@mui/material'; const defaultTonalOffsetTheme = createTheme({ palette: { primary: { main: blue[500], }, }, }); const higherTonalOffsetTheme = createTheme({ palette: { primary: { main: blue[500], }, tonalOffset: 0.5, }, }); const asymmetricTonalOffsetTheme = createTheme({ palette: { primary: { main: blue[500], }, tonalOffset: { light: 0.1, dark: 0.9, }, }, }); function ColorShowcase({ title, color }: { title: string; color: string }) { const { palette: { tonalOffset }, } = useTheme(); let caption; if (typeof tonalOffset === 'number') { caption = tonalOffset; } else { caption = `{ light: ${tonalOffset.light}, dark: ${tonalOffset.dark} }`; } return ( <Stack gap={1} alignItems="center"> <span> <b>{title}</b> </span> <span>{caption}</span> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: `${color}.light`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: `${color}.main`, width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: `${color}.dark`, width: 40, height: 20 }} /> </Stack> </Stack> </Stack> ); } export default function TonalOffset() { return ( <Stack direction={{ xs: 'column', sm: 'row' }} gap={8}> <ThemeProvider theme={defaultTonalOffsetTheme}> <ColorShowcase title="Default tonal offset" color="primary" /> </ThemeProvider> <ThemeProvider theme={higherTonalOffsetTheme}> <ColorShowcase title="Higher tonal offset" color="primary" /> </ThemeProvider> <ThemeProvider theme={asymmetricTonalOffsetTheme}> <ColorShowcase title="Asymmetric tonal offset" color="primary" /> </ThemeProvider> </Stack> ); }
3,426
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/TonalOffset.tsx.preview
<ThemeProvider theme={defaultTonalOffsetTheme}> <ColorShowcase title="Default tonal offset" color="primary" /> </ThemeProvider> <ThemeProvider theme={higherTonalOffsetTheme}> <ColorShowcase title="Higher tonal offset" color="primary" /> </ThemeProvider> <ThemeProvider theme={asymmetricTonalOffsetTheme}> <ColorShowcase title="Asymmetric tonal offset" color="primary" /> </ThemeProvider>
3,427
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/UsingAugmentColor.js
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 a salmon color // Update the Button's color options to include a salmon option let theme = createTheme({ // Theme customization goes here as usual, including tonalOffset and/or // contrastThreshold as the augmentColor() function relies on these }); theme = createTheme(theme, { // Custom colors created with augmentColor go here palette: { salmon: theme.palette.augmentColor({ color: { main: '#FF5733', }, name: 'salmon', }), }, }); export default function UsingAugmentColor() { return ( <ThemeProvider theme={theme}> <Stack gap={2} alignItems="center"> <Button variant="contained" color="salmon"> Salmon </Button> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: 'salmon.light', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: 'salmon.main', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: 'salmon.dark', width: 40, height: 20 }} /> </Stack> </Stack> </Stack> </ThemeProvider> ); }
3,428
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/UsingAugmentColor.tsx
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 a salmon color declare module '@mui/material/styles' { interface Palette { salmon: Palette['primary']; } interface PaletteOptions { salmon?: PaletteOptions['primary']; } } // Update the Button's color options to include a salmon option declare module '@mui/material/Button' { interface ButtonPropsColorOverrides { salmon: true; } } let theme = createTheme({ // Theme customization goes here as usual, including tonalOffset and/or // contrastThreshold as the augmentColor() function relies on these }); theme = createTheme(theme, { // Custom colors created with augmentColor go here palette: { salmon: theme.palette.augmentColor({ color: { main: '#FF5733', }, name: 'salmon', }), }, }); export default function UsingAugmentColor() { return ( <ThemeProvider theme={theme}> <Stack gap={2} alignItems="center"> <Button variant="contained" color="salmon"> Salmon </Button> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: 'salmon.light', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: 'salmon.main', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: 'salmon.dark', width: 40, height: 20 }} /> </Stack> </Stack> </Stack> </ThemeProvider> ); }
3,429
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/UsingColorObject.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { lime, purple } from '@mui/material/colors'; import Button from '@mui/material/Button'; const theme = createTheme({ palette: { primary: lime, secondary: purple, }, }); export default function UsingColorObject() { return ( <ThemeProvider theme={theme}> <Button variant="contained">Primary</Button> <Button variant="contained" color="secondary" sx={{ ml: 2 }}> Secondary </Button> </ThemeProvider> ); }
3,430
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/UsingColorObject.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { lime, purple } from '@mui/material/colors'; import Button from '@mui/material/Button'; const theme = createTheme({ palette: { primary: lime, secondary: purple, }, }); export default function UsingColorObject() { return ( <ThemeProvider theme={theme}> <Button variant="contained">Primary</Button> <Button variant="contained" color="secondary" sx={{ ml: 2 }}> Secondary </Button> </ThemeProvider> ); }
3,431
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/UsingColorObject.tsx.preview
<ThemeProvider theme={theme}> <Button variant="contained">Primary</Button> <Button variant="contained" color="secondary" sx={{ ml: 2 }}> Secondary </Button> </ThemeProvider>
3,432
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/UsingStylesUtils.js
import * as React from 'react'; import { createTheme, ThemeProvider, alpha, getContrastRatio, } 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 a violet color // Update the Button's color options to include a violet option const violetBase = '#7F00FF'; const violetMain = alpha(violetBase, 0.7); const theme = createTheme({ palette: { violet: { main: violetMain, light: alpha(violetBase, 0.5), dark: alpha(violetBase, 0.9), contrastText: getContrastRatio(violetMain, '#fff') > 4.5 ? '#fff' : '#111', }, }, }); export default function UsingStylesUtils() { return ( <ThemeProvider theme={theme}> <Stack gap={2} alignItems="center"> <Button variant="contained" color="violet"> Violet </Button> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: 'violet.light', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: 'violet.main', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: 'violet.dark', width: 40, height: 20 }} /> </Stack> </Stack> </Stack> </ThemeProvider> ); }
3,433
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/UsingStylesUtils.tsx
import * as React from 'react'; import { createTheme, ThemeProvider, alpha, getContrastRatio, } 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 a violet color declare module '@mui/material/styles' { interface Palette { violet: Palette['primary']; } interface PaletteOptions { violet?: PaletteOptions['primary']; } } // Update the Button's color options to include a violet option declare module '@mui/material/Button' { interface ButtonPropsColorOverrides { violet: true; } } const violetBase = '#7F00FF'; const violetMain = alpha(violetBase, 0.7); const theme = createTheme({ palette: { violet: { main: violetMain, light: alpha(violetBase, 0.5), dark: alpha(violetBase, 0.9), contrastText: getContrastRatio(violetMain, '#fff') > 4.5 ? '#fff' : '#111', }, }, }); export default function UsingStylesUtils() { return ( <ThemeProvider theme={theme}> <Stack gap={2} alignItems="center"> <Button variant="contained" color="violet"> Violet </Button> <Stack direction="row" gap={1}> <Stack alignItems="center"> <Typography variant="body2">light</Typography> <Box sx={{ bgcolor: 'violet.light', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">main</Typography> <Box sx={{ bgcolor: 'violet.main', width: 40, height: 20 }} /> </Stack> <Stack alignItems="center"> <Typography variant="body2">dark</Typography> <Box sx={{ bgcolor: 'violet.dark', width: 40, height: 20 }} /> </Stack> </Stack> </Stack> </ThemeProvider> ); }
3,434
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/palette/palette.md
# Palette <p class="description">The palette enables you to modify the color of the components to suit your brand.</p> ## Color tokens Palette colors are represented by four tokens: - `main`: The main shade of the color - `light`: A lighter shade of `main` - `dark`: A darker shade of `main` - `contrastText`: Text color, intended to contrast with `main` Here's how Material UI's default theme defines the primary color tokens: ```js const primary = { main: '#1976d2', light: '#42a5f5', dark: '#1565c0', contrastText: '#fff', }; ``` See the [Color](/material-ui/customization/color/) documentation for details on the Material Design color system. ## Default colors The theme exposes the following default palette colors (accessible under `theme.palette.*`): - `primary` - for primary interface elements. - `secondary` - for secondary interface elements. - `error` - for elements that the user should be made aware of. - `warning` - for potentially dangerous actions or important messages. - `info` - for highlighting neutral information. - `success` - for indicating the successful completion of an action that the user triggered. See Material Design's [Color System](https://m2.material.io/design/color/the-color-system.html) for details on color usage and guidelines. ### Values You can explore the default palette values using [the theme explorer](/material-ui/customization/default-theme/?expand-path=$.palette), or by opening the dev tools console on this page (`window.theme.palette`). {{"demo": "Intentions.js", "bg": "inline", "hideToolbar": true}} The default palette uses the shades prefixed with `A` (`A200`, etc.) for the secondary palette color, and the un-prefixed shades for the other palette colors. ### Customization You may override the default palette values by including a palette object as part of your theme. If any of the: - [`.palette.primary`](/material-ui/customization/default-theme/?expand-path=$.palette.primary) - [`.palette.secondary`](/material-ui/customization/default-theme/?expand-path=$.palette.secondary) - [`.palette.error`](/material-ui/customization/default-theme/?expand-path=$.palette.error) - [`.palette.warning`](/material-ui/customization/default-theme/?expand-path=$.palette.warning) - [`.palette.info`](/material-ui/customization/default-theme/?expand-path=$.palette.info) - [`.palette.success`](/material-ui/customization/default-theme/?expand-path=$.palette.success) palette color objects are provided, they will replace the default ones. This can be achieved by either using a color object or by providing the colors directly: #### Using a color object The most direct way to customize a palette color is to import and apply one or more [color objects](/material-ui/customization/color/#2014-material-design-color-palettes), as shown below: {{"demo": "UsingColorObject.js", "defaultCodeOpen": true}} #### Providing the colors directly To modify each color directly, provide an object with one or more of the color tokens. Only the `main` token is required; `light`, `dark`, and `contrastText` are optional, and if not provided, then their values are calculated automatically: ```js import { createTheme } from '@mui/material/styles'; const theme = createTheme({ palette: { primary: { main: '#FF5733', // light: will be calculated from palette.primary.main, // dark: will be calculated from palette.primary.main, // contrastText: will be calculated to contrast with palette.primary.main }, secondary: { main: '#E0C2FF', light: '#F5EBFF', // dark: will be calculated from palette.secondary.main, contrastText: '#47008F', }, }, }); ``` {{"demo": "ManuallyProvidePaletteColor.js", "defaultCodeOpen": false}} ### Contrast threshold The `contrastText` token is calculated using the `contrastThreshold` value, to maximize the contrast between the background and the text. A higher contrast threshold value increases the point at which a background color is considered light, and thus given a dark `contrastText`. Note that the contrast threshold follows a non-linear curve, and defaults to a value of 3 which indicates a minimum contrast ratio of 3:1. {{"demo": "ContrastThreshold.js", "defaultCodeOpen": false}} ### Tonal offset The `light` and `dark` tokens are calculated using the `tonalOffset` value, to shift the `main` color's luminance. A higher tonal offset value will make `light` tokens lighter, and `dark` tokens darker. :::warning This only applies when working with custom colors—it won't have any effect on the [default values](#default-values). ::: For example, the tonal offset default value `0.2` shifts the luminance by approximately two indexes, so if the `main` token is `blue[500]`, then the `light` token would be `blue[300]` and `dark` would be `blue[700]`. The tonal offset value can be either a number between 0 and 1 (which would apply to both `light` and `dark` tokens) or an object with `light` and `dark` keys specified: {{"demo": "TonalOffset.js", "defaultCodeOpen": false}} ## Custom colors :::warning Unlike [default colors](#default-colors), tokens for custom colors are _not_ automatically calculated. ::: To add custom colors, you must either provide the tokens manually, or generate them using the `augmentColor` utility: ### Provide tokens manually The most straightforward approach is to define all tokens—`main`, `light`, `dark`, and `contrastText`—manually: ```jsx import { createTheme } from '@mui/material/styles'; const theme = createTheme({ palette: { ochre: { main: '#E3D026', light: '#E9DB5D', dark: '#A29415', contrastText: '#242105', }, }, }); ``` {{"demo": "ManuallyProvideCustomColor.js", "defaultCodeOpen": false}} If you need to manipulate colors, `@mui/material/styles` provides [a set of utilities](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/styles/index.d.ts#L52-L67) to help with this. The following example uses the `alpha` and `getContrastRatio` utilities to define tokens using opacity: ```jsx import { createTheme, alpha, getContrastRatio } from '@mui/material/styles'; const violetBase = '#7F00FF'; const violetMain = alpha(violetBase, 0.7); const theme = createTheme({ palette: { violet: { main: violetMain, light: alpha(violetBase, 0.5), dark: alpha(violetBase, 0.9), contrastText: getContrastRatio(violetMain, '#fff') > 4.5 ? '#fff' : '#111', }, }, }); ``` {{"demo": "UsingStylesUtils.js", "defaultCodeOpen": false}} ### Generate tokens using augmentColor utility Alternatively, you can generate the `light`, `dark` and `contrastText` tokens using the palette's `augmentColor` utility, which is the same function used for the default palette colors. This requires creating the theme in two steps and providing the `main` token on which the other will be based on: ```jsx import { createTheme } from '@mui/material/styles'; let theme = createTheme({ // Theme customization goes here as usual, including tonalOffset and/or // contrastThreshold as the augmentColor() function relies on these }); theme = createTheme(theme, { // Custom colors created with augmentColor go here palette: { salmon: theme.palette.augmentColor({ color: { main: '#FF5733', }, name: 'salmon', }), }, }); ``` {{"demo": "UsingAugmentColor.js", "defaultCodeOpen": false}} The [contrast threshold](#contrast-threshold) and [tonal offset](#tonal-offset) values will apply for the colors defined using this utility. ### Using in components After adding a custom color, you will be able to use it in components just like you do with default palette colors: ```js <Button color="custom"> ``` ### TypeScript If you're using TypeScript, then you need to use [module augmentation](/material-ui/guides/typescript/#customization-of-theme) for custom colors. To add a custom color to the palette, you must add it to the `Palette` and `PaletteOptions` interfaces: <!-- tested with packages/mui-material/test/typescript/augmentation/paletteColors.spec.ts --> ```ts declare module '@mui/material/styles' { interface Palette { custom: Palette['primary']; } interface PaletteOptions { custom?: PaletteOptions['primary']; } } ``` To use a custom color for the `color` prop of a component, you must add it to the component's `PropsColorOverrides` interface. The example below shows how to do this with a Button component: <!-- tested with packages/mui-material/test/typescript/augmentation/paletteColors.spec.ts --> ```ts declare module '@mui/material/Button' { interface ButtonPropsColorOverrides { custom: true; } } ``` ## Adding color tokens To add a new [color token](#color-tokens), include it in the color's object as follows: ```jsx 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], }, }, }); ``` {{"demo": "AddingColorTokens.js", "defaultCodeOpen": false}} ### TypeScript If you're using TypeScript, then you'll need to use [module augmentation](/material-ui/guides/typescript/#customization-of-theme) to add the new color token to the `PaletteColor` and `SimplePaletteColorOptions` interfaces as follows: <!-- tested with packages/mui-material/test/typescript/augmentation/paletteColors.spec.ts --> ```ts declare module '@mui/material/styles' { interface PaletteColor { darker?: string; } interface SimplePaletteColorOptions { darker?: string; } } ``` ## Non-palette colors To learn how to add colors outside of `theme.palette`, see [Theming—Custom variables](/material-ui/customization/theming/#custom-variables). ## Accessibility To meet the minimum contrast of at least 4.5:1 as defined in [WCAG 2.1 Rule 1.4.3](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html), create a custom theme with a [contrast threshold](#contrast-threshold) value of 4.5 as follows: ```js import { createTheme } from '@mui/material/styles'; const theme = createTheme({ palette: { contrastThreshold: 4.5, }, }); ``` :::warning The `contrastThreshold` parameter can produce counterproductive results.\ Please verify that the [APCA](https://contrast.tools/?tab=apca) color contrast is improved (WCAG 3 [will use](https://typefully.com/u/DanHollick/t/sle13GMW2Brp) this new algorithm). ::: ## Picking colors Need inspiration? The Material Design team has built an [palette configuration tool](/material-ui/customization/color/#picking-colors) to help you. ## Dark mode For details of how you can set up a dark mode for your theme, head to the [dark mode guide](/material-ui/customization/dark-mode/).
3,435
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/spacing/spacing.md
# Spacing <p class="description">Use the theme.spacing() helper to create consistent spacing between the elements of your UI.</p> Material UI uses [a recommended 8px scaling factor](https://m2.material.io/design/layout/understanding-layout.html) by default. ```js const theme = createTheme(); theme.spacing(2); // `${8 * 2}px` = '16px' ``` ## Custom spacing You can change the spacing transformation by providing: - a number ```js const theme = createTheme({ spacing: 4, }); theme.spacing(2); // `${4 * 2}px` = '8px' ``` - a function ```js const theme = createTheme({ spacing: (factor) => `${0.25 * factor}rem`, // (Bootstrap strategy) }); theme.spacing(2); // = 0.25 * 2rem = 0.5rem = 8px ``` - an array ```js const theme = createTheme({ spacing: [0, 4, 8, 16, 32, 64], }); theme.spacing(2); // = '8px' ``` ## Multiple arity The `theme.spacing()` helper accepts up to 4 arguments. You can use the arguments to reduce the boilerplate. ```diff -padding: `${theme.spacing(1)} ${theme.spacing(2)}`, // '8px 16px' +padding: theme.spacing(1, 2), // '8px 16px' ``` Mixing string values is also supported: ```js margin: theme.spacing(1, 'auto'), // '8px auto' ```
3,436
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/DefaultProps.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ components: { // Name of the component ⚛️ MuiButtonBase: { defaultProps: { // The default props to change disableRipple: true, // No more ripple, on the whole application 💣! }, }, }, }); export default function DefaultProps() { return ( <ThemeProvider theme={theme}> <Button>This button has disabled ripples.</Button> </ThemeProvider> ); }
3,437
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/DefaultProps.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ components: { // Name of the component ⚛️ MuiButtonBase: { defaultProps: { // The default props to change disableRipple: true, // No more ripple, on the whole application 💣! }, }, }, }); export default function DefaultProps() { return ( <ThemeProvider theme={theme}> <Button>This button has disabled ripples.</Button> </ThemeProvider> ); }
3,438
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/DefaultProps.tsx.preview
<ThemeProvider theme={theme}> <Button>This button has disabled ripples.</Button> </ThemeProvider>
3,439
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalCss.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ components: { MuiButton: { // Style sheet name ⚛️ styleOverrides: { // Name of the rule textPrimary: { // Some CSS background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)', borderRadius: 3, border: 0, color: 'white', height: 48, padding: '0 30px', boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)', }, }, }, }, }); export default function GlobalCss() { return ( <ThemeProvider theme={theme}> <Button>Overrides CSS</Button> </ThemeProvider> ); }
3,440
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalCss.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ components: { MuiButton: { // Style sheet name ⚛️ styleOverrides: { // Name of the rule textPrimary: { // Some CSS background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)', borderRadius: 3, border: 0, color: 'white', height: 48, padding: '0 30px', boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)', }, }, }, }, }); export default function GlobalCss() { return ( <ThemeProvider theme={theme}> <Button>Overrides CSS</Button> </ThemeProvider> ); }
3,441
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalCss.tsx.preview
<ThemeProvider theme={theme}> <Button>Overrides CSS</Button> </ThemeProvider>
3,442
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverride.js
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ components: { MuiButton: { styleOverrides: { root: { fontSize: '1rem', }, }, }, }, }); export default function GlobalThemeOverride() { return ( <ThemeProvider theme={theme}> <Button>font-size: 1rem</Button> </ThemeProvider> ); }
3,443
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverride.tsx
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ components: { MuiButton: { styleOverrides: { root: { fontSize: '1rem', }, }, }, }, }); export default function GlobalThemeOverride() { return ( <ThemeProvider theme={theme}> <Button>font-size: 1rem</Button> </ThemeProvider> ); }
3,444
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverride.tsx.preview
<ThemeProvider theme={theme}> <Button>font-size: 1rem</Button> </ThemeProvider>
3,445
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverrideCallback.js
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Box from '@mui/material/Box'; import Slider, { sliderClasses } from '@mui/material/Slider'; const finalTheme = createTheme({ components: { MuiSlider: { styleOverrides: { valueLabel: ({ ownerState, theme }) => ({ ...(ownerState.orientation === 'vertical' && { backgroundColor: 'transparent', color: theme.palette.grey[500], fontWeight: 700, padding: 0, left: '3rem', }), [`&.${sliderClasses.valueLabelOpen}`]: { transform: 'none', top: 'initial', }, }), }, }, }, }); function valuetext(value) { return `${value}°C`; } export default function GlobalThemeOverrideCallback() { return ( <ThemeProvider theme={finalTheme}> <Box sx={{ height: 180, display: 'inline-block' }}> <Slider getAriaLabel={() => 'Temperature'} orientation="vertical" getAriaValueText={valuetext} defaultValue={[25, 50]} marks={[ { value: 0 }, { value: 25 }, { value: 50 }, { value: 75 }, { value: 100 }, ]} valueLabelFormat={valuetext} valueLabelDisplay="on" /> </Box> </ThemeProvider> ); }
3,446
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverrideCallback.tsx
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Box from '@mui/material/Box'; import Slider, { sliderClasses } from '@mui/material/Slider'; const finalTheme = createTheme({ components: { MuiSlider: { styleOverrides: { valueLabel: ({ ownerState, theme }) => ({ ...(ownerState.orientation === 'vertical' && { backgroundColor: 'transparent', color: theme.palette.grey[500], fontWeight: 700, padding: 0, left: '3rem', }), [`&.${sliderClasses.valueLabelOpen}`]: { transform: 'none', top: 'initial', }, }), }, }, }, }); function valuetext(value: number) { return `${value}°C`; } export default function GlobalThemeOverrideCallback() { return ( <ThemeProvider theme={finalTheme}> <Box sx={{ height: 180, display: 'inline-block' }}> <Slider getAriaLabel={() => 'Temperature'} orientation="vertical" getAriaValueText={valuetext} defaultValue={[25, 50]} marks={[ { value: 0 }, { value: 25 }, { value: 50 }, { value: 75 }, { value: 100 }, ]} valueLabelFormat={valuetext} valueLabelDisplay="on" /> </Box> </ThemeProvider> ); }
3,447
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverrideSx.js
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Chip from '@mui/material/Chip'; import Check from '@mui/icons-material/Check'; const finalTheme = createTheme({ components: { MuiChip: { styleOverrides: { root: ({ theme }) => theme.unstable_sx({ // https://mui.com/system/getting-started/the-sx-prop/#spacing px: 1, py: 0.25, // https://mui.com/system/borders/#border-radius borderRadius: 1, // 4px as default. }), label: { padding: 'initial', }, icon: ({ theme }) => theme.unstable_sx({ mr: 0.5, ml: '-2px', }), }, }, }, }); export default function GlobalThemeOverrideSx() { return ( <ThemeProvider theme={finalTheme}> <Chip color="success" label={ <span> <b>Status:</b> Completed </span> } icon={<Check fontSize="small" />} /> </ThemeProvider> ); }
3,448
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverrideSx.tsx
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Chip from '@mui/material/Chip'; import Check from '@mui/icons-material/Check'; const finalTheme = createTheme({ components: { MuiChip: { styleOverrides: { root: ({ theme }) => theme.unstable_sx({ // https://mui.com/system/getting-started/the-sx-prop/#spacing px: 1, py: 0.25, // https://mui.com/system/borders/#border-radius borderRadius: 1, // 4px as default. }), label: { padding: 'initial', }, icon: ({ theme }) => theme.unstable_sx({ mr: 0.5, ml: '-2px', }), }, }, }, }); export default function GlobalThemeOverrideSx() { return ( <ThemeProvider theme={finalTheme}> <Chip color="success" label={ <span> <b>Status:</b> Completed </span> } icon={<Check fontSize="small" />} /> </ThemeProvider> ); }
3,449
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeOverrideSx.tsx.preview
<ThemeProvider theme={finalTheme}> <Chip color="success" label={ <span> <b>Status:</b> Completed </span> } icon={<Check fontSize="small" />} /> </ThemeProvider>
3,450
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeVariants.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; const defaultTheme = createTheme(); const theme = createTheme({ components: { MuiButton: { variants: [ { props: { variant: 'dashed' }, style: { textTransform: 'none', border: `2px dashed ${defaultTheme.palette.primary.main}`, color: defaultTheme.palette.primary.main, }, }, { props: { variant: 'dashed', color: 'secondary' }, style: { border: `2px dashed ${defaultTheme.palette.secondary.main}`, color: defaultTheme.palette.secondary.main, }, }, { props: { variant: 'dashed', size: 'large' }, style: { borderWidth: 4, }, }, { props: { variant: 'dashed', color: 'secondary', size: 'large' }, style: { fontSize: 18, }, }, ], }, }, }); export default function GlobalThemeVariants() { return ( <ThemeProvider theme={theme}> <Button variant="dashed" sx={{ m: 1 }}> Dashed </Button> <Button variant="dashed" color="secondary" sx={{ m: 1 }}> Secondary </Button> <Button variant="dashed" size="large" sx={{ m: 1 }}> Large </Button> <Button variant="dashed" color="secondary" size="large" sx={{ m: 1 }}> Secondary large </Button> </ThemeProvider> ); }
3,451
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeVariants.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Button from '@mui/material/Button'; declare module '@mui/material/Button' { interface ButtonPropsVariantOverrides { dashed: true; } } const defaultTheme = createTheme(); const theme = createTheme({ components: { MuiButton: { variants: [ { props: { variant: 'dashed' }, style: { textTransform: 'none', border: `2px dashed ${defaultTheme.palette.primary.main}`, color: defaultTheme.palette.primary.main, }, }, { props: { variant: 'dashed', color: 'secondary' }, style: { border: `2px dashed ${defaultTheme.palette.secondary.main}`, color: defaultTheme.palette.secondary.main, }, }, { props: { variant: 'dashed', size: 'large' }, style: { borderWidth: 4, }, }, { props: { variant: 'dashed', color: 'secondary', size: 'large' }, style: { fontSize: 18, }, }, ], }, }, }); export default function GlobalThemeVariants() { return ( <ThemeProvider theme={theme}> <Button variant="dashed" sx={{ m: 1 }}> Dashed </Button> <Button variant="dashed" color="secondary" sx={{ m: 1 }}> Secondary </Button> <Button variant="dashed" size="large" sx={{ m: 1 }}> Large </Button> <Button variant="dashed" color="secondary" size="large" sx={{ m: 1 }}> Secondary large </Button> </ThemeProvider> ); }
3,452
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/GlobalThemeVariants.tsx.preview
<ThemeProvider theme={theme}> <Button variant="dashed" sx={{ m: 1 }}> Dashed </Button> <Button variant="dashed" color="secondary" sx={{ m: 1 }}> Secondary </Button> <Button variant="dashed" size="large" sx={{ m: 1 }}> Large </Button> <Button variant="dashed" color="secondary" size="large" sx={{ m: 1 }}> Secondary large </Button> </ThemeProvider>
3,453
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/ThemeVariables.js
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ typography: { button: { fontSize: '1rem', }, }, }); export default function ThemeVariables() { return ( <ThemeProvider theme={theme}> <Button>font-size: 1rem</Button> </ThemeProvider> ); }
3,454
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/ThemeVariables.tsx
import * as React from 'react'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import Button from '@mui/material/Button'; const theme = createTheme({ typography: { button: { fontSize: '1rem', }, }, }); export default function ThemeVariables() { return ( <ThemeProvider theme={theme}> <Button>font-size: 1rem</Button> </ThemeProvider> ); }
3,455
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/ThemeVariables.tsx.preview
<ThemeProvider theme={theme}> <Button>font-size: 1rem</Button> </ThemeProvider>
3,456
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theme-components/theme-components.md
# Themed components <p class="description">You can customize a component's styles, default props, and more by using its component key inside the theme.</p> The `components` key in the theme helps to achieve styling consistency across your application. However, the theme isn't tree-shakable, prefer creating new components for heavy customizations. ## Theme default props Every Material UI component has default values for each of its props. To change these default values, use the `defaultProps` key exposed in the theme's `components` key: ```js const theme = createTheme({ components: { // Name of the component MuiButtonBase: { defaultProps: { // The props to change the default for. disableRipple: true, // No more ripple, on the whole application 💣! }, }, }, }); ``` {{"demo": "DefaultProps.js"}} If you're using TypeScript and [lab components](/material-ui/about-the-lab/), check [this article to learn how to override their styles](/material-ui/about-the-lab/#typescript). ## Theme style overrides The theme's `styleOverrides` key makes it possible to potentially change every single style injected by Material UI into the DOM. This is useful if you want to apply a fully custom design system to Material UI's components. ```js const theme = createTheme({ components: { // Name of the component MuiButton: { styleOverrides: { // Name of the slot root: { // Some CSS fontSize: '1rem', }, }, }, }, }); ``` {{"demo": "GlobalThemeOverride.js"}} Each component is composed of several different parts. These parts correspond to classes that are available to the component—see the **CSS** section of the component's API page for a detailed list. You can use these classes inside the `styleOverrides` key to modify the corresponding parts of the component. ```js const theme = createTheme({ components: { MuiButton: { styleOverrides: { root: ({ ownerState }) => ({ ...(ownerState.variant === 'contained' && ownerState.color === 'primary' && { backgroundColor: '#202020', color: '#fff', }), }), }, }, }, }); ``` ### Overrides based on props You can pass a callback as a value in each slot of the component's `styleOverrides` to apply styles based on props. The `ownerState` prop is a combination of public props that you pass to the component + internal state of the component. ```js const finalTheme = createTheme({ components: { MuiSlider: { styleOverrides: { valueLabel: ({ ownerState, theme }) => ({ ...(ownerState.orientation === 'vertical' && { backgroundColor: 'transparent', color: theme.palette.grey[500], }), }), }, }, }, }); ``` {{"demo": "GlobalThemeOverrideCallback.js"}} ### The `sx` syntax (experimental) The `sx` prop acts as a shortcut for defining custom styles that access the theme object. This prop lets you write inline styles using a superset of CSS. Learn more about [the concept behind the `sx` prop](/system/getting-started/the-sx-prop/) and [how `sx` differs from the `styled` utility](/system/styled/#difference-with-the-sx-prop). You can use the `sx` prop inside the `styleOverrides` key to modify styles within the theme using shorthand CSS notation. This is especially handy if you're already using the `sx` prop with your components, because you can use the same syntax in your theme and quickly transfer styles between the two. :::info The `sx` prop is a stable feature for customizing components in Material UI v5, but it is still considered _experimental_ when used directly inside the theme object. ::: {{"demo": "GlobalThemeOverrideSx.js", "defaultCodeOpen": false}} ```tsx const finalTheme = createTheme({ components: { MuiChip: { styleOverrides: { root: ({ theme }) => theme.unstable_sx({ px: 1, py: 0.25, borderRadius: 1, }), label: { padding: 'initial', }, icon: ({ theme }) => theme.unstable_sx({ mr: 0.5, ml: '-2px', }), }, }, }, }); ``` ### Specificity If you use the theming approach to customize the components, you'll still be able to override them using the `sx` prop as it has a higher CSS specificity, even if you're using the experimental `sx` syntax within the theme. ## Creating new component variants You can use the `variants` key in the theme's `components` section to create new variants to Material UI components. These new variants can specify what styles the component should have when that specific variant prop value is applied. The definitions are specified in an array, under the component's name. For each of them a CSS class is added to the HTML `<head>`. The order is important, so make sure that the styles that should win are specified last. ```js const theme = createTheme({ components: { MuiButton: { variants: [ { props: { variant: 'dashed' }, style: { textTransform: 'none', border: `2px dashed ${blue[500]}`, }, }, { props: { variant: 'dashed', color: 'secondary' }, style: { border: `4px dashed ${red[500]}`, }, }, ], }, }, }); ``` If you're using TypeScript, you'll need to specify your new variants/colors, using [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation). <!-- Tested with packages/mui-material/test/typescript/augmentation/themeComponents.spec.ts --> ```tsx declare module '@mui/material/Button' { interface ButtonPropsVariantOverrides { dashed: true; } } ``` {{"demo": "GlobalThemeVariants.js"}} ## Theme variables Another way to override the look of all component instances is to adjust the [theme configuration variables](/material-ui/customization/theming/#theme-configuration-variables). ```js const theme = createTheme({ typography: { button: { fontSize: '1rem', }, }, }); ``` {{"demo": "ThemeVariables.js"}}
3,457
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/CustomStyles.js
import * as React from 'react'; import Checkbox from '@mui/material/Checkbox'; import { createTheme, ThemeProvider, styled } from '@mui/material/styles'; import { orange } from '@mui/material/colors'; const CustomCheckbox = styled(Checkbox)(({ theme }) => ({ color: theme.status.danger, '&.Mui-checked': { color: theme.status.danger, }, })); const theme = createTheme({ status: { danger: orange[500], }, }); export default function CustomStyles() { return ( <ThemeProvider theme={theme}> <CustomCheckbox defaultChecked /> </ThemeProvider> ); }
3,458
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/CustomStyles.tsx
import * as React from 'react'; import Checkbox from '@mui/material/Checkbox'; import { createTheme, ThemeProvider, styled } from '@mui/material/styles'; import { orange } from '@mui/material/colors'; declare module '@mui/material/styles' { interface Theme { status: { danger: string; }; } // allow configuration using `createTheme` interface ThemeOptions { status?: { danger?: string; }; } } const CustomCheckbox = styled(Checkbox)(({ theme }) => ({ color: theme.status.danger, '&.Mui-checked': { color: theme.status.danger, }, })); const theme = createTheme({ status: { danger: orange[500], }, }); export default function CustomStyles() { return ( <ThemeProvider theme={theme}> <CustomCheckbox defaultChecked /> </ThemeProvider> ); }
3,459
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/CustomStyles.tsx.preview
<ThemeProvider theme={theme}> <CustomCheckbox defaultChecked /> </ThemeProvider>
3,460
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/ThemeNesting.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Checkbox from '@mui/material/Checkbox'; import { green, orange } from '@mui/material/colors'; const outerTheme = createTheme({ palette: { primary: { main: orange[500], }, }, }); const innerTheme = createTheme({ palette: { primary: { main: green[500], }, }, }); export default function ThemeNesting() { return ( <ThemeProvider theme={outerTheme}> <Checkbox defaultChecked /> <ThemeProvider theme={innerTheme}> <Checkbox defaultChecked /> </ThemeProvider> </ThemeProvider> ); }
3,461
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/ThemeNesting.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Checkbox from '@mui/material/Checkbox'; import { green, orange } from '@mui/material/colors'; const outerTheme = createTheme({ palette: { primary: { main: orange[500], }, }, }); const innerTheme = createTheme({ palette: { primary: { main: green[500], }, }, }); export default function ThemeNesting() { return ( <ThemeProvider theme={outerTheme}> <Checkbox defaultChecked /> <ThemeProvider theme={innerTheme}> <Checkbox defaultChecked /> </ThemeProvider> </ThemeProvider> ); }
3,462
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/ThemeNesting.tsx.preview
<ThemeProvider theme={outerTheme}> <Checkbox defaultChecked /> <ThemeProvider theme={innerTheme}> <Checkbox defaultChecked /> </ThemeProvider> </ThemeProvider>
3,463
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/ThemeNestingExtend.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Checkbox from '@mui/material/Checkbox'; import { green, orange } from '@mui/material/colors'; const outerTheme = createTheme({ palette: { secondary: { main: orange[500], }, }, }); export default function ThemeNestingExtend() { return ( <ThemeProvider theme={outerTheme}> <Checkbox defaultChecked color="secondary" /> <ThemeProvider theme={(theme) => createTheme({ ...theme, palette: { ...theme.palette, primary: { main: green[500], }, }, }) } > <Checkbox defaultChecked /> <Checkbox defaultChecked color="secondary" /> </ThemeProvider> </ThemeProvider> ); }
3,464
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/ThemeNestingExtend.tsx
import * as React from 'react'; import { createTheme, Theme, ThemeProvider } from '@mui/material/styles'; import Checkbox from '@mui/material/Checkbox'; import { green, orange } from '@mui/material/colors'; const outerTheme = createTheme({ palette: { secondary: { main: orange[500], }, }, }); export default function ThemeNestingExtend() { return ( <ThemeProvider theme={outerTheme}> <Checkbox defaultChecked color="secondary" /> <ThemeProvider theme={(theme: Theme) => createTheme({ ...theme, palette: { ...theme.palette, primary: { main: green[500], }, }, }) } > <Checkbox defaultChecked /> <Checkbox defaultChecked color="secondary" /> </ThemeProvider> </ThemeProvider> ); }
3,465
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/theming/theming.md
# Theming <p class="description">Customize Material UI with your theme. You can change the colors, the typography and much more.</p> The theme specifies the color of the components, darkness of the surfaces, level of shadow, appropriate opacity of ink elements, etc. Themes let you apply a consistent tone to your app. It allows you to **customize all design aspects** of your project in order to meet the specific needs of your business or brand. To promote greater consistency between apps, light and dark theme types are available to choose from. By default, components use the light theme type. ## Theme provider If you wish to customize the theme, you need to use the `ThemeProvider` component in order to inject a theme into your application. However, this is optional; Material UI components come with a default theme. `ThemeProvider` relies on the [context feature of React](https://react.dev/learn/passing-data-deeply-with-context) to pass the theme down to the components, so you need to make sure that `ThemeProvider` is a parent of the components you are trying to customize. You can learn more about this in [the API section](#themeprovider). ## Theme configuration variables Changing the theme configuration variables is the most effective way to match Material UI to your needs. The following sections cover the most important theme variables: - [`.palette`](/material-ui/customization/palette/) - [`.typography`](/material-ui/customization/typography/) - [`.spacing`](/material-ui/customization/spacing/) - [`.breakpoints`](/material-ui/customization/breakpoints/) - [`.zIndex`](/material-ui/customization/z-index/) - [`.transitions`](/material-ui/customization/transitions/) - [`.components`](/material-ui/customization/theme-components/) You can check out the [default theme section](/material-ui/customization/default-theme/) to view the default theme in full. ### Custom variables When using Material UI's theme with [MUI System](/system/getting-started/) or [any other styling solution](/material-ui/guides/interoperability/), it can be convenient to add additional variables to the theme so you can use them everywhere. For instance: ```jsx const theme = createTheme({ status: { danger: orange[500], }, }); ``` :::warning `vars` is a private field for [CSS theme variables](/material-ui/experimental-api/css-theme-variables/overview/). It will throw an error if you try to pass a value to it: ```jsx createTheme({ vars: { ... }, // ❌ error }) ``` ::: ### TypeScript You have to use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) to add new variables to the `Theme` and `ThemeOptions`. ```tsx declare module '@mui/material/styles' { interface Theme { status: { danger: string; }; } // allow configuration using `createTheme` interface ThemeOptions { status?: { danger?: string; }; } } ``` {{"demo": "CustomStyles.js"}} To add extra variables to the `theme.palette`, see [palette customization](/material-ui/customization/palette/). ## Theme builder <video autoPlay muted loop width="320"> <source src="/static/studies.mp4" type="video/mp4" > </video> The community has built great tools to build a theme: - [mui-theme-creator](https://zenoo.github.io/mui-theme-creator/): A tool to help design and customize themes for the Material UI component library. Includes basic site templates to show various components and how they are affected by the theme - [Material palette generator](https://m2.material.io/inline-tools/color/): The Material palette generator can be used to generate a palette for any color you input. ## Accessing the theme in a component You can access the theme variables inside your functional React components using the `useTheme` hook: ```jsx import { useTheme } from '@mui/material/styles'; function DeepChild() { const theme = useTheme(); return <span>{`spacing ${theme.spacing}`}</span>; } ``` ## Nesting the theme [You can nest](/system/styles/advanced/#theme-nesting) multiple theme providers. {{"demo": "ThemeNesting.js"}} The inner theme will **override** the outer theme. You can extend the outer theme by providing a function: {{"demo": "ThemeNestingExtend.js"}} ## API ### `createTheme(options, ...args) => theme` Generate a theme base on the options received. Then, pass it as a prop to [`ThemeProvider`](#themeprovider). #### Arguments 1. `options` (_object_): Takes an incomplete theme object and adds the missing parts. 2. `...args` (_object[]_): Deep merge the arguments with the about to be returned theme. :::warning Only the first argument (`options`) is processed by the `createTheme` function. If you want to actually merge two themes' options and create a new one based on them, you may want to deep merge the two options and provide them as a first argument to the `createTheme` function. ::: ```js import { deepmerge } from '@mui/utils'; import { createTheme } from '@mui/material/styles'; const theme = createTheme(deepmerge(options1, options2)); ``` #### Returns `theme` (_object_): A complete, ready-to-use theme object. #### Examples ```js import { createTheme } from '@mui/material/styles'; import { green, purple } from '@mui/material/colors'; const theme = createTheme({ palette: { primary: { main: purple[500], }, secondary: { main: green[500], }, }, }); ``` #### Theme composition: using theme options to define other options When the value for a theme option is dependent on another theme option, you should compose the theme in steps. ```js import { createTheme } from '@mui/material/styles'; let theme = createTheme({ palette: { primary: { main: '#0052cc', }, secondary: { main: '#edf2ff', }, }, }); theme = createTheme(theme, { palette: { info: { main: theme.palette.secondary.main, }, }, }); ``` Think of creating a theme as a two-step composition process: first, you define the basic design options; then, you'll use these design options to compose other options. **WARNING**: `theme.vars` is a private field used for CSS variables support. Please use another name for a custom object. ### `responsiveFontSizes(theme, options) => theme` Generate responsive typography settings based on the options received. #### Arguments 1. `theme` (_object_): The theme object to enhance. 2. `options` (_object_ [optional]): - `breakpoints` (_array\<string\>_ [optional]): Default to `['sm', 'md', 'lg']`. Array of [breakpoints](/material-ui/customization/breakpoints/) (identifiers). - `disableAlign` (_bool_ [optional]): Default to `false`. Whether font sizes change slightly so line heights are preserved and align to Material Design's 4px line height grid. This requires a unitless line height in the theme's styles. - `factor` (_number_ [optional]): Default to `2`. This value determines the strength of font size resizing. The higher the value, the less difference there is between font sizes on small screens. The lower the value, the bigger font sizes for small screens. The value must be greater than 1. - `variants` (_array\<string\>_ [optional]): Default to all. The typography variants to handle. #### Returns `theme` (_object_): The new theme with a responsive typography. #### Examples ```js import { createTheme, responsiveFontSizes } from '@mui/material/styles'; let theme = createTheme(); theme = responsiveFontSizes(theme); ``` ### `unstable_createMuiStrictModeTheme(options, ...args) => theme` **WARNING**: Do not use this method in production. Generates a theme that reduces the amount of warnings inside [`React.StrictMode`](https://react.dev/reference/react/StrictMode) like `Warning: findDOMNode is deprecated in StrictMode`. #### Requirements Currently `unstable_createMuiStrictModeTheme` adds no additional requirements. #### Arguments 1. `options` (_object_): Takes an incomplete theme object and adds the missing parts. 2. `...args` (_object[]_): Deep merge the arguments with the about to be returned theme. #### Returns `theme` (_object_): A complete, ready-to-use theme object. #### Examples ```js import { unstable_createMuiStrictModeTheme } from '@mui/material/styles'; const theme = unstable_createMuiStrictModeTheme(); function App() { return ( <React.StrictMode> <ThemeProvider theme={theme}> <LandingPage /> </ThemeProvider> </React.StrictMode> ); } ``` ### `ThemeProvider` This component takes a `theme` prop and applies it to the entire React tree that it is wrapping around. It should preferably be used at **the root of your component tree**. #### Props | Name | Type | Description | | :--------------- | :--------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children&nbsp;\* | node | Your component tree. | | theme&nbsp;\* | union:&nbsp;object&nbsp;&#124;&nbsp;func | A theme object, usually the result of [`createTheme()`](#createtheme-options-args-theme). The provided theme will be merged with the default theme. You can provide a function to extend the outer theme. | #### Examples ```jsx import * as React from 'react'; import { red } from '@mui/material/colors'; import { ThemeProvider, createTheme } from '@mui/material/styles'; const theme = createTheme({ palette: { primary: { main: red[500], }, }, }); function App() { return <ThemeProvider theme={theme}>...</ThemeProvider>; } ```
3,466
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/transitions/TransitionHover.js
import * as React from 'react'; import { styled, createTheme, ThemeProvider } from '@mui/material/styles'; import { deepPurple } from '@mui/material/colors'; import Avatar from '@mui/material/Avatar'; const customTheme = createTheme({ palette: { primary: { main: deepPurple[500], }, }, }); const StyledAvatar = styled(Avatar)` ${({ theme }) => ` cursor: pointer; background-color: ${theme.palette.primary.main}; transition: ${theme.transitions.create(['background-color', 'transform'], { duration: theme.transitions.duration.standard, })}; &:hover { background-color: ${theme.palette.secondary.main}; transform: scale(1.3); } `} `; export default function TransitionHover() { return ( <ThemeProvider theme={customTheme}> <StyledAvatar>OP</StyledAvatar> </ThemeProvider> ); }
3,467
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/transitions/TransitionHover.tsx
import * as React from 'react'; import { styled, createTheme, ThemeProvider } from '@mui/material/styles'; import { deepPurple } from '@mui/material/colors'; import Avatar from '@mui/material/Avatar'; const customTheme = createTheme({ palette: { primary: { main: deepPurple[500], }, }, }); const StyledAvatar = styled(Avatar)` ${({ theme }) => ` cursor: pointer; background-color: ${theme.palette.primary.main}; transition: ${theme.transitions.create(['background-color', 'transform'], { duration: theme.transitions.duration.standard, })}; &:hover { background-color: ${theme.palette.secondary.main}; transform: scale(1.3); } `} `; export default function TransitionHover() { return ( <ThemeProvider theme={customTheme}> <StyledAvatar>OP</StyledAvatar> </ThemeProvider> ); }
3,468
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/transitions/TransitionHover.tsx.preview
<ThemeProvider theme={customTheme}> <StyledAvatar>OP</StyledAvatar> </ThemeProvider>
3,469
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/transitions/transitions.md
# Transitions <p class="description">These theme helpers allow you to create custom CSS transitions, you can customize the durations, easings and more.</p> ## API ### `theme.transitions.create(props, options) => transition` #### Arguments 1. `props` (_string_ | _string[]_): Defaults to `['all']`. Provides a CSS property, or a list of CSS properties that should be transitioned. 2. `options` (_object_ [optional]): - `options.duration` (_string_ | _number_ [optional]): Defaults to `theme.transitions.duration.standard`. Provides the duration of the transition. - `options.easing` (_string_ [optional]): Defaults to `theme.transitions.easing.easeInOut`. Provides the easing for the transition. - `options.delay` (_string_ | _number_ [optional]): Defaults to `0`. Provides the delay for the transition. #### Returns `transition`: A CSS transition value, which composes all CSS properties that should be transitioned, together with the defined duration, easing and delay. Use the <code>theme.transitions.create()</code> helper to create consistent transitions for the elements of your UI.</p> ```js theme.transitions.create(['background-color', 'transform']); ``` #### Example {{"demo": "TransitionHover.js", "defaultCodeOpen": false}} ### `theme.transitions.getAutoHeightDuration(height) => duration` #### Arguments 1. `height` (_number_): The height of the component. #### Returns `duration`: The calculated duration based on the height. ## Durations You can change some or all of the duration values, or provide your own (for use in the `create()` helper). This example shows all the default values (in milliseconds), but you only need to provide the keys you wish to change or add. ```js const theme = createTheme({ transitions: { duration: { shortest: 150, shorter: 200, short: 250, // most basic recommended timing standard: 300, // this is to be used in complex animations complex: 375, // recommended when something is entering screen enteringScreen: 225, // recommended when something is leaving screen leavingScreen: 195, }, }, }); ``` ## Easings You can change some or all of the easing values, or provide your own, by providing a custom CSS <code>transition-timing-function</code> value. ```js const theme = createTheme({ transitions: { easing: { // This is the most common easing curve. easeInOut: 'cubic-bezier(0.4, 0, 0.2, 1)', // Objects enter the screen at full velocity from off-screen and // slowly decelerate to a resting point. easeOut: 'cubic-bezier(0.0, 0, 0.2, 1)', // Objects leave the screen at full velocity. They do not decelerate when off-screen. easeIn: 'cubic-bezier(0.4, 0, 1, 1)', // The sharp curve is used by objects that may return to the screen at any time. sharp: 'cubic-bezier(0.4, 0, 0.6, 1)', }, }, }); ``` ## References Check out the [Transitions](/material-ui/transitions/) page to explore the transition components that are included with Material UI.
3,470
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/CustomResponsiveFontSizes.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; const theme = createTheme(); theme.typography.h3 = { fontSize: '1.2rem', '@media (min-width:600px)': { fontSize: '1.5rem', }, [theme.breakpoints.up('md')]: { fontSize: '2rem', }, }; export default function CustomResponsiveFontSizes() { return ( <ThemeProvider theme={theme}> <Typography variant="h3">Responsive h3</Typography> </ThemeProvider> ); }
3,471
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/CustomResponsiveFontSizes.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; const theme = createTheme(); theme.typography.h3 = { fontSize: '1.2rem', '@media (min-width:600px)': { fontSize: '1.5rem', }, [theme.breakpoints.up('md')]: { fontSize: '2rem', }, }; export default function CustomResponsiveFontSizes() { return ( <ThemeProvider theme={theme}> <Typography variant="h3">Responsive h3</Typography> </ThemeProvider> ); }
3,472
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/CustomResponsiveFontSizes.tsx.preview
<ThemeProvider theme={theme}> <Typography variant="h3">Responsive h3</Typography> </ThemeProvider>
3,473
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/FontSizeTheme.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; const theme = createTheme({ typography: { // Tell MUI what the font-size on the html element is. htmlFontSize: 10, }, }); export default function FontSizeTheme() { return ( <ThemeProvider theme={theme}> <Typography>body1</Typography> </ThemeProvider> ); }
3,474
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/FontSizeTheme.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; const theme = createTheme({ typography: { // Tell MUI what the font-size on the html element is. htmlFontSize: 10, }, }); export default function FontSizeTheme() { return ( <ThemeProvider theme={theme}> <Typography>body1</Typography> </ThemeProvider> ); }
3,475
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/FontSizeTheme.tsx.preview
<ThemeProvider theme={theme}> <Typography>body1</Typography> </ThemeProvider>
3,476
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/ResponsiveFontSizes.js
import * as React from 'react'; import { createTheme, responsiveFontSizes, ThemeProvider, } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; let theme = createTheme(); theme = responsiveFontSizes(theme); export default function ResponsiveFontSizes() { return ( <div> <ThemeProvider theme={theme}> <Typography variant="h3">Responsive h3</Typography> <Typography variant="h4">Responsive h4</Typography> <Typography variant="h5">Responsive h5</Typography> </ThemeProvider> </div> ); }
3,477
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/ResponsiveFontSizes.tsx
import * as React from 'react'; import { createTheme, responsiveFontSizes, ThemeProvider, } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; let theme = createTheme(); theme = responsiveFontSizes(theme); export default function ResponsiveFontSizes() { return ( <div> <ThemeProvider theme={theme}> <Typography variant="h3">Responsive h3</Typography> <Typography variant="h4">Responsive h4</Typography> <Typography variant="h5">Responsive h5</Typography> </ThemeProvider> </div> ); }
3,478
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/ResponsiveFontSizes.tsx.preview
<ThemeProvider theme={theme}> <Typography variant="h3">Responsive h3</Typography> <Typography variant="h4">Responsive h4</Typography> <Typography variant="h5">Responsive h5</Typography> </ThemeProvider>
3,479
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/ResponsiveFontSizesChart.js
import * as React from 'react'; // import of a small, pure module in a private demo // bundle size and module duplication is negligible /* eslint-disable-next-line no-restricted-imports */ import { convertLength } from '@mui/material/styles/cssUtils'; import { createTheme, responsiveFontSizes } from '@mui/material/styles'; import Box from '@mui/material/Box'; import { Legend, Tooltip, LineChart, Line, XAxis, YAxis, Label, ResponsiveContainer, } from 'recharts'; let theme = createTheme(); theme = responsiveFontSizes(theme); const colors = [ '#443dc2', '#2060df', '#277e91', '#378153', '#4d811d', '#63780d', '#996600', ]; const variants = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'subtitle1']; export default function ResponsiveFontSizesChart() { const convert = convertLength(theme.typography.htmlFontSize); const toPx = (rem) => parseFloat(convert(rem, 'px')); const series = variants.map((variantName) => { const variant = theme.typography[variantName]; const data = []; data.push({ viewport: 0, fontSize: toPx(variant.fontSize), }); theme.breakpoints.keys.forEach((key) => { const viewport = theme.breakpoints.values[key]; const value = theme.breakpoints.up(key); if (variant[value]) { data.push({ viewport: viewport - 1, fontSize: data[data.length - 1].fontSize, }); data.push({ viewport, fontSize: toPx(variant[value].fontSize), }); } else if (key === 'xl') { data.push({ viewport, fontSize: data[data.length - 1].fontSize, }); } }); return { name: variantName, data, }; }); return ( <Box sx={{ height: 380, width: '100%', color: 'black' }}> <ResponsiveContainer> <LineChart margin={{ top: 50, right: 140, bottom: 0, left: 30, }} > <XAxis dataKey="viewport" type="number"> <Label position="right" offset={30}> viewport (px) </Label> </XAxis> <YAxis dataKey="fontSize" type="number"> <Label position="top" offset={20}> font-size (px) </Label> </YAxis> <Tooltip /> <Legend /> {series.map((serie, index) => ( <Line dataKey="fontSize" stroke={colors[index % colors.length]} data={serie.data} name={serie.name} key={serie.name} /> ))} </LineChart> </ResponsiveContainer> </Box> ); }
3,480
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/TypographyCustomVariant.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; const theme = createTheme({ typography: { poster: { fontSize: '4rem', color: 'indianred', }, // Disable v3 variant h3: undefined, }, components: { MuiTypography: { defaultProps: { variantMapping: { poster: 'h1', // map our new variant to render an <h1> by default }, }, }, }, }); export default function TypographyCustomVariant() { return ( <ThemeProvider theme={theme}> <Box sx={{ '& > *': { display: 'block' } }}> {/* @ts-ignore */} <Typography variant="poster">poster</Typography> <Typography variant="h3">h3</Typography> </Box> </ThemeProvider> ); }
3,481
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/TypographyCustomVariant.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; const theme = createTheme({ typography: { // @ts-ignore poster: { fontSize: '4rem', color: 'indianred', }, // Disable v3 variant h3: undefined, }, components: { MuiTypography: { defaultProps: { variantMapping: { // @ts-ignore poster: 'h1', // map our new variant to render an <h1> by default }, }, }, }, }); export default function TypographyCustomVariant() { return ( <ThemeProvider theme={theme}> <Box sx={{ '& > *': { display: 'block' } }}> {/* @ts-ignore */} <Typography variant="poster">poster</Typography> <Typography variant="h3">h3</Typography> </Box> </ThemeProvider> ); }
3,482
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/TypographyCustomVariant.tsx.preview
<ThemeProvider theme={theme}> <Box sx={{ '& > *': { display: 'block' } }}> {/* @ts-ignore */} <Typography variant="poster">poster</Typography> <Typography variant="h3">h3</Typography> </Box> </ThemeProvider>
3,483
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/TypographyVariants.js
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; const theme = createTheme({ typography: { subtitle1: { fontSize: 12, }, body1: { fontWeight: 500, }, button: { fontStyle: 'italic', }, }, }); export default function TypographyVariants() { return ( <div> <ThemeProvider theme={theme}> <Typography variant="subtitle1">subtitle</Typography> <Typography>body1</Typography> <Button>Button</Button> </ThemeProvider> </div> ); }
3,484
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/TypographyVariants.tsx
import * as React from 'react'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; const theme = createTheme({ typography: { subtitle1: { fontSize: 12, }, body1: { fontWeight: 500, }, button: { fontStyle: 'italic', }, }, }); export default function TypographyVariants() { return ( <div> <ThemeProvider theme={theme}> <Typography variant="subtitle1">subtitle</Typography> <Typography>body1</Typography> <Button>Button</Button> </ThemeProvider> </div> ); }
3,485
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/TypographyVariants.tsx.preview
<ThemeProvider theme={theme}> <Typography variant="subtitle1">subtitle</Typography> <Typography>body1</Typography> <Button>Button</Button> </ThemeProvider>
3,486
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/typography/typography.md
# Typography <p class="description">The theme provides a set of type sizes that work well together, and also with the layout grid.</p> ## Font family You can change the font family with the `theme.typography.fontFamily` property. For instance, this example uses the system font instead of the default Roboto font: ```js const theme = createTheme({ typography: { fontFamily: [ '-apple-system', 'BlinkMacSystemFont', '"Segoe UI"', 'Roboto', '"Helvetica Neue"', 'Arial', 'sans-serif', '"Apple Color Emoji"', '"Segoe UI Emoji"', '"Segoe UI Symbol"', ].join(','), }, }); ``` ### Self-hosted fonts To self-host fonts, download the font files in `ttf`, `woff`, and/or `woff2` formats and import them into your code. ⚠️ This requires that you have a plugin or loader in your build process that can handle loading `ttf`, `woff`, and `woff2` files. Fonts will _not_ be embedded within your bundle. They will be loaded from your webserver instead of a CDN. ```js import RalewayWoff2 from './fonts/Raleway-Regular.woff2'; ``` Next, you need to change the theme to use this new font. In order to globally define Raleway as a font face, the [`CssBaseline`](/material-ui/react-css-baseline/) component can be used (or any other CSS solution of your choice). ```jsx import RalewayWoff2 from './fonts/Raleway-Regular.woff2'; const theme = createTheme({ typography: { fontFamily: 'Raleway, Arial', }, components: { MuiCssBaseline: { styleOverrides: ` @font-face { font-family: 'Raleway'; font-style: normal; font-display: swap; font-weight: 400; src: local('Raleway'), local('Raleway-Regular'), url(${RalewayWoff2}) format('woff2'); unicodeRange: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF; } `, }, }, }); // ... return ( <ThemeProvider theme={theme}> <CssBaseline /> <Box sx={{ fontFamily: 'Raleway', }} > Raleway </Box> </ThemeProvider> ); ``` Note that if you want to add additional `@font-face` declarations, you need to use the string CSS template syntax for adding style overrides, so that the previously defined `@font-face` declarations won't be replaced. ## Font size Material UI uses `rem` units for the font size. The browser `<html>` element default font size is `16px`, but browsers have an option to change this value, so `rem` units allow us to accommodate the user's settings, resulting in a better accessibility support. Users change font size settings for all kinds of reasons, from poor eyesight to choosing optimum settings for devices that can be vastly different in size and viewing distance. To change the font-size of Material UI you can provide a `fontSize` property. The default value is `14px`. ```js const theme = createTheme({ typography: { // In Chinese and Japanese the characters are usually larger, // so a smaller fontsize may be appropriate. fontSize: 12, }, }); ``` The computed font size by the browser follows this mathematical equation: <div class="only-light-mode"> <img alt="font size calculation" style="width: 550px;" src="/static/images/font-size.svg" width="436" height="48" /> </div> <div class="only-dark-mode"> <img alt="font size calculation" style="width: 550px;" src="/static/images/font-size-dark.svg" width="436" height="48" /> </div> <!-- https://latex.codecogs.com/svg.latex?\dpi{200}&space;\text{computed}&space;=&space;\text{specification}\cdot\frac{\text{typography.fontSize}}{14}\cdot\frac{\text{html&space;fontsize}}{\text{typography.htmlFontSize}} --> ### Responsive font sizes The `theme.typography.*` [variant](#variants) properties map directly to the generated CSS. You can use [media queries](/material-ui/customization/breakpoints/#api) inside them: ```js const theme = createTheme(); theme.typography.h3 = { fontSize: '1.2rem', '@media (min-width:600px)': { fontSize: '1.5rem', }, [theme.breakpoints.up('md')]: { fontSize: '2.4rem', }, }; ``` {{"demo": "CustomResponsiveFontSizes.js"}} To automate this setup, you can use the [`responsiveFontSizes()`](/material-ui/customization/theming/#responsivefontsizes-theme-options-theme) helper to make Typography font sizes in the theme responsive. {{"demo": "ResponsiveFontSizesChart.js", "hideToolbar": true}} You can see this in action in the example below. Adjust your browser's window size, and notice how the font size changes as the width crosses the different [breakpoints](/material-ui/customization/breakpoints/): ```js import { createTheme, responsiveFontSizes } from '@mui/material/styles'; let theme = createTheme(); theme = responsiveFontSizes(theme); ``` {{"demo": "ResponsiveFontSizes.js"}} ### Fluid font sizes To be done: [#15251](https://github.com/mui/material-ui/issues/15251). ### HTML font size You might want to change the `<html>` element default font size. For instance, when using the [10px simplification](https://www.sitepoint.com/understanding-and-using-rem-units-in-css/). :::warning Changing the font size can harm accessibility ♿️. Most browsers agree on the default size of 16px, but the user can change it. For instance, someone with an impaired vision could set their browser's default font size to something larger. ::: The `theme.typography.htmlFontSize` property is provided for this use case, which tells Material UI what the font-size on the `<html>` element is. This is used to adjust the `rem` value so the calculated font-size always match the specification. ```js const theme = createTheme({ typography: { // Tell Material UI what the font-size on the html element is. htmlFontSize: 10, }, }); ``` ```css html { font-size: 62.5%; /* 62.5% of 16px = 10px */ } ``` _You need to apply the above CSS on the html element of this page to see the below demo rendered correctly_ {{"demo": "FontSizeTheme.js"}} ## Variants The typography object comes with [13 variants](/material-ui/react-typography/#component) by default: - h1 - h2 - h3 - h4 - h5 - h6 - subtitle1 - subtitle2 - body1 - body2 - button - caption - overline Each of these variants can be customized individually: ```js const theme = createTheme({ typography: { subtitle1: { fontSize: 12, }, body1: { fontWeight: 500, }, button: { fontStyle: 'italic', }, }, }); ``` {{"demo": "TypographyVariants.js"}} ## Adding & disabling variants In addition to using the default typography variants, you can add custom ones, or disable any you don't need. Here is what you need to do: **Step 1. Update the theme's typography object** The code snippet below adds a custom variant to the theme called `poster`, and removes the default `h3` variant: ```js const theme = createTheme({ typography: { poster: { fontSize: '4rem', color: 'red', }, // Disable h3 variant h3: undefined, }, }); ``` **Step 2. (Optional) Set the default semantic element for your new variant** At this point, you can already use the new `poster` variant, which will render a `<span>` by default with your custom styles. Sometimes you may want to default to a different HTML element for semantic purposes, or to replace the inline `<span>` with a block-level element for styling purposes. To do this, update the `variantMapping` prop of the `Typography` component globally, at the theme level: ```js const theme = createTheme({ typography: { poster: { fontSize: 64, color: 'red', }, // Disable h3 variant h3: undefined, }, components: { MuiTypography: { defaultProps: { variantMapping: { // Map the new variant to render a <h1> by default poster: 'h1', }, }, }, }, }); ``` **Step 3. Update the necessary typings (if you are using TypeScript)** :::info If you aren't using TypeScript you should skip this step. ::: You need to make sure that the typings for the theme's `typography` variants and the `Typography`'s `variant` prop reflects the new set of variants. <!-- Tested with packages/mui-material/test/typescript/augmentation/typographyVariants.spec.ts --> ```ts declare module '@mui/material/styles' { interface TypographyVariants { poster: React.CSSProperties; } // allow configuration using `createTheme` interface TypographyVariantsOptions { poster?: React.CSSProperties; } } // Update the Typography's variant prop options declare module '@mui/material/Typography' { interface TypographyPropsVariantOverrides { poster: true; h3: false; } } ``` **Step 4. You can now use the new variant** {{"demo": "TypographyCustomVariant.js", "hideToolbar": true}} ```jsx <Typography variant="poster">poster</Typography>; /* This variant is no longer supported. If you are using TypeScript it will give an error */ <Typography variant="h3">h3</Typography>; ``` ## Default values You can explore the default values of the typography using [the theme explorer](/material-ui/customization/default-theme/?expand-path=$.typography) or by opening the dev tools console on this page (`window.theme.typography`).
3,487
0
petrpan-code/mui/material-ui/docs/data/material/customization
petrpan-code/mui/material-ui/docs/data/material/customization/z-index/z-index.md
# z-index <p class="description">z-index is the CSS property that helps control layout by providing a third axis to arrange content.</p> Several Material UI components utilize `z-index`, employing a default z-index scale that has been designed to properly layer drawers, modals, snackbars, tooltips, and more. The `z-index` values start at an arbitrary number, high and specific enough to ideally avoid conflicts: - mobile stepper: 1000 - fab: 1050 - speed dial: 1050 - app bar: 1100 - drawer: 1200 - modal: 1300 - snackbar: 1400 - tooltip: 1500 These values can always be customized. You will find them in the theme under the [`zIndex`](/material-ui/customization/default-theme/?expand-path=$.zIndex) key of the theme. Customization of individual values is discouraged; should you change one, you likely need to change them all.
3,488
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/backers/backers.md
# Sponsors and Backers <p class="description">Support the development of the open-source projects of the MUI organization through crowdfunding.</p> Material UI, Joy UI, and Base UI, are crowd-funded open-source projects, licensed under the permissive MIT license. Sponsorship increases the rate of bug fixes, documentation improvements, and feature development. ## Diamond sponsors <p style="display: flex; justify-content: start; align-items: center; flex-wrap: wrap;"> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="octopus.com" href="https://octopus.com/?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 16px;"><img height="128" width="128" src="https://i.ibb.co/w0HF0Nz/Logo-Blue-140px-rgb.png" srcset="https://i.ibb.co/w0HF0Nz/Logo-Blue-140px-rgb.png 2x" alt="octopus" title="Repeatable, reliable deployments" loading="lazy" /></a> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="doit.com" href="https://www.doit.com/flexsave/?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 24px;"><img height="128" width="128" src="https://avatars.githubusercontent.com/u/8424863?s=128" srcset="https://avatars.githubusercontent.com/u/8424863?s=256 2x" alt="doit" title="Management Platform for Google Cloud and AWS" loading="lazy" /></a> </p> _1/3 slots available_ Diamond sponsors are those who've pledged \$1,500/month or more to MUI. [Tier benefits](#diamond). ## Gold sponsors via [Open Collective](https://opencollective.com/mui-org) or via [the for-profit](https://www.patreon.com/oliviertassinari) <p style="display: flex; justify-content: start; align-items: center; flex-wrap: wrap;"> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="tidelift.com" href="https://tidelift.com/subscription/pkg/npm-material-ui?utm_source=npm-material-ui&utm_medium=referral&utm_campaign=homepage" rel="noopener sponsored" target="_blank" style="margin-right: 16px;"><img height="96" width="96" src="https://avatars.githubusercontent.com/u/30204434?s=96" srcset="https://avatars.githubusercontent.com/u/30204434?s=192 2x" alt="tidelift.com" title="Enterprise-ready open-source software" loading="lazy" /></a> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="text-em-all.com" href="https://www.text-em-all.com/?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 16px;"><img src="https://avatars.githubusercontent.com/u/1262264?s=96" srcset="https://avatars.githubusercontent.com/u/1262264?s=192 2x" alt="text-em-all.com" title="Mass Text Messaging & Automated Calling" height="96" width="96" loading="lazy"></a> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="spotify.com" href="https://open.spotify.com?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 16px;"><img height="96" width="96" src="https://images.opencollective.com/spotify/f37ea28/logo/96.png" srcset="https://images.opencollective.com/spotify/f37ea28/logo/192.png 2x" alt="Spotify" title="Music service to access to millions of songs" loading="lazy"></a> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="megafamous.com" href="https://megafamous.com/?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 16px;"><img height="96" width="96" src="/static/sponsors/megafamous.png" alt="megafamous.com" title="The best place to buy Instagram followers & likes" loading="lazy" /></a> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="dialmycalls.com" href="https://www.dialmycalls.com/?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 16px;"><img height="96" width="96" src="https://images.opencollective.com/dialmycalls/f5ae9ab/avatar/96.png" srcset="https://images.opencollective.com/dialmycalls/f5ae9ab/avatar/192.png 2x" alt="dialmycalls.com" title="Send text messages, calls & emails to thousands with ease." loading="lazy" /></a> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="goread.io" href="https://goread.io/?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 16px; display:flex;"><img height="110" width="96" src="https://images.opencollective.com/goread_io/eb6337d/logo/96.png" srcset="https://images.opencollective.com/goread_io/eb6337d/logo/192.png 2x" alt="goread.io" title="Instagram followers, likes, power likes, views, comments, saves in minutes." loading="lazy" /></a> <a data-ga-event-category="sponsor" data-ga-event-action="docs-backers" data-ga-event-label="icons8.com" href="https://icons8.com?utm_source=MUI&utm_medium=referral&utm_content=backers" rel="noopener sponsored" target="_blank" style="margin-right: 16px;"><img height="96" width="96" src="https://images.opencollective.com/icons8/7fa1641/logo/96.png" srcset="https://images.opencollective.com/icons8/7fa1641/logo/192.png 2x" alt="Icons8" title="We provide the neat icons, photos, illustrations, and music. Developers, use our API to insert all the content we have into your apps." loading="lazy"></a> </p> Gold sponsors are those who've pledged \$500/month or more to MUI. [Tier benefits](#gold). ## Silver sponsors via [Open Collective](https://opencollective.com/mui-org) <p style="overflow: auto;"> <object type="image/svg+xml" data="https://opencollective.com/mui-org/tiers/silver-sponsor.svg?avatarHeight=70&width=600" style="border-radius: 10px;">Silver Sponsors</object> </p> Silvers sponsors are those who've pledged $250/month to $500/month to MUI. [Tier benefits](#silver). ## Bronze sponsors via [Open Collective](https://opencollective.com/mui-org) <p style="overflow: auto;"> <object type="image/svg+xml" data="https://opencollective.com/mui-org/tiers/bronze-sponsor.svg?avatarHeight=60&width=600" style="border-radius: 10px;">Bronze Sponsors</object> </p> Bronze sponsors are those who've pledged $100/month to $250/month to MUI. [Tier benefits](#sliver). ## Backers via [Open Collective](https://opencollective.com/mui-org) <p style="overflow: auto;"> <object type="image/svg+xml" data="https://opencollective.com/mui-org/tiers/backer.svg?avatarHeight=50&width=600" style="border-radius: 10px;">Backers</object> </p> ## FAQ ### Why is Material UI a "crowd-funded open-source project"? Material UI (as well as [Base UI](/base-ui/) and [Joy UI](/joy-ui/getting-started/)) is open-source to give users great freedom in how they use the software, and to enable the community to have influence over how the project progresses to make it appropriate for a wide range of use-cases. To ensure that MUI's component libraries can stand the test of time for our users, they need to be well directed and financially sustainable. The absolute best way to support MUI's libraries ongoing development efforts is to become a sponsor. Crowd-sourced funding enables us to spend the most time directly working on improving MUI's products, which you and other MUI users then benefit from. ### How is sponsorship money spent? Sponsorship money is used to fund open-source software development, testing, documentation, and releases of the projects. ### Is sponsorship required to use MUI's products? Users are not obligated to give back to MUI, but it is in their interest to do so. By significantly reducing the amount of work needed to achieve business goals and reducing running costs, MUI's libraries result in huge time and money savings for users. We encourage organizations to contribute a portion of these savings back, enabling the project to advance more rapidly and result in even greater savings for your organization. ### What's the difference between Open Collective and the for-profit? Funds donated via Open Collective are managed transparently and aimed to sustain the MIT projects. MUI benefits from the Open Collective's fiscal sponsorship (hosted as a non-profit), in exchange for 10% of the donations. Funds transferred to the MUI for-profit support the company's mission. ## Services These great services sponsor MUI's core infrastructure: <span class="only-light-mode"> <img src="/static/readme/github-lightmode.svg" alt="GitHub logo" loading="lazy" width="300" height="107" style="width:80px;"> </span> <span class="only-dark-mode"> <img src="/static/readme/github-darkmode.svg" alt="GitHub logo" loading="lazy" width="300" height="107" style="width:80px;"> </span> [GitHub](https://github.com/) lets us host the Git repository and coordinate contributions. <span class="only-light-mode"> <img src="/static/readme/netlify-lightmode.svg" alt="Netlify logo" loading="lazy" width="180" height="49" style="width: 100px; margin-top: 1rem;"> </span> <span class="only-dark-mode"> <img src="/static/readme/netlify-darkmode.svg" alt="Netlify logo" loading="lazy" width="180" height="49" style="width: 100px; margin-top: 1rem;"> </span> [Netlify](https://www.netlify.com/) lets us distribute the documentation. <span class="only-light-mode"> <img src="/static/readme/browserstack-lightmode.svg" alt="BrowserStack logo" loading="lazy" width="180" height="32" style="width: 140px; margin-top: 1rem;"> </span> <span class="only-dark-mode"> <img src="/static/readme/browserstack-darkmode.svg" alt="BrowserStack logo" loading="lazy" width="180" height="32" style="width: 140px; margin-top: 1rem;"> </span> [BrowserStack](https://www.browserstack.com/) lets us test in real browsers. <img loading="lazy" alt="CodeCov logo" src="https://avatars.githubusercontent.com/u/8226205?s=70" width="70" height="70" style="width: 35px; margin-top: 1rem;"> [CodeCov](https://about.codecov.io/) lets us monitor test coverage. ## Tier benefits ### Diamond Your organization logo will be prominently featured: - on the sidebar of all content pages (4m+ sessions, 900k+ unique visitors/month) - the [homepage](https://mui.com/#sponsors) (500k+ pageviews and 150k+ unique visitors/month) - the [README.md](https://github.com/mui/material-ui#sponsors) (80k+ unique visitors/month) - the [Diamond sponsor list](#diamond-sponsors) Please contact us at [email protected] before subscribing to this tier to get preliminary approval. ### Gold Your organization logo will be placed in: - the [homepage](https://mui.com/#sponsors) (500k+ pageviews and 150k+ unique visitors/month) - the [README.md](https://github.com/mui/material-ui#sponsors) (80k+ unique visitors/month) - the [Gold sponsor list](#gold-sponsors) \*we accept donations, but we won't show unethical ads. ### Silver Your organization logo will be placed in the [Silver sponsor list](#silver-sponsors). ### Bronze Your organization logo will be placed in the [Bronze sponsor list](#bronze-sponsors). ### Backers Help support more open-source development by becoming a Backer. We'll thank you by including your avatar in the [backers list](#backers).
3,489
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/changelog/changelog.md
# Changelog <p class="description">MUI follows Semantic Versioning 2.0.0.</p> All notable changes of the current major version are described in the [CHANGELOG.md file](https://github.com/mui/material-ui/blob/HEAD/CHANGELOG.md). Changes of older versions are described in the [CHANGELOG.old.md file](https://github.com/mui/material-ui/blob/HEAD/CHANGELOG.old.md)
3,490
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/design-kits/design-kits.md
# Design kits <p class="description">Boost consistency and facilitate communication when working with developers by using Material UI components in your favorite design tool.</p> The Material UI design kits allow you to be more efficient by designing and developing with the same library. - **For designers:** Save time getting the Material UI components all set up, leveraging the latest features from your favorite design tool. - **For product managers:** Quickly put together ideas and high-fidelity mockups/prototypes using components from your actual product. - **For developers:** Effortlessly communicate with designers using the same language around the Material UI component props and variants. Find them in your design tool of choice: <a href="https://mui.com/store/items/figma-react/?utm_source=docs&utm_medium=referral&utm_campaign=installation-figma" style="margin-left: 8px; margin-top: 8px; display: inline-block;"><img src="/static/images/download-figma.svg" alt="figma" /></a> <a href="https://mui.com/store/items/adobe-xd-react/?utm_source=docs&utm_medium=referral&utm_campaign=installation-adobe-xd" style="margin-left: 32px; margin-top: 8px; display: inline-block;"><img src="/static/images/download-adobe-xd.svg" alt="adobe-xd" /></a> <a href="https://mui.com/store/items/sketch-react/?utm_source=docs&utm_medium=referral&utm_campaign=installation-sketch" style="margin-left: 32px; margin-top: 8px; display: inline-block;"><img src="/static/images/download-sketch.svg" alt="sketch" /></a>
3,491
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/related-projects/related-projects.md
# Related projects <p class="description">A carefully curated list of third-party tools that expand or build on top of Material UI's component library.</p> Developers from the community have built some excellent supplemental tools for working with Material UI—this page gathers the best that we've seen. Do you have a project that you think should be featured here? We'd love to see it. Feel free to submit a pull request! ## Design resources - [UXPin](https://www.uxpin.com/merge/mui-library): A large UI kit of Material UI components. It renders the components in a web runtime and uses the same React implementation as your production environment. ## IDE tools - [eslint: detect unused classes](https://github.com/jens-ox/eslint-plugin-material-ui-unused-classes): ESLint plugin to detect unused styling classes with `@mui/styles`. ## Theming - [material-ui-theme-editor](https://in-your-saas.github.io/material-ui-theme-editor/): A tool to generate themes for your Material UI applications that features live previewing. - [Material palette generator](https://m2.material.io/inline-tools/color/): The official Material Design palette generator can be used to generate a palette for any color you choose. ## Components ### Layout - [@mui-treasury/layout](https://mui-treasury.com/layout/): Components to handle the overall layout of a page. Check out examples such as [a reactjs.org clone](https://mui-treasury.com/layout/clones/reactjs/). ### Image - [mui-image](https://github.com/benmneb/mui-image): The only Material UI image component to satisfy the Material Design guidelines for loading images. - [material-ui-image](https://mui.wertarbyte.com/#material-ui-image): Adds a "materializing" effect to images so they fade in like [Material Design's image loading pattern](https://m1.material.io/patterns/loading-images.html) suggests. ### Chips - [mui-chips-input](https://github.com/viclafouch/mui-chips-input): A chips input designed for use with Material UI. ### Phone Number - [mui-tel-input](https://github.com/viclafouch/mui-tel-input): A phone number input designed for use with Material UI, built with [libphonenumber-js](https://www.npmjs.com/package/libphonenumber-js). ### One-Time Password - [mui-otp-input](https://github.com/viclafouch/mui-otp-input): A One-Time Password input designed for use with Material UI. ### File - [mui-file-input](https://github.com/viclafouch/mui-file-input): A file input designed for use with Material UI. ### Color picker - [mui-color-input](https://github.com/viclafouch/mui-color-input): A color input designed for use with Material UI, built with [TinyColor](https://tinycolor.vercel.app/). - [material-ui-color](https://github.com/mikbry/material-ui-color): Collections of color components for Material UI. No dependencies, small, highly customizable, and supports theming. ### Sparkline - [mui-plus](https://mui-plus.vercel.app/components/Sparkline): A sparkline is a tiny chart that can be used to indicate the trend of a value. ## Admin frameworks - [React Admin](https://github.com/marmelab/react-admin): A frontend Framework for building data-driven applications running in the browser on top of REST/GraphQL APIs. - [refine](https://github.com/refinedev/refine): An open source, headless React-based framework for the rapid development of web applications.
3,492
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/roadmap/roadmap.md
# Roadmap <p class="description">The roadmap is a living document, the priorities will likely change, but the list below should give some indication of our plans for the next releases.</p> ## Methodology MUI is community-driven—issues that resonate most with the community get the most attention. Please **upvote** (👍) on GitHub the issues you are most interested in. Thank you for participating [in the developer survey](/blog/2021-developer-survey-results/). ## Quarterly roadmap Our GitHub project's roadmap is where you can learn about what features we're working on, what stage they're at, and when we expect to bring them to you: - [MUI Core](https://github.com/orgs/mui/projects/18/views/1). This repository focuses on empowering the creation of great design systems with React, as well as providing two ready to use themes (Material Design so far, another one coming in the near future). - [MUI X](https://github.com/mui/mui-x/projects/1). This repository focuses on providing advanced React components. Some of the features are MIT licensed, others are available under a commercial license. - [MUI Design kits](https://github.com/mui/mui-design-kits/projects/1) This repository focuses on providing the components for designers on Figma and other design tools. It's a great place to leave feedback, feature requests, and ask questions. ## Priorities Here are the top priorities: - **More components**. 🧰 We have to strictly prioritize as developing a fully-fledged component takes a considerable amount of time. We apply the following strategy: - Identify frequently needed components. There are many resources we leverage for this: the developer survey answers, GitHub issue upvotes, Algolia search volume, Google search volume, documentation usage, npm downloads, etc. - Prioritize the creation of frequently needed components. - Encourage the usage of third-party components if they already exist and are well maintained. - **Design.** 🎀 We are relatively up-to-date, but the Material Design guidelines [are evolving](https://material.io/blog/). So should we. We also plan to implement [a second design](https://github.com/mui/material-ui/issues/22485). - **Better customization.** 💅 We want to make component customization intuitive, no matter if you are using global CSS or styled-components: - **Better documentation.** 📚 No solution is complete without great documentation. - **Performance.** 🚀 React abstraction has a cost. The more components you render, the slower your page will be. You will notice stark differences when rendering a large table or list. - **Bundle size.** 📦 You can follow our progress [with bundlephobia.com report](https://bundlephobia.com/package/@mui/material). Please pay special attention to the cost of the individual modules under "Exports Analysis". - **TypeScript.** 📏 We are continuously improving the definitions. The codebase is mostly written in JavaScript with manually authored `.d.ts` definitions. While we do not plan a migration effort as a standalone effort, new modules are written in TypeScript. - **Accessibility.** ♿️ We have relatively [few accessibility issues](https://darekkay.com/blog/accessible-ui-frameworks/), but we are eager to address them all. We would appreciate the help of accessibility experts. ## New components Here are the components we will work on being supported in the MUI ecosystem: - ✅ Released as stable - 🧪 Not too far from becoming stable, already released as unstable - 🛠 Work in progress, will be or already released as unstable - ⏳ Planning to build | Name | Product | Status | | :------------------------------------------------------------- | :------- | :----- | | Advanced Layout | MUI X | ⏳ | | Carousel | MUI X | ⏳ | | [Charts](https://mui.com/x/react-charts/) | MUI X | 🧪 | | [Data Grid](/x/react-data-grid/) | MUI X | ✅ | | [Date Picker](/x/react-date-pickers/date-picker/) | MUI X | ✅ | | [Time Picker](/x/react-date-pickers/time-picker/) | MUI X | ✅ | | [Date Time Picker](/x/react-date-pickers/date-time-picker/) | MUI X | ✅ | | [Date Range Picker](/x/react-date-pickers/date-range-picker/) | MUI X | ✅ | | Time Range Picker | MUI X | ⏳ | | Date Time Range Picker | MUI X | ⏳ | | Dropdown | MUI Core | ⏳ | | Dropzone | MUI X | ⏳ | | File Upload | MUI X | ⏳ | | Gantt Chart | MUI X | ⏳ | | Gauge | MUI X | ⏳ | | Image | MUI Core | ⏳ | | [Masonry](/material-ui/react-masonry/) | MUI Core | 🧪 | | Navbar | MUI Core | ⏳ | | Nested Menu | MUI X | ⏳ | | NProgress | MUI Core | ⏳ | | Numeric Input | MUI Core | ⏳ | | Rich Text Editor | MUI X | ⏳ | | Scheduler | MUI X | ⏳ | | Scrollspy | MUI Core | ⏳ | | Sparkline | MUI X | ⏳ | | [Timeline](/material-ui/react-timeline/) | MUI Core | 🧪 | | Tree select | MUI X | ⏳ | | [Tree View](/x/react-tree-view/) | MUI X | 🧪 | | Tree View - Checkbox | MUI X | ⏳ | | Tree View - Drag & Drop | MUI X | ⏳ | | [Tree View - Multiselect](/x/react-tree-view/#multi-selection) | MUI X | 🧪 | | Tree View - Virtualization | MUI X | ⏳ | | Window Splitter | MUI X | ⏳ | :::warning **Disclaimer**: We operate in a dynamic environment, and things are subject to change. The information provided is intended to outline the general framework direction, for informational purposes only. We may decide to add or remove new items at any time, depending on our capability to deliver while meeting our quality standards. The development, releases, and timing of any features or functionality remains at the sole discretion of MUI. The roadmap does not represent a commitment, obligation, or promise to deliver at any time. :::
3,493
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/showcase/appList.js
/** * The app structure: * * { * title: string; * description: string; * image?: string; * link: string; * source?: string; * similarWebVisits?: number; * dateAdded: string; // ISO 8601 format: YYYY-MM-DD * } */ const appList = [ { title: 'd-cide', description: 'A progressive Web App to make rational decisions in workshops. ' + 'It uses MUI with a neumorphic custom theme.', image: 'dcide.jpg', link: 'https://d-cide.me/', source: 'https://github.com/cjoecker/d-cide', dateAdded: '2020-07-01', }, { title: 'QuintoAndar', description: 'QuintoAndar is a company that uses technology and ' + 'design to simplify the rental of residential real estate.', image: 'quintoandar.jpg', link: 'https://www.quintoandar.com.br/', similarWebVisits: 8500, dateAdded: '2019-05-08', }, { title: 'Bethesda.net', description: 'The official site for Bethesda, publisher of Fallout, DOOM, Dishonored, ' + 'Skyrim, Wolfenstein, The Elder Scrolls, more. Your source for news, features & community.', image: 'bethesda.jpg', link: 'https://bethesda.net/', similarWebVisits: 4000, dateAdded: '2019-01-01', }, { title: 'OpenClassrooms', description: 'OpenClassrooms is an online platform offering top quality, ' + 'education-to-employment programs and career coaching services for students worldwide. ', image: 'openclassrooms.png', link: 'https://openclassrooms.com/en/', similarWebVisits: 6000, dateAdded: '2018-01-34', }, { title: 'Codementor', description: 'Codementor is the largest community for developer mentorship and an on-demand marketplace ' + 'for software developers. Get instant coding help, build projects faster, ' + 'and read programming tutorials from our community of developers.', image: 'codementor.jpg', link: 'https://www.codementor.io/', similarWebVisits: 1500, dateAdded: '2018-01-34', }, { title: 'BARKS', description: 'Japan Music Network. 🇯🇵', image: 'barks.jpg', link: 'https://www.barks.jp/', similarWebVisits: 3000, dateAdded: '2019-01-01', }, { title: 'GovX', description: 'Current & former uniformed professionals get exclusive access to deals ' + 'on gear, apparel, tickets, travel and more.', image: 'govx.jpg', link: 'https://www.govx.com/', similarWebVisits: 2000, dateAdded: '2018-01-31', }, { title: 'Hijup', description: 'A pioneering Muslim Fashion e-commerce site.', image: 'hijup.jpg', link: 'https://www.hijup.com/', similarWebVisits: 328, dateAdded: '2018-01-18', }, { title: 'iFit', description: 'Get the best personal training, right at home. Access hundreds of training programs, ' + 'unique health tips, and expert advice that will lead you to a healthier lifestyle.', image: 'ifit.jpg', link: 'https://www.ifit.com/', similarWebVisits: 304, dateAdded: '2019-01-01', }, { title: 'EQ3', description: 'Modern Furniture & Accessories, designed in Canada, for everyday living.', image: 'eq3.jpg', link: 'https://www.eq3.com/ca/en', similarWebVisits: 256, dateAdded: '2018-01-34', }, { title: 'Housecall Pro', description: 'The #1 rated mobile software to run your home service business. ' + 'Schedule, dispatch, GPS track employees, invoice, accept credit cards and get booked ' + 'online. The marketing website is also built with MUI: https://www.housecallpro.com/', image: 'housecall.jpg', link: 'https://pro.housecallpro.com/pro/log_in', similarWebVisits: 1800, dateAdded: '2019-01-01', }, { title: 'VMware CloudHealth', description: 'The most trusted cloud management platform that enables users to analyze and manage cloud ' + 'cost, usage and performance in one place. ' + '(Used for the business application, but not the marketing website.)', image: 'cloudhealth.jpg', link: 'https://cloudhealth.vmware.com/', similarWebVisits: 132, dateAdded: '2018-01-37', }, { title: 'CityAds', description: 'CityAds Media: global technology platform for online performance marketing ' + 'powered by big data', image: 'cityads.jpg', link: 'https://cityads.com/main', similarWebVisits: 132, dateAdded: '2019-01-01', }, { title: 'EOS Toolkit', description: 'EOSToolkit is the premier free, open source interface for managing EOS ' + 'accounts. Create, transfer, stake, vote and more with Scatter!', image: 'eostoolkit.jpg', link: 'https://eostoolkit.io/', source: 'https://github.com/eostoolkit/eostoolkit', stars: 91, dateAdded: '2019-01-01', }, { title: 'The Media Ant', description: "India's Largest online marketing service provider, " + 'with more than 200K advertising options, and more than 1M satisfied customers.', image: 'themediaant.jpg', link: 'https://www.themediaant.com/', similarWebVisits: 90, dateAdded: '2019-01-01', }, { title: 'Forex Bank', description: 'Vi kan tilby kjapp og enkel valutaveksling, pengeoverføringer, samt kjøp av norsk veksel. ' + '🇳🇴', image: 'forex.jpg', link: 'https://www.forex.no/', similarWebVisits: 95, dateAdded: '2018-01-34', }, { title: 'LocalMonero', description: 'A safe and easy-to-use person-to-person platform to allow anyone ' + 'to trade their local currency for Monero, anywhere.', image: 'localmonero.jpg', link: 'https://localmonero.co/?rc=ogps', dateAdded: '2018-01-04', }, { title: 'LessWrong', description: 'LessWrong is a community blog devoted to the art of human rationality.', image: 'lesswrong.jpg', link: 'https://www.lesswrong.com/', similarWebVisits: 1000, dateAdded: '2018-01-38', }, { title: 'ODIGEO Connect', description: "Connect your hotel, B&B and apartment with Europe's #1 flight OTA " + 'and distribute it to millions of travellers.', image: 'odigeo.jpg', link: 'https://www.odigeoconnect.com/', dateAdded: '2019-01-01', }, { title: 'comet', description: 'Comet lets you track code, experiments, and results on ML projects. ' + "It's fast, simple, and free for open source projects.", image: 'comet.jpg', link: 'https://www.comet.com/', similarWebVisits: 180, dateAdded: '2019-01-01', }, { title: 'Pointer', description: 'Revestimentos cerâmicos para pisos e paredes com qualidade e design acessível. ' + 'A Pointer faz parte da Portobello e atua no Nordeste do Brasil. 🇧🇷', image: 'pointer.jpg', link: 'https://www.pointer.com.br/', dateAdded: '2019-01-01', }, { title: 'Oneplanetcrowd', description: "Oneplanetcrowd is Europe's leading sustainable crowdfunding platform for People & Planet.", image: 'oneplanetcrowd.jpg', link: 'https://www.oneplanetcrowd.com/en', dateAdded: '2019-01-01', }, { title: 'CollegeAI', description: 'Get a college recommendation and your chances using the best college predictor. ' + "Answer some questions and we'll calculate where you fit in best with our college finder " + 'and college matching tools. CollegeAI is an admissions and college counselor, college ' + 'planner, and college chance calculator.', image: 'collegeai.jpg', link: 'https://collegeai.com', dateAdded: '2019-01-01', }, { title: 'react-admin', description: 'The admin of an imaginary poster shop, used as a demo for the react-admin framework. ' + 'Uses many material-ui components, including tables, forms, snackbars, buttons, and ' + 'theming. The UI is responsive. The code is open-source!', image: 'posters-galore.jpg', link: 'https://marmelab.com/react-admin-demo/', source: 'https://github.com/marmelab/react-admin', dateAdded: '2018-01-21', stars: 18500, }, { title: 'Builder Book', description: 'Books to learn how to build full-stack, production-ready JavaScript web applications from scratch. ' + 'Learn React, MUI, Next, Express, Mongoose, MongoDB, third party APIs, and more.', image: 'builderbook.jpg', link: 'https://builderbook.org/', source: 'https://github.com/async-labs/builderbook', stars: 3000, dateAdded: '2018-01-05', }, { title: 'Commit Swimming', description: 'The #1 workout journal for coaches and swimmers.', image: 'commitswimming.jpg', link: 'https://commitswimming.com/', dateAdded: '2019-01-01', }, { title: 'EventHi', description: 'Cannabis event platform to create and coordinate Cannabis events for the Cannabis ' + 'community. Use our easy ticketing system, sponsor, and sell merchandise.', image: 'eventhi.jpg', link: 'https://eventhi.io/', dateAdded: '2019-01-01', }, { title: 'Iceberg Finder', description: 'Whether spotting them from outer space, or standing on our coastline, ' + 'IcebergFinder.com is your premier place for finding bergs in Newfoundland and Labrador.', image: 'icebergfinder.jpg', link: 'https://icebergfinder.com/', dateAdded: '2019-01-01', }, { title: 'MetaFact', description: "Metafact is a place to verify knowledge via the world's top experts. " + "It's a platform to ask questions, learn the facts and share the truth.", image: 'metafact.jpg', link: 'https://metafact.io/', dateAdded: '2019-01-01', }, { title: 'AudioNodes', description: 'Modular audio production suite with multi-track audio mixing, audio effects, ' + 'parameter automation, MIDI editing, synthesis, cloud production, and more.', image: 'audionodes.jpg', link: 'https://www.audionodes.com/', dateAdded: '2018-01-07', }, { title: 'SlidesUp', description: 'SlidesUp is a platform to help conference organizers plan their events.', image: 'slidesup.jpg', link: 'https://slidesup.com/', dateAdded: '2018-01-03', }, { title: 'Typekev', description: 'The personal site of Kevin Gonzalez, featuring his witty chatbot.', image: 'typekev.jpg', link: 'https://typekev.com/', source: 'https://github.com/typekev/typekev-site', stars: 10, dateAdded: '2018-01-23', }, { title: 'npm registry browser', description: 'An open source web app that lets you search the npm registry ' + 'and browse packages details.', image: 'npm-registry-browser.jpg', link: 'https://topheman.github.io/npm-registry-browser/', source: 'https://github.com/topheman/npm-registry-browser', stars: 90, dateAdded: '2018-01-15', }, { title: 'Snippets Chrome Extension', description: 'An open source Chrome extension allowing you to import and execute JavaScript code ' + 'snippets from GitHub.', image: 'snippets.jpg', link: 'https://chrome.google.com/webstore/detail/snippets/dcibnkkafifbanoclgjbkmkbogijndin', source: 'https://github.com/richardscarrott/snippets', stars: 42, dateAdded: '2018-01-19', }, { title: 'Tree', description: 'An open source top 100 documentaries (personal opinion) app ' + 'with React Hooks and MUI.', link: 'https://tree.valleyease.me/', image: 'tree.jpg', source: 'https://github.com/ValleyZw/tree', stars: 24, dateAdded: '2018-01-35', }, { title: 'TagSpaces', description: 'TagSpaces is an offline, open source, file manager.' + 'It helps organizing your files and folders with tags and colors.', image: 'tagspaces.jpg', link: 'https://www.tagspaces.org/demo/', source: 'https://github.com/tagspaces/tagspaces', stars: 2500, dateAdded: '2019-11-01', }, { title: 'HiFiveWork', description: 'HiFiveWork, the cool tool for leave management', image: 'hifivework.png', link: 'https://hifivework.com/', dateAdded: '2020-01-08', }, { title: 'FANSPO', description: 'NBA trade machine and social analysis tools for the basketball community.', image: 'tradenba.jpg', link: 'https://fanspo.com/', similarWebVisits: 417, dateAdded: '2020-01-20', }, { title: 'Backstage', description: 'Backstage is an open platform by Spotify for building developer portals.', image: 'backstage.jpg', link: 'https://backstage.io', source: 'https://github.com/backstage/backstage', stars: 14300, dateAdded: '2020-08-31', }, { title: 'buybags', description: 'buybags is a fashion shopping aggregator in Germany.', image: 'buybags.jpg', link: 'https://www.buybags.de/', dateAdded: '2020-10-08', }, { title: 'react-admin CRM demo', description: 'A full-featured Customer Relationship Management app', image: 'atomiccrm.jpg', link: 'https://marmelab.com/react-admin-crm/', source: 'https://github.com/marmelab/react-admin/tree/master/examples/crm', stars: 18500, dateAdded: '2021-05-06', }, { title: 'Saleor Store Dashboard', description: 'Dashboard application for Saleor headless e-commerce platform', image: 'saleor.jpg', link: 'https://demo.saleor.io/dashboard/', source: 'https://github.com/saleor/saleor-dashboard', stars: 15079, similarWebVisits: 62, dateAdded: '2022-02-05', }, { title: 'MQTT Explorer', description: 'A comprehensive MQTT Client which visualizes broker traffic in a hierarchical view. ' + 'The protocol is used in many IoT and home automation scenarios, ' + 'making integrating new services dead easy.', link: 'https://mqtt-explorer.com/', source: 'https://github.com/thomasnordquist/MQTT-Explorer', image: 'mqtt-explorer.png', stars: 1600, dateAdded: '2019-03-25', }, { title: 'refine FineFoods demo', description: 'A full-featured Admin panel app', image: 'refine-finefoods.png', link: 'https://example.mui.admin.refine.dev/', source: 'https://github.com/refinedev/refine/tree/next/examples/finefoods-material-ui', stars: 10646, dateAdded: '2022-06-21', }, ]; export default appList;
3,494
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/showcase/showcase.md
# Showcase <p class="description">Check out these public apps using Material UI to get inspired for your next project.</p> This is a curated list of some of the best apps we've seen that show off what's possible with Material UI. Are you also using it? [Show us what you're building](https://github.com/mui/material-ui/issues/22426)! We'd love to see it. --- {{"component": "modules/components/MaterialShowcase.js"}}
3,495
0
petrpan-code/mui/material-ui/docs/data/material/discover-more
petrpan-code/mui/material-ui/docs/data/material/discover-more/vision/vision.md
# Vision <p class="description">Our vision is to provide an elegant React implementation of the Material Design guidelines that can be customized to fully match your brand.</p> The Material Design guidelines are an incredible starting point, but they do not provide guidance on all aspects or needs of an application. In addition to the guidelines-specific implementation, we want Material UI to become whatever is generally useful for application development, all in the spirit of the Material Design guidelines. Therefore, Material UI will be not only be an implementation of the Material Design guidelines, but a general use UI library of components that are needed by many. This generalized use doesn't imply any other design methodology. It also means we will have components or combinations that are simply not addressed in the design guidelines. We will focus on providing all the low-level tools needed to build a rich user-interface with React. Once we implement the Material Design guidelines (which is a bar set quite high), you should be able to take advantage of it for your own business with any style customization needed. We want to see companies succeeding using Material UI in a way that matches their brand, close to the material philosophy or not. We don't want them to feel that their UI simply looks like another Google product. From a developer's point of view, we want Material UI to: - Deliver on fully encapsulated / composable React components. - Be themeable / customizable. - Be cross browser compatible and accessible. - Promote developer joy, a sense of community, and an environment where new and experienced developers can learn from each other.
3,496
0
petrpan-code/mui/material-ui/docs/data/material/experimental-api
petrpan-code/mui/material-ui/docs/data/material/experimental-api/classname-generator/classname-generator.md
# ClassName generator <p class="description">Configure classname generation at build time.</p> This API is introduced in `@mui/material` (v5.0.5) as a replacement of deprecated [`createGenerateClassName`](/system/styles/api/#creategenerateclassname-options-class-name-generator). :::warning This API is at an unstable stage and is subject to change in the future. ::: ## Setup By default, Material UI generates a global class name for each component slot. For example, `<Button>Text</Button>` generates html as: ```html <button class="MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium MuiButtonBase-root css-1ujsas3" > Text </button> ``` To customize all the class names generated by Material UI components, create a separate JavaScript file to use the `ClassNameGenerator` API. ```js // create a new file called `MuiClassNameSetup.js` at the root or src folder. import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className'; ClassNameGenerator.configure( // Do something with the componentName (componentName) => componentName, ); ``` and then import the file at the root of the index before any `@mui/*` imports. ```js import './MuiClassNameSetup'; import Button from '@mui/material/Button'; // ...other component imports function App() { return <Button>Text</Button>; } ``` Here are some configuration examples: ### Change class name prefix ```js // MuiClassNameSetup.js import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className'; ClassNameGenerator.configure((componentName) => `foo-bar-${componentName}`); ``` As a result, the HTML result changes to the following: ```html <button class="foo-bar-MuiButton-root foo-bar-MuiButton-text foo-bar-MuiButton-textPrimary foo-bar-MuiButton-sizeMedium foo-bar-MuiButton-textSizeMedium foo-bar-MuiButtonBase-root css-1ujsas3" > Button </button> ``` ### Rename component class name Every Material UI component has `${componentName}-${slot}` classname format. For example, the component name of [`Chip`](/material-ui/react-chip/) is `MuiChip`, which is used as a global class name for every `<Chip />` element. You can remove/change the `Mui` prefix as follows: ```js // MuiClassNameSetup.js import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className'; ClassNameGenerator.configure((componentName) => componentName.replace('Mui', '')); ``` Now, the `Mui` class is gone. ```html <div class="Chip-root Chip-filled Chip-sizeMedium Chip-colorDefault Chip-filledDefault css-mttbc0" > Chip </div> ``` :::warning [State classes](/material-ui/customization/how-to-customize/#state-classes) are not component names and therefore cannot be changed or removed. ::: ## Caveat - `ClassNameGenerator.configure` must be called before any Material UI components import. - you should always use `[component]Classes` for theming/customization to get the correct generated class name. ```diff +import { outlinedInputClasses } from '@mui/material/OutlinedInput'; const theme = createTheme({ components: { MuiOutlinedInput: { styleOverrides: { root: { - '& .MuiOutlinedInput-notchedOutline': { + // the result will contain the prefix. + [`& .${outlinedInputClasses.notchedOutline}`]: { borderWidth: 1, } } } } } }); ``` - This API should only be used at build-time. - The configuration is applied to all of the components across the application. You cannot target a specific part of the application. ## Framework examples Always create an initializer file to hoist the `ClassNameGenerator` call to the top. ```js // create a new file called `MuiClassNameSetup.js` at the root or src folder. import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className'; ClassNameGenerator.configure( // Do something with the componentName (componentName) => componentName, ); ``` Then import the file in the main JavaScript source based on the framework. ### Next.js Pages Router Import the initializer in `/pages/_app.js`. ```diff +import './MuiClassNameSetup'; import * as React from 'react'; import PropTypes from 'prop-types'; import Head from 'next/head'; export default function MyApp(props) { const { Component, pageProps } = props; return ( <Component {...pageProps} /> ); } ``` ### Create React App Import the initializer in `/src/index.js`. ```diff +import './MuiClassNameSetup'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import App from './App'; ReactDOM.render(<App />); ```
3,497
0
petrpan-code/mui/material-ui/docs/data/material/experimental-api
petrpan-code/mui/material-ui/docs/data/material/experimental-api/css-theme-variables/customization.md
# CSS theme variables - Customization <p class="description">A guide for customizing CSS theme variables in Material UI.</p> ## Theming `experimental_extendTheme` is an API that extends the default theme. It returns a theme that can only be used by the `Experimental_CssVarsProvider`. ```js import { Experimental_CssVarsProvider as CssVarsProvider, experimental_extendTheme as extendTheme, } from '@mui/material/styles'; const theme = extendTheme(); // ...custom theme function App() { return <CssVarsProvider theme={theme}>...</CssVarsProvider>; } ``` :::warning `extendTheme` is not the same as [`createTheme`](/material-ui/customization/theming/#createtheme-options-args-theme). Do not use them interchangeably. - `createTheme()` returns a theme for `ThemeProvider`. - `extendTheme()` returns a theme for `CssVarsProvider`. ::: ### Color schemes The major difference from the default approach is in palette customization. With the `extendTheme` API, you can specify the palette for all color schemes at once (`light` and `dark` are built in) under the `colorSchemes` node. Here's an example of how to customize the `primary` palette: ```js import { pink } from '@mui/material/colors'; const theme = extendTheme({ colorSchemes: { light: { palette: { primary: { main: pink[600], }, }, }, dark: { palette: { primary: { main: pink[400], }, }, }, }, }); ``` ### Components [Component customization](/material-ui/customization/theme-components/) remains the same as the default approach. We recommend using the value from `theme.vars.*` whenever possible for a better debugging experience: ```js const theme = extendTheme({ components: { MuiChip: { styleOverrides: { root: ({ theme, ownerState }) => ({ ...(ownerState.variant === 'outlined' && ownerState.color === 'primary' && { // this is the same as writing: // backgroundColor: 'var(--mui-palette-background-paper)', backgroundColor: theme.vars.palette.background.paper, }), }), }, }, }, }); ``` ### Channel tokens A channel token is a variable that consists of [color space channels](https://www.w3.org/TR/css-color-4/#color-syntax) but without the alpha component. The value of a channel token is separated by a space, e.g. `12 223 31`, which can be combined with the [color functions](https://www.w3.org/TR/css-color-4/#color-functions) to create a translucent color. The `extendTheme()` automatically generates channel tokens that are likely to be used frequently from the theme palette. Those colors are suffixed with `Channel`, for example: ```js const theme = extendTheme(); const light = theme.colorSchemes.light; console.log(light.palette.primary.mainChannel); // '25 118 210' // This token is generated from `theme.colorSchemes.light.palette.primary.main`. ``` You can use the channel tokens to create a translucent color like this: ```js const theme = extendTheme({ components: { MuiChip: { styleOverrides: { root: ({ theme, ownerState }) => ({ ...(ownerState.variant === 'outlined' && ownerState.color === 'primary' && { backgroundColor: `rgba(${theme.vars.palette.primary.mainChannel} / 0.12)`, }), }), }, }, }, }); ``` :::warning Don't use a comma (`,`) as a separator because the channel colors use empty spaces to define [transparency](https://www.w3.org/TR/css-color-4/#transparency): ```js `rgba(${theme.vars.palette.primary.mainChannel}, 0.12)`, // 🚫 this does not work `rgba(${theme.vars.palette.primary.mainChannel} / 0.12)`, // ✅ always use `/` ``` ::: ## Adding new theme tokens You can add other key-value pairs to the theme input which will be generated as a part of the CSS theme variables: ```js const theme = extendTheme({ colorSchemes: { light: { palette: { // The best part is that you can refer to the variables wherever you like 🤩 gradient: 'linear-gradient(to left, var(--mui-palette-primary-main), var(--mui-palette-primary-dark))', border: { subtle: 'var(--mui-palette-neutral-200)', }, }, }, dark: { palette: { gradient: 'linear-gradient(to left, var(--mui-palette-primary-light), var(--mui-palette-primary-main))', border: { subtle: 'var(--mui-palette-neutral-600)', }, }, }, }, }); function App() { return <CssVarsProvider theme={theme}>...</CssVarsProvider>; } ``` Then, you can access those variables from the `theme.vars` object: ```js const Divider = styled('hr')(({ theme }) => ({ height: 1, border: '1px solid', borderColor: theme.vars.palette.border.subtile, backgroundColor: theme.vars.palette.gradient, })); ``` Or use `var()` to refer to the CSS variable directly: ```css /* global.css */ .external-section { background-color: var(--mui-palette-gradient); } ``` :::warning If you're using a [custom prefix](/material-ui/experimental-api/css-theme-variables/customization/#changing-variable-prefixes), make sure to replace the default `--mui`. ::: ### TypeScript You must augment the theme palette to avoid type errors: ```ts declare module '@mui/material/styles' { interface PaletteOptions { gradient: string; border: { subtle: string; }; } interface Palette { gradient: string; border: { subtle: string; }; } } ``` ## Changing variable prefixes To change the default variable prefix (`--mui`), provide a string to `cssVarPrefix` property, as shown below: ```js const theme = extendTheme({ cssVarPrefix: 'any' }); // the stylesheet will be like this: // --any-palette-primary-main: ...; ``` To remove the prefix, use an empty string as a value: ```js const theme = extendTheme({ cssVarPrefix: '' }); // the stylesheet will be like this: // --palette-primary-main: ...; ``` ## Custom styles per mode To customize the style without creating new tokens, you can use the `theme.getColorSchemeSelector` utility: ```js const Button = styled('button')(({ theme }) => ({ // in default mode. backgroundColor: theme.vars.palette.primary.main, color: '#fff', '&:hover': { backgroundColor: theme.vars.palette.primary.dark, }, // in dark mode. [theme.getColorSchemeSelector('dark')]: { backgroundColor: theme.vars.palette.primary.dark, color: theme.vars.palette.primary.main, '&:hover': { color: '#fff', backgroundColor: theme.vars.palette.primary.dark, }, }, })); ``` :::info Using this utility is equivalent to writing a plain string `'[data-mui-color-scheme="dark"] &'` if you don't have a custom configuration. ::: ## Force a specific color scheme Specify `data-mui-color-scheme="dark"` to any DOM node to force the children components to appear as if they are in dark mode. ```js <div data-mui-color-scheme="dark"> <Paper sx={{ p: 2 }}> <TextField label="Email" type="email" margin="normal" /> <TextField label="Password" type="password" margin="normal" /> <Button>Sign in</Button> </Paper> </div> ``` ## Dark color scheme application For an application that only has a dark mode, set the default mode to `dark`: ```js const theme = extendTheme({ // ... }); // remove the `light` color scheme to optimize the HTML size for server-side application delete theme.colorSchemes.light; function App() { return ( <CssVarsProvider theme={theme} defaultMode="dark"> ... </CssVarsProvider> ); } ``` For a server-side application, provide the same value to [`getInitColorSchemeScript()`](/material-ui/experimental-api/css-theme-variables/usage/#server-side-rendering): ```js getInitColorSchemeScript({ defaultMode: 'dark', }); ``` :::warning In development, make sure to clear local storage and refresh the page after you configure the `defaultMode`. :::
3,498
0
petrpan-code/mui/material-ui/docs/data/material/experimental-api
petrpan-code/mui/material-ui/docs/data/material/experimental-api/css-theme-variables/migration.md
# Migrating to CSS theme variables <p class="description">A step-by-step migration guide to start using CSS theme variables in your project.</p> This is a guide that shows how to migrate an existing Material UI project to CSS theme variables. This migration offers a solution to a longstanding issue in which a user who prefers dark mode will see a flash of light mode when the page first loads. ## 1. Add the new provider ### Without a custom theme If you aren't using [`ThemeProvider`](/material-ui/customization/theming/#theme-provider), then all you need to do is wrap your application with the `CssVarsProvider`: ```js import { Experimental_CssVarsProvider as CssVarsProvider } from '@mui/material/styles'; function App() { return <CssVarsProvider>...your existing application</CssVarsProvider>; } ``` You should see the generated CSS theme variables in the stylesheet. Material UI components that render inside the new provider will automatically consume the variables. ### Custom theme If you have a custom theme, you must replace `createTheme()` with the `extendTheme()` API. This moves palette customization to within the `colorSchemes` node. Other properties can be copied and pasted. ```diff -import { createTheme } from '@mui/material/styles'; +import { experimental_extendTheme as extendTheme} from '@mui/material/styles'; -const lightTheme = createTheme({ - palette: { - primary: { - main: '#ff5252', - }, - ... - }, - // ...other properties, e.g. breakpoints, spacing, shape, typography, components -}); -const darkTheme = createTheme({ - palette: { - mode: 'dark', - primary: { - main: '#000', - }, - ... - }, -}); +const theme = extendTheme({ + colorSchemes: { + light: { + palette: { + primary: { + main: '#ff5252', + }, + ... + }, + }, + dark: { + palette: { + primary: { + main: '#000', + }, + ... + }, + }, + }, + // ...other properties +}); ``` Then, replace the `ThemeProvider` with the `CssVarsProvider`: ```diff -import { ThemeProvider } from '@mui/material/styles'; +import { Experimental_CssVarsProvider as CssVarsProvider } from '@mui/material/styles'; const theme = extendTheme(...); function App() { - return <ThemeProvider theme={theme}>...</ThemeProvider> + return <CssVarsProvider theme={theme}>...</CssVarsProvider> } ``` Save the file and start the development server. Your application should be able to run without crashing. :::info If you encounter any errors, please [open an issue](https://github.com/mui/material-ui/issues/new?assignees=&labels=status%3A+needs+triage&template=1.bug.yml) to share it with us. We'd love to help. ::: If you inspect the page, you will see the generated CSS variables in the stylesheet. Material UI components that render inside the new provider will automatically use the CSS theme variables. ## 2. Remove the toggle mode logic You can remove your existing logic that handles the user-selected mode and replace it with the `useColorScheme` hook. **Before**: ```jsx // This is only a minimal example to demonstrate the migration. function App() { const [mode, setMode] = React.useState(() => { if (typeof window !== 'undefined') { return localStorage.getItem('mode') ?? 'light'; } return 'light'; }); // a new theme is created every time the mode changes const theme = createTheme({ palette: { mode, }, // ...your custom theme }); return ( <ThemeProvider theme={theme}> <Button onClick={() => { const newMode = mode === 'light' ? 'dark' : 'light'; setMode(newMode); localStorage.setItem('mode', newMode); }} > {mode === 'light' ? 'Turn dark' : 'Turn light'} </Button> ... </ThemeProvider> ); } ``` **After**: ```js import { Experimental_CssVarsProvider as CssVarsProvider, experimental_extendTheme as extendTheme, useColorScheme, } from '@mui/material/styles'; function ModeToggle() { const { mode, setMode } = useColorScheme(); return ( <Button onClick={() => { setMode(mode === 'light' ? 'dark' : 'light'); }} > {mode === 'light' ? 'Turn dark' : 'Turn light'} </Button> ); } const theme = extendTheme({ // ...your custom theme }); function App() { return ( <CssVarsProvider theme={theme}> <ModeToggle /> ... </CssVarsProvider> ); } ``` The `useColorScheme` hook provides the user-selected `mode` and a function `setMode` to update the value. The `mode` is stored inside `CssVarsProvider` which handles local storage synchronization for you. ## 3. Prevent dark-mode flickering in server-side applications The `getInitColorSchemeScript()` API prevents dark-mode flickering by returning a script that must be run before React. ### Next.js Pages Router Place the script before `<Main />` in your [`pages/_document.js`](https://nextjs.org/docs/pages/building-your-application/routing/custom-document): ```jsx import Document, { Html, Head, Main, NextScript } from 'next/document'; import { getInitColorSchemeScript } from '@mui/material/styles'; export default class MyDocument extends Document { render() { return ( <Html data-color-scheme="light"> <Head>...</Head> <body> {getInitColorSchemeScript()} <Main /> <NextScript /> </body> </Html> ); } } ``` ### Gatsby Place the script in your [`gatsby-ssr.js`](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/) file: ```jsx import * as React from 'react'; import { getInitColorSchemeScript } from '@mui/material/styles'; export function onRenderBody({ setPreBodyComponents }) { setPreBodyComponents([getInitColorSchemeScript()]); } ``` ## 4. Refactor custom styles to use the attribute selector Users will continue to encounter dark-mode flickering if your custom styles include conditional expressions, as shown below: ```js // theming example extendTheme({ components: { MuiChip: { styleOverrides: { root: ({ theme }) => ({ backgroundColor: theme.palette.mode === 'dark' ? 'rgba(255 255 255 / 0.2)' : 'rgba(0 0 0 / 0.2)', }), }, }, }, }); // or a custom component example const Button = styled('button')(({ theme }) => ({ backgroundColor: theme.palette.mode === 'dark' ? 'rgba(255 255 255 / 0.2)' : 'rgba(0 0 0 / 0.2)', })); ``` This is because the `theme.palette.mode` is always `light` on the server. To fix this problem, replace conditional expressions with the attribute selector instead: ```js // theming example extendTheme({ components: { MuiChip: { styleOverrides: { root: ({ theme }) => ({ backgroundColor: 'rgba(0 0 0 / 0.2)', [theme.getColorSchemeSelector('dark')]: { backgroundColor: 'rgba(255 255 255 / 0.2)', }, }), }, }, }, }); // or a custom component example const Button = styled('button')(({ theme }) => ({ backgroundColor: 'rgba(0 0 0 / 0.2)', [theme.getColorSchemeSelector('dark')]: { backgroundColor: 'rgba(255 255 255 / 0.2)', }, })); ``` :::warning The `theme.getColorSchemeSelector()` is a utility function that returns an attribute selector `'[data-mui-color-scheme="dark"] &'`. Note that the attribute selector creates higher CSS specificity which could be cumbersome for theming. ::: ## 5. Test dark-mode flickering 1. Toggle dark mode in your application 2. Open DevTools and set the [CPU throttling](https://developer.chrome.com/docs/devtools/performance/#simulate_a_mobile_cpu) to the lowest value (don't close the DevTools). 3. Refresh the page. You should see the all components in dark mode at first glance.
3,499