npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

css-to-mui-loader

v2.0.2

Published

Webpack loader for using external CSS files with Material UI

Downloads

156

Readme

css-to-mui-loader

NPM version

Webpack loader for using external CSS files with Material UI.

Install | Usage | Description | Features | Demo | Linting | Help out

Install

npm install css-to-mui-loader

Dependency version support:

material-ui
jss

Usage

styles.css

.button {
  background: $(theme.palette.primary.main);
  padding: 2su; /* Material UI spacing units */
}

.button:hover {
  background: $(theme.palette.primary.light);
}

MyComponent.js

import Button from '@material-ui/core/Button';
import { withStyles } from '@material-ui/core/styles';
import styles from './styles.css';

const MyComponent = withStyles(styles)(({ classes }) => (
  <Button className={classes.button}>
    Click Me
  </Button>
));

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [ 'css-to-mui-loader' ]
      }
    ]
  }
}

Description

The css-to-mui-loader allows you to write external CSS files then import them for use in your Material UI components. It provides shortcuts for accessing the Material UI theme within the CSS itself.

Why?

  1. CSS is more concise
  2. Designers don't want to write JS
  3. You can copy/paste CSS directly from Chrome Inspector
  4. You still get component-scoped CSS and a centralized theme

Features

Provides custom unit for Material UI spacing

.spacing {
  padding: 10su; /* Equal to theme.spacing.unit * 10 */
}

Provides access to the Material UI theme

.theme {
  color: $(theme.palette.primary.main);
  z-index: $(theme.zIndex.appBar);
}

Supports media queries using the Material UI theme breakpoints

@media $(theme.breakpoints.down('sm')) {
  .media {
    display: none;
  }
}

Allows Material UI theme objects to be included as mixins

.mixins {
  -mui-mixins: theme.typography.display4, theme.shape;
}

Supports classes, child selectors and pseudo-classes

.parent.qualifier .child:hover * {
  padding: 10px;
}

Supports CSS variables

:root {
  --small-spacing: 2su;
}

.variables {
  margin: var(--small-spacing);
}

Supports keyframes

@keyframes my-animation {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.keyframes {
  animation: my-animation 1s ease-in-out;
}

If you want to know what the loader output looks like, take a look at the tests.

Demo

Check out the css-to-mui-loader-example repository for a bare-bones demo bootstrapped with create-react-app.

Linting

Some linters might complain about the custom syntax, but there are usually rules you can enable to address this. For example, the following .stylelintrc for stylelint does not raise any errors with the custom css-to-mui-loader syntax:

{
  "extends": "stylelint-config-standard",
  "plugins": [
    "stylelint-order"
  ],
  "rules": {
    "function-name-case": null,
    "property-no-unknown": [
      true,
      {
        "ignoreProperties": ["-mui-mixins"]
      }
    ],
    "unit-no-unknown": [
      true,
      {
        "ignoreUnits": ["/^su$/"]
      }
    ]
  }
}

Help out

Pull requests, issues, complaints and suggestions are all welcome.