-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
3 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
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,86 @@ | ||
# CSS Variables | ||
|
||
Use [CSS Custom Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/--*) (aka CSS variables) theming with automatic fallback | ||
to [regular theming](./theme.md). Below components allow you to safely use CSS variables. You simply use `<CssVarsProvider>` similar | ||
to how you use [`<Theme>`](./theme.me#theme), but if CSS variables are supported by user's browser all values will be replaces instead | ||
by CSS variables and on subsequent re-renders it will try to just modify the CSS variables without re-rendering the its children. | ||
|
||
> If CSS Custom Properties are not supported, CssVars works like a typical theme provider. | ||
## Usage | ||
|
||
```jsx | ||
import {CssVarsProvider, CssVars} from 'libreact/lib/cssvars'; | ||
|
||
<CssVarsProvider vars={{ | ||
color: 'tomato' | ||
}}> | ||
<CssVars>{vars => | ||
<button style={vars}>Click me!</button> | ||
}</CssVars> | ||
</CssVarsProvider> | ||
``` | ||
|
||
|
||
## `<CssVarsProvider>` | ||
|
||
CSS variable context provider. | ||
|
||
### Props | ||
|
||
- `ns` — optional, string, context namespace, defaults to `''`. | ||
- `vars` — require, plain flat JavaScript object, map of keys to CSS values, which will be replaces by CSS variables. | ||
|
||
|
||
## `<CssVars>` | ||
|
||
CSS variable context consumer render prop. | ||
|
||
### Props | ||
|
||
- `ns` — optional, string, context namespace, defaults to `''`. | ||
|
||
### Arguments | ||
|
||
Render prop receives a single argument — map of variables where values are replaced by CSS variables. | ||
|
||
|
||
## `withCssVars()` HOC | ||
|
||
Enhancer that injects `vars` prop into component. | ||
|
||
### Usage | ||
|
||
```js | ||
import {withCssVars} from 'libreact/lib/cssvars'; | ||
|
||
const MyCompWithVars = withCssVars(MyComp); | ||
const MyCompWithVars = withCssVars(MyComp, 'theme', {ns: 'css-theme'}); | ||
``` | ||
|
||
### Signature | ||
|
||
```js | ||
withCssVars(Component, propName?, cssVarsProps?); | ||
``` | ||
## `@withCssVars` Decorator | ||
Stateful class decorator that injects `vars` prop. | ||
### Usage | ||
```js | ||
import {withCssVars} from 'libreact/lib/cssvars'; | ||
|
||
@withCssVars | ||
class MyCompWithVars extends Component { | ||
|
||
} | ||
|
||
@withCssVars('theme', {ns: 'css-theme'}) | ||
class MyCompWithVars extends Component { | ||
|
||
} | ||
``` |
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