Skip to content

Commit

Permalink
fix: support class prop
Browse files Browse the repository at this point in the history
React supports using class instead of className. we should too.
  • Loading branch information
satya164 committed Oct 18, 2018
1 parent b1d1490 commit 56bc52e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/react/styled.js
@@ -1,6 +1,7 @@
/* @flow */

const React = require('react'); // eslint-disable-line import/no-extraneous-dependencies
const { cx } = require('../index');

/* ::
type Options = {
Expand All @@ -23,13 +24,10 @@ function styled(tag /* : React.ComponentType<*> | string */) {

/* $FlowFixMe: Flow doesn't know about forwardRef */
const Result = React.forwardRef((props, ref) => {
const { as: component = tag, ...rest } = props;
const next = Object.assign(rest, {
ref,
className: props.className
? `${options.class} ${props.className}`
: options.class,
});
const { as: component = tag, class: className, ...rest } = props;

rest.ref = ref;
rest.className = cx(rest.className || className, options.class);

const { vars } = options;

Expand All @@ -43,10 +41,10 @@ function styled(tag /* : React.ComponentType<*> | string */) {
}${unit}`;
});

next.style = Object.assign(style, next.style);
rest.style = Object.assign(style, rest.style);
}

return React.createElement(component, next);
return React.createElement(component, rest);
});

Result.displayName = options.name;
Expand Down

0 comments on commit 56bc52e

Please sign in to comment.