0.3.0 • Published 6 years ago

stylos v0.3.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

What is it?

Inspired by bootstrap's utility classes, stylos is a Webpack plugin that automatically generates and injects CSS utilities into your application. All you have to do is specify utility classes on DOM elements; webpack will identify and generate the properties with relevant values and inject them to your application.

npm.io

As you can see, all you have to do is specify the classes having shorthand for the CSS property key, required value and optionally the unit. Stylos will understand it and generate the CSS for you.

Features

  • Supports HTML as well as JSX
  • Works well in vanilla JavaScript apps as well as frameworks e.g. Angular, React or Vue.js
  • Plays nicely with webpack-dev-server / webpack serve
  • Integrates with html-webpack-plugin
  • Helps you make those little UI changes without any accidental broken UI

Supported Shorthands

Here is the the list of known shorthand formulas that you can use in your DOM classes.

ShorthandCSS PropertyExample Usage
ppaddingp10 will translate to padding: 10px
ptpadding-toppt20 will translate to padding-top: 20px;
pbpadding-bottompb10 will translate to padding-bottom: 10px;
prpadding-rightpr20 will translate to padding-right: 20px;
plpadding-leftpl23 will translate to padding-left: 23px;
mmarginm20 will translate to margin: 20px
mtmargin-topmt20 will translate to margin-top: 20px;
mbmargin-bottommb20 will translate to margin-bottom: 20px;
mlmargin-leftml50 will translate to margin-left: 50px;
mrmargin-rightmr30 will translate to margin-right: 30px;
wwidthw200 will translate to width: 200px
hheighth60 will translate to height: 60px;
brborder-radiusbr5 will translate to border-radius: 5px;
fsfont-sizefs15 will translate to font-size: 15px
fwfont-weightfw400 will translate to font-weight: 400px
lhline-heightlh20em will translate to line-height: 20em
ttopt6 will translate to top: 6px;
lleftl30 will translate to left: 30px
bbottomb20em will translate to bottom: 20em;
rrightr20em will translate to right: 20em;

For the units, you can specify them after the value and relevant CSS unit will be used

  • Units including px, pt, em, p, vh, vw, vmin, ex, cm, in, mm, pc will translate to the same unit in CSS
  • If you don't provide any unit px will be used
  • If you need % specify it as p e.g. w50p will get translated to width: 50%
  • If no unit is needed, specify n e.g. fw600n will translate to font-weight: 600

Installation

First, install Stylos as a development dependency:

npm i -D stylos

Then, import Stylos into your Webpack configuration and add it to your list of plugins:

// webpack.config.js
const Stylos = require('stylos');

module.exports = {
  // ...
  rules: [
    // ...
    // Add the rule to use the loader for HTML or JSX files
    {
      test: /(\.js|\.jsx|\.html)$/,
      exclude: /node_modules/,
      use: Stylos.Loader
    }
  ],
  plugins: [
    // ...
    // new HtmlWebpackPlugin(..),  // <-- You must have it installed and set up
    // Add the plugin right after the HTMLWebpackPlugin
    new Stylos.Plugin()
  ]
}

Contributions

  • Open pull request with improvements
  • Report any bugs
  • Discuss ideas in issues
  • Spread the word
  • Reach out with any feedback Twitter URL

License

MIT © Kamran Ahmed