Skip to content

Commit

Permalink
feat: add $ref and $as support for jsx()
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 14, 2018
1 parent a7612fa commit 1207854
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Empty file added addon/extend.js
Empty file.
18 changes: 16 additions & 2 deletions addon/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ exports.addon = function (renderer) {
addonCache(renderer);
}

if (process.env.NODE_ENV !== 'production') {
require('./__dev__/warnOnMissingDependencies')('styled', renderer, ['rule', 'cache']);
}

renderer.jsx = function (fn, styles, block) {
var className;
var isElement = typeof fn === 'string';
Expand All @@ -20,17 +24,27 @@ exports.addon = function (renderer) {
}

var copy = props;
var $as = copy.$as;
var $ref = copy.$ref;

if (process.env.NODE_ENV !== 'production') {
copy = Object.assign({}, props);
copy = renderer.assign({}, props);
}

var dynamicClassName = renderer.cache(props.css);
delete copy.css;
delete copy.$as;

if (isElement || $as) {
delete copy.$ref;
copy.ref = $ref;
}

copy.className = (props.className || '') + className + dynamicClassName;

return isElement ? renderer.h(fn, copy) : fn(copy);
return (isElement || $as)
? renderer.h($as || fn, copy)
: fn(copy);
};

if (process.env.NODE_EVN !== 'production') {
Expand Down
Empty file added addon/keyframes.js
Empty file.

0 comments on commit 1207854

Please sign in to comment.