🎭Theme/Style Configuration
Defines core of theme. How theme is being set using Material-UI.
Last updated
Defines core of theme. How theme is being set using Material-UI.
Last updated
Customize Able Pro with your theme. You can change the colors, the typography, and much more. Material-UI provides flexibility to change the style of the project in a single place and on top of it, we made it more centralized and consistent with the proper file structure.
The whole theme can be configured from the folder src\themes
. Theme initialization starts in index.jsx
, where the palette, typography, and component's overridable style exist.
import { ReactNode, useMemo } from 'react';
// material-ui
import { createTheme, ThemeOptions, ThemeProvider, Theme, TypographyVariantsOptions, StyledEngineProvider } from '@mui/material/styles';
You can check other settings like theme typography, palette, and components style override in the same folder. src\themes
You might come across questions like how to change a theme's primary color. How to change the textbox or other components which can apply to an entire theme?
To change the color of the theme, you can apply color directly to src\theme\palatte.js
For instance, if you want to change color where theme.palette.primary.light
is being used in a theme then, update the following in src\themes\palatte.js
You can customize the typography used in the theme as well from the central place.
For instance, If you want to change font-weight
the typography h5
to 900
. To do that, open src\themes\typography.js
and update as below:
This will apply to all places where you used Typography variants as h5
<Typography variant="h5"...>
We have provided a central location to override any default style of any component. All the overrides styles exist in src\themes\overrides
You can add a default property for any MUI component and it will be applied everywhere. We emitted lines to view it better in the above code block but you can see many controls' styles overridden in the same file. Feel free to change it as per your need.
// material-ui
import { alpha, createTheme } from '@mui/material/styles';
import { PaletteMode } from '@mui/material';
// project-imports
import ThemeOption from './theme';
import { ThemeMode } from 'config';
// types
import { PresetColor } from 'types/config';
import { PaletteThemeProps } from 'types/theme';
// ==============================|| DEFAULT THEME - PALETTE ||============================== //
export default function Palette(mode: ThemeMode, presetColor: PresetColor, themeContrast: boolean) {
const paletteColor: PaletteThemeProps = ThemeOption(presetColor, mode);
return createTheme({
palette: {
mode: mode as PaletteMode,
common: {
black: '#000',
white: '#fff'
},
...paletteColor,
text: {
primary: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker!, 0.87) : paletteColor.secondary[800],
secondary: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker!, 0.45) : paletteColor.secondary.main,
disabled: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker!, 0.1) : paletteColor.secondary[400]
},
action: {
disabled: paletteColor.secondary.light
},
divider: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker!, 0.05) : alpha(paletteColor.secondary.light!, 0.65),
background: {
paper: mode === ThemeMode.DARK ? paletteColor.secondary[100] : '#fff',
default: themeContrast && mode !== ThemeMode.DARK ? '#fff' : paletteColor.secondary.lighter
}
}
});
}
// material-ui
import { alpha, createTheme } from '@mui/material/styles';
// project-imports
import ThemeOption from './theme';
import { ThemeMode } from 'config';
// ==============================|| DEFAULT THEME - PALETTE ||============================== //
export default function Palette(mode, presetColor, themeContrast) {
const paletteColor = ThemeOption(presetColor, mode);
return createTheme({
palette: {
mode: mode,
common: {
black: '#000',
white: '#fff'
},
...paletteColor,
text: {
primary: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker, 0.87) : paletteColor.secondary[800],
secondary: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker, 0.45) : paletteColor.secondary.main,
disabled: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker, 0.1) : paletteColor.secondary[400]
},
action: {
disabled: paletteColor.secondary.light
},
divider: mode === ThemeMode.DARK ? alpha(paletteColor.secondary.darker, 0.05) : alpha(paletteColor.secondary.light, 0.65),
background: {
paper: mode === ThemeMode.DARK ? paletteColor.secondary[100] : '#fff',
default: themeContrast && mode !== ThemeMode.DARK ? '#fff' : paletteColor.secondary.lighter
}
}
});
}
// material-ui
import { TypographyVariantsOptions } from '@mui/material/styles';
// types
import { FontFamily } from 'types/config';
// ==============================|| DEFAULT THEME - TYPOGRAPHY ||============================== //
export default function Typography(fontFamily: FontFamily): TypographyVariantsOptions {
return {
....
h5: {
fontWeight: 600,
fontSize: '1rem',
lineHeight: 1.5
},
...
}
}
// ==============================|| DEFAULT THEME - TYPOGRAPHY ||============================== //
export default function Typography(fontFamily){
return {
....
h5: {
fontWeight: 600,
fontSize: '1rem',
lineHeight: 1.5
},
...
}
}
// material-ui
import { Theme } from '@mui/material/styles';
// ==============================|| OVERRIDES - ACCORDION ||============================== //
export default function Accordion(theme: Theme) {
return {
MuiAccordion: {
defaultProps: {
disableGutters: true,
square: true,
elevation: 0
},
styleOverrides: {
root: {
border: '1px solid',
borderColor: theme.palette.divider,
'&:not(:last-child)': {
borderBottom: 0
},
'&:before': {
display: 'none'
},
'&.Mui-disabled': {
backgroundColor: theme.palette.secondary.lighter
}
}
}
}
};
}
// ==============================|| OVERRIDES - ACCORDION ||============================== //
export default function Accordion(theme) {
return {
MuiAccordion: {
defaultProps: {
disableGutters: true,
square: true,
elevation: 0
},
styleOverrides: {
root: {
border: '1px solid',
borderColor: theme.palette.divider,
'&:not(:last-child)': {
borderBottom: 0
},
'&:before': {
display: 'none'
},
'&.Mui-disabled': {
backgroundColor: theme.palette.secondary.lighter
}
}
}
}
};
}