-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from helpscout/styled-theme-provider
Styled + ThemeProvider
- Loading branch information
Showing
33 changed files
with
719 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"presets": ["env", "react"] | ||
"presets": ["env", "react", "flow"], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package.json | ||
package-lock.json | ||
dist/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
semi: false | ||
singleQuote: true | ||
trailingComma: es5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Documentation | ||
|
||
* [Getting Started](./getting-started.md) | ||
* [Nesting](./nesting.md) | ||
* [Dynamic Styles](./dynamic-styles.md) | ||
* [Dynamic ClassNames](./dynamic-classnames.md) | ||
- [Getting Started](./getting-started.md) | ||
- [Nesting](./nesting.md) | ||
- [Dynamic Styles](./dynamic-styles.md) | ||
- [Dynamic ClassNames](./dynamic-classnames.md) | ||
- [Theming](./theming.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Theming | ||
|
||
Fancy comes with `Theme.Provider`. Added to the top-level of your app, it can modify fancy styled components via a special `props.theme` prop. | ||
|
||
Define your theme props to `Theme.Provider` as `theme`. | ||
|
||
### Example | ||
|
||
```jsx | ||
import styled, { ThemeProvider } from '@helpscout/fancy' | ||
|
||
const css = props => ` | ||
.Card { | ||
background: ${props.theme.dark ? 'black' : 'white'}; | ||
position: relative; | ||
border: 1px solid black; | ||
} | ||
` | ||
|
||
const Card = props => ( | ||
<div className="Card"> | ||
<div className="Card__block">{props.children}</div> | ||
</div> | ||
) | ||
|
||
const StyledCard = styled(Card)(css) | ||
|
||
const App = () => { | ||
;<div id="App"> | ||
<ThemeProvider theme={{ dark: true }}> | ||
<div> | ||
... | ||
<StyledCard /> | ||
... | ||
</div> | ||
</ThemeProvider> | ||
</div> | ||
} | ||
``` | ||
|
||
## Scoping | ||
|
||
`Theme.Provider` has another special `scope` prop that allows you to define additional selectors to scope your fancy `styled` component CSS under. | ||
|
||
### Example | ||
|
||
```jsx | ||
<ThemeProvider scope="html #App"> | ||
<StyledCard /> | ||
</ThemeProvider> | ||
``` | ||
|
||
If the hashed CSS classes for `StyledCard` was `.Card__213jdhx`, they will now render as `html #App .Card__213jdhx`. |
Oops, something went wrong.