react-sow
Customizable styling for React components
Installation
npm install react-sow --save
Example
Create the styles you wish to use using sow()
.
To render based on props, pass a function returning the style rules.
Otherwise, just pass the style rules.
You can attach child stylers by using the second parameter.
// styles.js ; const listStyler = ; const itemStyler = ;
In your pure components, accept the prop styler
,
defaulting it to defaultStyler
(imported from 'react-sow/default').
Then on your main component, call and spread styler()
,
optionally passing props.
// List.js;; { return <li ... > title </li> ;} { return <ul ... > items </ul> ;}
Then in your controller components, import your stylers and render your pure components with them.
// ListController.js;;; ;
Combining stylers
; const orangeTextStyler = ; const largeTextStyler = ; const headingStyler = sow;
:before and :after support
You can even use :before
and :after
in stylers, using fallow()
This works by lazily creating <style>
elements and inserting
them into the <head>
for you.
;; const getMakeGreatAgainClass = ; { return <h2 className= > slogan </h2> ;}
You can use fallow with stylers by passing it to
the classes
style prop:
const makeGreatAgainStyler = ; { return <h2 ... > slogan </h2> ;}
In fact, you can use any function that returns a class name, or even a string:
var tookRedPill = true; { if tookRedPill return 'real-world'; else return 'the-matrix'; } const makeGreatAgainStyler = ;
The function could even lazily create a class when rendering,
and that in fact is exactly how fallow()
works.