Uses context components to provide theme object deep down React tree.
import {Theme, Themed} from 'libreact/lib/theme';
const theme = {
color: 'white',
background: 'tomato'
};
<Theme value={theme}>
<Themed>{({color, background}) =>
<div style={{color, background}}>Color is: {color}</div>
}</Themed>
</Theme>
Theme provider, used to specify and update theme object.
value
- theme object.name
- optional, theme name.
FaCC theme consumer, re-renders on theme update.
name
- optional, theme name.
Theme enhancer that ensures your component is injected with theme
property.
withTheme: (Comp: React.Component, propName?: string, props?: object) => React.Component;
, where
Comp
- your React component.propName
- optional, string, injected prop name.props
- optional, object, props to provided to<Themed>
.
Returns a themed component that will have a prop named theme
containing
theme object.
const Block = ({theme: {color, background}}) =>
<div style={{color, background}}>Color is: {color}</div>;
const BlockThemed = withTheme(Block);
const theme = {
color: 'white',
background: 'tomato'
};
<Theme value={theme}>
<BlockThemed />
</Theme>
React component class decorator that injects theme
into props. You can optionally,
specify injected prop name and theme name.
Usage
@withTheme
@withTheme('')
@withTheme('specialTheme', {name: 'specialTheme'})
class Button extends Component {
}
``