Skip to content

technobuddha/postcss-mui-theme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postcss-mui-theme

PostCSS plugin that transforms MUI theme into CSS values.

This plugin processes CSS declarations and replaces custom function calls with their corresponding values from the MUI theme:

  • mui-theme(): Resolves theme paths (e.g., mui-theme(palette-primary-main) becomes the primary color)
  • mui-spacing(): Converts spacing values (e.g., mui-spacing(2) becomes the theme's spacing calculation)
  • contrastText(): Gets the contrast text color for a given background color

Example

import { createTheme } from '@mui/material/styles';
import postcss from 'postcss';
import muiThemePlugin from 'postcss-mui-theme';

const theme = createTheme();
const result = await postcss([muiThemePlugin({ theme })]).process(css);

Sample CSS Input and Output

// Input CSS
.button {
  background-color: mui-theme(palette-primary-main);
  padding: mui-spacing(2);
  color: contrastText(#ff0000);
}
// Output CSS
.button {
  background-color: #1976d2;
  padding: 16px;
  color: #fff;
}

About

Access the material-ui theme from postcss

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors