Skip to content

Commit

Permalink
feat: add react preset
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 24, 2018
1 parent 8f38473 commit ae542c0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/Presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Below is a list of available presets.

- `sheet` — installs [`sheet()`](./sheet.md) addon, as well as `stable`, `nesting`, `atoms`, and `keyframes` addons
- `vdom` — similar to `sheet` preset, but also installs [`jsx()`](./jsx.md) addon, you need to provide `h` function in configuration
- `react` — similar to `vdom` preset, but specifies hyperscript function `h` automatically and also installs `snake`, `style`, `styled`, and `decorator` addons
38 changes: 38 additions & 0 deletions preset/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

var h = require('react').createElement;
var create = require('../index').create;
var addonCache = require('../addon/cache').addon;
var addonStable = require('../addon/stable').addon;
var addonNesting = require('../addon/nesting').addon;
var addonAtoms = require('../addon/atoms').addon;
var addonSnake = require('../addon/snake').addon;
var addonKeyframes = require('../addon/keyframes').addon;
var addonRule = require('../addon/rule').addon;
var addonSheet = require('../addon/sheet').addon;
var addonJsx = require('../addon/jsx').addon;
var addonStyle = require('../addon/style').addon;
var addonStyled = require('../addon/styled').addon;
var addonDecorator = require('../addon/decorator').addon;

exports.preset = function (config) {
config = config || {};
config.h = config.h || h;

var nano = create(config);

addonCache(nano);
addonStable(nano);
addonNesting(nano);
addonAtoms(nano);
addonSnake(nano);
addonKeyframes(nano);
addonRule(nano);
addonSheet(nano);
addonJsx(nano);
addonStyle(nano);
addonStyled(nano);
addonDecorator(nano);

return nano;
};
9 changes: 9 additions & 0 deletions preset/vdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ var addonSheet = require('../addon/sheet').addon;
var addonJsx = require('../addon/jsx').addon;

exports.preset = function (config) {
if (process.env.NODE_ENV !== 'production') {
if (!config || !(config instanceof Object) || !config.h) {
console.error(
'For "vdom" nano-css preset you have to provide virtual DOM ' +
'hyperscript function h. Such as: preset({h: require("react").createElement})'
);
}
}

var nano = create(config);

addonCache(nano);
Expand Down

0 comments on commit ae542c0

Please sign in to comment.