react-themeable
Utility for making React components easily themeable.
This project is still experimental, so feedback from component authors would be greatly appreciated!
Why?
The React community is highly fragmented when it comes to styling. How do we write components that can happily co-exist with all of these competing approaches?
With react-themeable, you can support custom themes provided by CSS Modules, Radium, Aphrodite, React Style, JSS, global CSS or inline styles as easily as this:
<MyComponent theme=theme />
Install
npm install --save react-themeable
Usage
react-themeable
exposes just a single function.
This function is designed to accept a theme
prop inside of your render
method. This then returns a small helper function that accepts a key and a series of style names.
const theme = ;...<div ... />
Note: A unique key for each themed element is required for Radium to work correctly.
This helper function detects whether a theme is class or style based, and creates the appropriate attributes for you.
For example:
;; { const theme = ; return <div ...> <div ...>Foo Bar</div> <div ...>Baz</div> </div> ; }
A theme can now be passed to your component like so:
CSS Modules
;...<MyComponent theme=theme />
Radium
; const theme = foo: color: 'red' ':hover': color: 'green' bar: color: 'blue' ; const ThemedMyComponent = ;...<ThemedMyComponent theme=theme />
Aphrodite
; const theme = StyleSheet;...<MyComponent theme= theme css />
React Style
; const theme = StyleSheet;...<MyComponent theme=theme />
JSS
; const sheet = jss;...<MyComponent theme=sheetclasses />
Global CSS
const theme = foo: 'MyComponent__foo' bar: 'MyComponent__bar';...<MyComponent theme=theme />
Inline styles
const theme = foo: color: 'red' bar: color: 'blue' ;...<MyComponent theme=theme />