|
1 |
| -Build your own theme, or view our [example theme](https://zillow.github.io/drywall-theme-bootstrap/) based on the [Bootstrap](https://getbootstrap.com/) UI system. |
| 1 | +All styles in drywall come from a theme object that is passed down to components via the [`ThemeProvider`](https://www.styled-components.com/docs/api#themeprovider) component. |
| 2 | +Wrap your application in the component, and pass it your theme to see your library come to life! |
| 3 | + |
| 4 | +```jsx static |
| 5 | +import React from 'react'; |
| 6 | +import ReactDOM from 'react-dom'; |
| 7 | +import { ThemeProvider } from 'styled-components'; |
| 8 | +import { ThemeBoostrap } from 'drywall-theme-bootstrap'; |
| 9 | +import { Button } from 'drywall'; |
| 10 | + |
| 11 | +ReactDOM.render( |
| 12 | + <ThemeProvider theme={ThemeBootstrap}> |
| 13 | + <Button>Bootstrap button</Button> |
| 14 | + </ThemeProvider>, |
| 15 | + document.getElementById('root') |
| 16 | +); |
| 17 | +``` |
| 18 | + |
| 19 | +If you're not interested in building a theme yourself, check out our [example theme](https://zillow.github.io/drywall-theme-bootstrap/) based on the [Bootstrap](https://getbootstrap.com/) UI system. |
| 20 | +If you are interested, keep reading! |
| 21 | + |
| 22 | +At the simplest level, a theme is just a plain javascript object consisting of many [styled-components `css` objects](https://www.styled-components.com/docs/api#css). |
| 23 | +Drywall components know how to pull their corresponding styles from the theme object through the convention, `theme.namespace.Component`. |
| 24 | +For example, `Button` styles for the bootstrap example theme will always live at `theme.bootstrap.Button`. |
| 25 | +There is some additional functionality supporting namespacing, but for now, just make sure to wrap your theme with the `withNamespace` function: |
| 26 | + |
| 27 | +```jsx static |
| 28 | +import { withNamespace } from 'drywall'; |
| 29 | +import { css } from 'styled-components'; |
| 30 | + |
| 31 | +const CustomTheme = { |
| 32 | + CustomTheme: { |
| 33 | + Button: css` |
| 34 | + color: blue; |
| 35 | + ` |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +export default withNamespace(CustomTheme, 'CustomTheme'); |
| 40 | +``` |
| 41 | + |
| 42 | +Other than the location of the top level component css objects, drywall makes no assumptions about what your theme object looks like. |
| 43 | +Feel free to add design tokens and other shared functionality to the theme as you please. |
0 commit comments