ReTheme
Tools for styling React or React Native components
Setup
- Add to your package.json
"re-theme": "git+https://github.com/keg-hub/re-theme"
- Wrap the entry point of your application with an instance of
ReThemeProvider
, e.g.:
import { ReThemeProvider } from 're-theme'
const myCustomTheme = {
}
export const App from Component {
state = { theme: myCustomTheme }
componentDidUpdate = () => {
this.props.theme !== this.state.theme &&
this.setState({ theme: this.props.theme })
}
render(){
return (
<ReThemeProvider theme={this.state.theme} merge={false}>
<App />
</ReThemeProvider>
)
}
}
ReThemeProvider
accepts two props
theme
: the theme object, containing any global styles you want to use across your appmerge
: a boolean indicating whether or not you want to merge the passed in theme prop with the current theme
reStyle
reStyle
is the preferred utility in ReTheme for styling your components
Usage
...
import { reStyle } from '@keg-hub/re-theme/reStyle'
const StyledButton = reStyle(Button)({
position: 'absolute'
})
const StyledButton = reStyle(Button)(theme => ({
pos: 'absolute',
c: theme.colors.red
}))
const StyledButton = reStyle(Button)((theme, props) => ({
position: 'absolute',
color: theme.colors.red
borderColor: props.outline || theme.colors.borderColor
})
const StyledIcon = reStyle(SomeSvgIcon)(
{ position: 'absolute' }
theme => ({
width: 32,
height: 32
className: 'some-class',
customProp: theme.customValue
})
)
const StyledContainer = reStyle(Container, 'styles')({
main: {
position: 'absolute'
},
content: {
margin: 32
}
})
API
Checkout the Example App for documentation.