string-css
Create CSS-in-JS via tagged template strings.
Install
$ npm i string-css --save
API
The export is a singleton containing 3 methods:
Bearing in mind the use of the singleton pattern, calls to inject
or string
should appear after all styles are created.
.css(string)
The function that parses CSS-in-JS template strings.
// constants should be externalconst BLACK = 'black'const BLOCK = 'block' // create rule with strings & values// returns class names to apply to elementconst rule = css` display: ; width: 100px; height: 100px; background-color: ;` // apply class names to DOM elementdocumentclassName = rule
.inject()
Injects created styles into the DOM, using insertRule
.
// synchronously creates a style tag in the head, then inserts the rules
.string()
Returns a string representation of all the created CSS.
// synchronously creates a string of CSSconst style =
See Also
- hsx - Static HTML sites with JSX and webpack (no React).
- string-dom - Create HTML strings using JSX (or functions).
License
MIT. © 2017 Michael Cavalea