diff --git a/README.md b/README.md index edbbad3..dc932f1 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ yarn add styled-components styled-theming ## Example +### Without fallback ```js import React from 'react'; import styled, {ThemeProvider} from 'styled-components'; @@ -37,6 +38,34 @@ export default function App() { } ``` +### With fallback +When there is no ThemeProvider on top hierarchy of components, you can set the fallback. + +```js +import React from 'react'; +import styled, {ThemeProvider} from 'styled-components'; +import theme from 'styled-theming'; + +const boxBackgroundColor = theme('mode', { + light: '#fff', + dark: '#000', +}, 'light'); + +const Box = styled.div` + background-color: ${boxBackgroundColor}; +`; + +export default function App() { + return ( + + + Hello World + + + ); +} +``` + ## API ### `` @@ -69,7 +98,7 @@ function App() { } ``` -### `theme(name, values)` +### `theme(name, values, fallback)` Most of your theming will be done with this function. @@ -162,7 +191,28 @@ const Box = styled.div` `; ``` -### `theme.variants(name, prop, themes)` +`fallback` should match one of the keys in your `` theme. + +```js +import styled, { ThemeProvider } from 'styled-components'; +import theme from 'styled-theming'; + +const backgroundColor = theme('mode', { light: 'lightgray', dark: 'darkgray' }, 'light'); + +const Button = styled.button` + background-color: ${backgroundColor}; +`; + +// Example #1 - bg color of this will be lightgray because no ThemeProvider as it's ancestors +