fluent-style-sheets
fluent-style-sheets
is a library that lets you define your CSS using JavaScript.
It supports two usage styles: it has a fluent API that resembles CSS
as much as possible or you can use it more like an EDSL.
Installation
npm i fluent-style-sheets --save-dev
Features
Usage styles
Fluent style
const makeStyleSheet = ; const bodyBackgroundColor = '#ff00ff'; const styleSheet = // imports // rules // nested rules ; console;
EDSL style
const makeStyleSheet = ; const bodyBackgroundColor = '#ff00ff'; const styleSheet = ;const i r = styleSheet; // imports; // rules; // nested rules; console;
Quick reference
makeStyleSheet
Create a new style sheet instance.
Type: function(): StyleSheet
const myStyleSheet = ;
StyleSheet.i
Alias for StyleSheet.import
.
StyleSheet.import
Create a new CSS @import.
Type: function(url: string, mediaQueries: ...string): StyleSheet
const myStyleSheet = ;myStyleSheet // using media queries: ;
StyleSheet.r
Alias for StyleSheet.rule
.
StyleSheet.renderCSS
Render the style sheet to string with CSS syntax.
Type: function(signature: ?string=): string
const myStyleSheet = ;// ... build your style sheet using myStyleSheet ...const cssWithDefaultSignature = myStyleSheet; // or .renderCSS(undefined)const cssWithNoSignature = myStyleSheet;const cssWithCustomSignature = myStyleSheet;
StyleSheet.rule
Create a new CSS rule.
Type: function(selectors: ...string, declarationsOrAssembler: (object | object[] | function(subcontext: Subcontext))): StyleSheet
const myStyleSheet = ;myStyleSheet // you can use multiple selectors // if no selector is specified, the rule will be global ;
Subcontext.r
Alias for Subcontext.rule
.
Subcontext.rule
Create a new CSS rule embedded in the subcontext.
Type: function(selectors: ...string, declarationsOrAssembler: (object | object[] | function(subcontext: Subcontext))): Subcontext
const myStyleSheet = ;myStyleSheet ; /* CSS:.my-class .my-class-2 { color: #ff00ff;} .my-class + .siblings-to-my-class,.my-class > .children-of-my-class { margin: 1px;} .my-class .my-class-3 .my-class-4 { display: none;}*/
Subcontext.s
Alias for Subcontext.spec
.
Subcontext.spec
Create a rule specialization embedded in the subcontext.
Type: function(selectors: ...string, declarationsOrAssembler: (object | object[] | function(subcontext: Subcontext))): Subcontext
const myStyleSheet = ;myStyleSheet ; /* CSS:.my-class:hover,.my-class[data-foo="bar"] { color: #ff00ff;} .my-class.my-other-class section { padding: 0px;}*/