Skip to content

Commit

Permalink
Docs: Add documentation for Styled Components ThemeProvider (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbsmith authored and sapegin committed Jan 26, 2018
1 parent 1e837c2 commit 5767c01
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/Thirdparties.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,41 @@ const SalmonButton = styled.button`
export default SalmonButton
```

#### Adding Styled Components `ThemeProvider`

If your styled-components require a theme to render properly, you'll want to add a ThemeProvider Wrapper component to the docs.

First, you'll need to create your Wrapper component. For this example we'll put it in the `styleguide/` directory, but you can add it anywhere you want.

```jsx
// styleguide/ThemeWrapper.js

import React, { Component } from 'react'
import { ThemeProvider } from 'styled-components';
import theme from 'where/your/theme/lives';

export default class ThemeWrapper extends Component {
render() {
return <ThemeProvider theme={theme}>{this.props.children}</ThemeProvider>
}
}
```

Next, you'll need to add ThemeWrapper to your `styleguide.config.js`.

```javascript
const path = require('path');

module.exports = {
...
styleguideComponents: {
Wrapper: path.join(__dirname, 'styleguide/ThemeWrapper'),
},
}
```

This will automatically apply your theme to your styled-components. When you fire up the styleguide, `npm run styleguide`, you should see your components render as expected.

### Fela

Check out the [official example](https://github.com/rofrischmann/fela/tree/master/packages/example-with-styleguidist).
Expand Down

0 comments on commit 5767c01

Please sign in to comment.