0.1.1 • Published 10 years ago

styles.js v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

Dynamically generate CSS in JavaScript

As was recommended by Christopher Chedeau in his talk about CSS, it is recommended to forego global CSS entirely, and use local CSS instead. However, Christopher suggests embedding styles directly in the DOM element itself. As a result, we lose the ability to style multiple elements using the developer console.

Fortunately, this is where styles.js comes in.

You declaratively define styles using JavaScript objects, which styles.js will interpret then apply styles to globally unique class names. You then assign the DOM elements with the class names, to apply the styles that you want.

Usage

Install styles.js with npm:

npm install styles.js

Then, you generate a set of classes, and inject a new stylesheet like so:

var createStyles = require('createStyles');

var myBoxStyles = createStyles({
  box: {
    backgroundColor: 'blue',
    color: 'white'
  },

  inner: {
    padding: '10px',
    color: 'red'
  }
}, 'My App Name');

var div = document.createElement('div');

div.setAttribute('class', myBoxStyles.box);

License

styles.js is MIT-Licensed

0.1.1

10 years ago

0.1.0-alpha4

10 years ago

0.1.0-alpha3

10 years ago

0.1.0-alpha2

10 years ago

0.1.0-alpha1

10 years ago