Skip to content

Commit 5223f8f

Browse files
authored
Docs: Update styled-components usage
1 parent 5402dfe commit 5223f8f

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

docs/Thirdparties.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ _Based on @mikberg’s [blog post](https://medium.com/@mikaelberg/writing-simple
186186

187187
### Styled-components
188188

189-
The recommended way of using [styled-components](https://www.styled-components.com/) is by adding the `@component` JSDoc annotation:
189+
To show PropTypes documentation for [styled-components](https://www.styled-components.com/), you need to add the `@component` JSDoc annotation to the component export:
190190

191191
```jsx
192192
import React from 'react'
193+
import PropTypes from 'prop-types'
193194
import styled from 'styled-components'
194195

195196
const SalmonButton = styled.button`
@@ -198,6 +199,10 @@ const SalmonButton = styled.button`
198199
color: snow;
199200
`
200201

202+
Button.propTypes = {
203+
children: PropTypes.node,
204+
};
205+
201206
/** @component */
202207
export default SalmonButton
203208
```
@@ -213,37 +218,42 @@ export default SalmonButton
213218
+ `
214219
```
215220

221+
**Warning:** other use case for calling the `styled` factory as a function, like styled-system, aren’t supported too:
222+
223+
```diff
224+
- const Input = styled.input(
225+
- css({
226+
- boxSizing: 'border-box',
227+
- // ...
228+
- })
229+
- );
230+
```
231+
216232
#### Adding styled-components `ThemeProvider`
217233

218234
If your styled-components require a theme to render properly, add a `ThemeProvider` to your style guide.
219235

220-
First, create your `Wrapper` component. For this example, we’ll put it in the `styleguide/` directory, but you can add it anywhere you want.
236+
First, create a `Provider` component:
221237

222238
```jsx
223-
// styleguide/ThemeWrapper.js
224-
import React, { Component } from 'react'
239+
// src/Provider.js
240+
import React from 'react'
225241
import { ThemeProvider } from 'styled-components'
226-
import theme from 'where/your/theme/lives'
242+
import theme from './theme'
227243

228-
export default class ThemeWrapper extends Component {
229-
render() {
230-
return (
231-
<ThemeProvider theme={theme}>
232-
{this.props.children}
233-
</ThemeProvider>
234-
)
235-
}
244+
export default function Provider({ children }) {
245+
return <ThemeProvider theme={theme}>{children}</ThemeProvider>
236246
}
237247
```
238248

239-
Next, add `ThemeWrapper` to your `styleguide.config.js`.
249+
Next, add `Provider` to your `styleguide.config.js`:
240250

241251
```javascript
242252
// styleguide.config.js
243253
const path = require('path')
244254
module.exports = {
245255
styleguideComponents: {
246-
Wrapper: path.join(__dirname, 'styleguide/ThemeWrapper')
256+
Wrapper: path.join(__dirname, 'src/Provider.js')
247257
}
248258
}
249259
```

0 commit comments

Comments
 (0)