Skip to content

Commit ae542c0

Browse files
committedMar 24, 2018
feat: add react preset
1 parent 8f38473 commit ae542c0

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
 

‎docs/Presets.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ Below is a list of available presets.
2525

2626
- `sheet` — installs [`sheet()`](./sheet.md) addon, as well as `stable`, `nesting`, `atoms`, and `keyframes` addons
2727
- `vdom` — similar to `sheet` preset, but also installs [`jsx()`](./jsx.md) addon, you need to provide `h` function in configuration
28+
- `react` — similar to `vdom` preset, but specifies hyperscript function `h` automatically and also installs `snake`, `style`, `styled`, and `decorator` addons

‎preset/react.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
var h = require('react').createElement;
4+
var create = require('../index').create;
5+
var addonCache = require('../addon/cache').addon;
6+
var addonStable = require('../addon/stable').addon;
7+
var addonNesting = require('../addon/nesting').addon;
8+
var addonAtoms = require('../addon/atoms').addon;
9+
var addonSnake = require('../addon/snake').addon;
10+
var addonKeyframes = require('../addon/keyframes').addon;
11+
var addonRule = require('../addon/rule').addon;
12+
var addonSheet = require('../addon/sheet').addon;
13+
var addonJsx = require('../addon/jsx').addon;
14+
var addonStyle = require('../addon/style').addon;
15+
var addonStyled = require('../addon/styled').addon;
16+
var addonDecorator = require('../addon/decorator').addon;
17+
18+
exports.preset = function (config) {
19+
config = config || {};
20+
config.h = config.h || h;
21+
22+
var nano = create(config);
23+
24+
addonCache(nano);
25+
addonStable(nano);
26+
addonNesting(nano);
27+
addonAtoms(nano);
28+
addonSnake(nano);
29+
addonKeyframes(nano);
30+
addonRule(nano);
31+
addonSheet(nano);
32+
addonJsx(nano);
33+
addonStyle(nano);
34+
addonStyled(nano);
35+
addonDecorator(nano);
36+
37+
return nano;
38+
};

‎preset/vdom.js

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ var addonSheet = require('../addon/sheet').addon;
1111
var addonJsx = require('../addon/jsx').addon;
1212

1313
exports.preset = function (config) {
14+
if (process.env.NODE_ENV !== 'production') {
15+
if (!config || !(config instanceof Object) || !config.h) {
16+
console.error(
17+
'For "vdom" nano-css preset you have to provide virtual DOM ' +
18+
'hyperscript function h. Such as: preset({h: require("react").createElement})'
19+
);
20+
}
21+
}
22+
1423
var nano = create(config);
1524

1625
addonCache(nano);

0 commit comments

Comments
 (0)