Skip to content

Commit

Permalink
docs: document ThemeProvider override functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Dec 27, 2023
1 parent f398686 commit f6ff6dc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion sections/api/primary/theme-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ Check the section on [Theming](/docs/advanced#theming).
<Code>theme</Code>
</Column>
<Column>
An object that will be injected as <Code>theme</Code> into all
An object (or function returning an object) that will be injected as <Code>theme</Code> into all
interpolations in styled components beneath the provider.
</Column>
</Row>
</Table>

Simple usage:

```react
// import styled, { ThemeProvider } from 'styled-components'
Expand All @@ -32,3 +34,25 @@ render(
</ThemeProvider>
)
```

Adding to or replacing an outer theme using nested `ThemeProvider`:

```react
// import styled, { ThemeProvider } from 'styled-components'
const Box = styled.div`
background-color: ${props => props.theme.bg};
color: ${props => props.theme.color};
`
render(
<ThemeProvider theme={{ bg: 'white', color: 'mediumseagreen' }}>
<Box>
I'm mediumseagreen with a white background!
<ThemeProvider theme={outerTheme => ({...outerTheme, bg: 'black'})}>
<Box>I'm mediumseagreen with a black background!</Box>
</ThemeProvider>
</Box>
</ThemeProvider>
)
```

0 comments on commit f6ff6dc

Please sign in to comment.