Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThemeProvider: Add nesting support #19

Merged
merged 5 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"presets": ["env", "react", "flow"],
"presets": [
"./scripts/babel-preset-env",
"react",
"flow"
],
"plugins": [
"transform-class-properties",
"transform-flow-strip-types",
"transform-object-rest-spread"
]
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ stories
node_modules
coverage
src
__tests__
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> A simple way to include CSS with React Components.

- **Tiny**, around 3 KB gzipped
- **Tiny**, around 4 KB gzipped
- **One dependency** - ([Stylis](https://github.com/thysultan/stylis.js))
- **Write** plain ol' CSS. Period.
- **Pre-processing** when you need it. Powered by [Stylis](https://github.com/thysultan/stylis.js).
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Dynamic styles](./dynamic-styles.md)
- [Dynamic classNames](./dynamic-classnames.md)
- [Theming](./theming.md)
- [Scoping](./scoping.md)
- [HTML primitives](./primitives.md)
- [Component styling](./component-styling.md)
- [Style interpolation](./style-interpolation.md)
20 changes: 20 additions & 0 deletions docs/scoping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Scoping

Fancy comes with a special `ScopeProvider` that allows you to define additional selectors to scope your fancy `styled` component CSS under.

### Example

```jsx
<ScopeProvider scope="html #App">
<StyledCard />
</ScopeProvider>
```

If the hashed CSS classes for `StyledCard` was `.Card__213jdhx`, they will now render as `html #App .Card__213jdhx`.

## See also

- [Primitives](./primitives.md)
- [Component styling](./component-styling.md)
- [Style interpolation](./style-interpolation.md)
- [Theming](./theming.md)
19 changes: 3 additions & 16 deletions docs/theming.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 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.
Fancy comes with `ThemeProvider`. 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`.
Define your theme props to `ThemeProvider` as `theme`.

### Example

Expand Down Expand Up @@ -38,22 +38,9 @@ const App = () => (
)
```

## 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`.

## See also

- [Primitives](./primitives.md)
- [Component styling](./component-styling.md)
- [Scoping](./scoping.md)
- [Style interpolation](./style-interpolation.md)
56 changes: 23 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"private": false,
"version": "1.0.5",
"description": "A simple way to include CSS with React Components",
"main": "lib/index.js",
"main": "dist/index.js",
"module": "lib/index.js",
"source": "lib/index.js",
"scripts": {
"babel:main": "babel --presets=react,flow,es2015 --plugins=transform-object-rest-spread --no-babelrc -d lib --ignore '*.test.js' src",
"babel": "npm run babel:main",
"babel:module": "BABEL_ENV=modules babel -d lib --ignore '*.test.js' src",
"babel:main": "babel -d dist --ignore '*.test.js' src",
"babel": "npm run babel:main && npm run babel:module",
"build": "npm run lint && npm run clean && npm run babel",
"bundle:prebuild": "npm run babel:module",
"bundle:build": "microbundle build --external all --jsx React.createElement",
Expand Down Expand Up @@ -67,6 +68,8 @@
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-jest": "22.4.3",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-preset-env": "1.6.1",
"babel-preset-es2015": "6.24.1",
Expand Down
18 changes: 18 additions & 0 deletions scripts/babel-preset-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const env = require('babel-preset-env')

const ENV = process.env.BABEL_ENV

module.exports = {
presets: [
[
env,
{
targets: {
ie: 11,
node: '6.11',
},
modules: ENV === 'modules' ? false : 'commonjs',
},
],
],
}
29 changes: 29 additions & 0 deletions src/Fragment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Source:
// https://github.com/donavon/render-fragment/blob/master/src/index.jsx

import React from 'react'

const [reactMajorVersion] = React.version.split('.')
const canReturnArray = parseInt(reactMajorVersion, 10) >= 16

const FragmentPolyfill = ({ children, as: Wrapper, ...others }) =>
Wrapper ? (
<Wrapper {...others}>{children}</Wrapper>
) : (
/* istanbul ignore next */
React.Children.toArray(children)
)

FragmentPolyfill.defaultProps = {
as: canReturnArray
? /* istanbul ignore next */
undefined
: 'div',
}

const Fragment = React.Fragment
? /* istanbul ignore next */
React.Fragment
: FragmentPolyfill

export default Fragment
Loading