Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sonaye committed Aug 2, 2018
1 parent 27cab44 commit bc75c59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
@@ -1,4 +1,4 @@
# 0.0.7
# 0.0.8

- Support dynamic props in `attrs()`. By default `attrs()` only overwrites the `defaultProps` of the component, now when you pass it a function it will allow for computed props.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"license": "MIT",
"name": "shakl",
"description": "A utility to create styled components in React Native.",
"version": "0.0.7",
"version": "0.0.8",
"main": "lib/index.js",
"react-native": "lib/rn.js",
"repository": {
Expand Down
10 changes: 7 additions & 3 deletions src/styled.js
Expand Up @@ -6,9 +6,12 @@ import { ThemeProvider, withTheme } from './theme';

const styled = (Comp, { name, multi, ...opts } = {}) => style => {
const Styled = React.forwardRef(({ childRef, ...props }, ref) => {
const { attrs, comp, child, childProps } = opts;
const { comp, child, childProps } = opts;
const { children } = props;

let { attrs } = opts;
attrs = attrs ? attrs(props) : {};

const styleProps = multi ? style : { style };
const styleKeys = Object.keys(styleProps);

Expand All @@ -18,6 +21,7 @@ const styled = (Comp, { name, multi, ...opts } = {}) => style => {
const prop = styleKeys[i];

styles[prop] = flatten([
attrs[prop],
typeof styleProps[prop] === 'function'
? styleProps[prop](props)
: styleProps[prop],
Expand All @@ -26,7 +30,7 @@ const styled = (Comp, { name, multi, ...opts } = {}) => style => {
}

const parentProps = {
...(attrs && attrs(props)),
...attrs,
...props,
...styles
};
Expand Down Expand Up @@ -54,7 +58,7 @@ const styled = (Comp, { name, multi, ...opts } = {}) => style => {
Styled.extend = more => styled(Styled, { name })(more);

Styled.attrs = attrs => {
if (typeof attrs === 'function') return styled(Styled, { name, attrs })();
if (typeof attrs === 'function') return styled(Styled, { attrs })();

Styled.defaultProps = {
...Styled.defaultProps,
Expand Down

0 comments on commit bc75c59

Please sign in to comment.