1.0.1 • Published 6 years ago
@telkomdesign/styles v1.0.1
Tedis Icons
Styles utilites telkom design system
Installation
$ npm install --save @telkomdesign/stylesUsage
The idea is that you define a theme, wrap your application with ThemeProvider and pass the theme to ThemeProvider. ThemeProvider will pass it over context to your styles creator function and to your props. After that you may change your theme, and all your components will get the new theme automatically. And withStyles for inject your style into component.
Using ThemeProvider:
- It has a
themeprop which should be anobjectorfunction:- If it is an
Objectand used in a rootThemeProviderthen it's intact and being passed down the react tree. - If it is
Objectand used in a nestedThemeProviderthen it's being merged with theme from a parentThemeProviderand passed down the react tree. - If it is
Functionand used in a nestedThemeProviderthen it's being applied to the theme from a parentThemeProvider. If result is anObjectit will be passed down the react tree, throws otherwise.
- If it is an
ThemeProvideras every other component can render only single child, because it usesReact.Children.onlyin render and throws otherwise.
import React from 'react'
import { withStyle, ThemeProvider } from '@telkomdesign/styles'
const Button = ({classes, children}) => (
<button className={classes.button}>
<span className={classes.label}>{children}</span>
</button>
)
const styles = theme => ({
button: {
background: theme.colorPrimary
},
label: {
fontWeight: 'bold'
}
})
const StyledButton = withStyle(styles)(Button)
const theme = {
colorPrimary: 'green'
}
const App = () => (
<ThemeProvider theme={theme}>
<StyledButton>I am a button with green background</StyledButton>
</ThemeProvider>
)