Make CSS easier and more maintainable by using JavaScript
npm install free-style> Free-Style is designed to make CSS easier and more maintainable by using JavaScript.
```
npm install free-style --save
There's a great presentation by Christopher Chedeau you should check out.
- No global variables (What and where is .button? Why is it conflicting?)
- Defined dependency systems (CommonJS, Require.js, )
- Dead code elimination automatically removes unused styles
- Minification through JavaScript tooling
- Shared constants and reusable styles
- Every style is isolated, tested and namespaced to the JS component
- Extensible - everything from Math to color manipulation already exists!
- Works with third-party DOM components (You can nest regular .class-name in your styles)ul > li > a
- Deterministically generates styles and class names, and automatically merges duplicate styles
- Develop components alongside the style (No more hunting CSS files for estranged ){ '&:hover': { ... } }
- Create universal applications and serve styles for only the components rendered (see React Free-Style)
- Write the CSS you already know ()@
- Automatically namespace -rule styles ({ '@media (min-width: 500px)': { ... } }){ backgroundColor: ['red', 'linear-gradient(to right, red 0%, blue 100%)'] }
- Overload CSS properties using arrays ()
- Small and powerful API that works with any ecosystem (~360 SLOC)
Free-Style generates a hash from the style to use as the class name. This allows duplicate styles to automatically be merged on duplicate hashes. Every style is "registered" and assigned to a variable, which gets the most out of linters that will warn on unused variables and features like dead code minification. Styles should usually be created outside of the application run loop (e.g. render()) so the CSS string and hashes are only generated once.
- typestyle - Popular type-safe interface for working with CSS
- react-free-style - React implementation that renders styles on the current page (for universal apps)
- stylin - Simplest abstraction for creating styles, rules, and keyframes, and keeps in syncethcss
- - Library for writing CSS with literal objects
- This module! - Manually create, compose and manipulate style instances
`js
import { create } from "free-style";
// Create a stylesheet instance.
const sheet = create();
// Register a new style, returning a class name to use.
const backgroundStyle = sheet.registerStyle({
backgroundColor: "red",
}); //=> "f14svl5e"
// Inject