Skip to content

Commit bc75c59

Browse files
committed
Minor fixes
1 parent 27cab44 commit bc75c59

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 0.0.7
1+
# 0.0.8
22

33
- 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.
44

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"license": "MIT",
33
"name": "shakl",
44
"description": "A utility to create styled components in React Native.",
5-
"version": "0.0.7",
5+
"version": "0.0.8",
66
"main": "lib/index.js",
77
"react-native": "lib/rn.js",
88
"repository": {

src/styled.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import { ThemeProvider, withTheme } from './theme';
66

77
const styled = (Comp, { name, multi, ...opts } = {}) => style => {
88
const Styled = React.forwardRef(({ childRef, ...props }, ref) => {
9-
const { attrs, comp, child, childProps } = opts;
9+
const { comp, child, childProps } = opts;
1010
const { children } = props;
1111

12+
let { attrs } = opts;
13+
attrs = attrs ? attrs(props) : {};
14+
1215
const styleProps = multi ? style : { style };
1316
const styleKeys = Object.keys(styleProps);
1417

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

2023
styles[prop] = flatten([
24+
attrs[prop],
2125
typeof styleProps[prop] === 'function'
2226
? styleProps[prop](props)
2327
: styleProps[prop],
@@ -26,7 +30,7 @@ const styled = (Comp, { name, multi, ...opts } = {}) => style => {
2630
}
2731

2832
const parentProps = {
29-
...(attrs && attrs(props)),
33+
...attrs,
3034
...props,
3135
...styles
3236
};
@@ -54,7 +58,7 @@ const styled = (Comp, { name, multi, ...opts } = {}) => style => {
5458
Styled.extend = more => styled(Styled, { name })(more);
5559

5660
Styled.attrs = attrs => {
57-
if (typeof attrs === 'function') return styled(Styled, { name, attrs })();
61+
if (typeof attrs === 'function') return styled(Styled, { attrs })();
5862

5963
Styled.defaultProps = {
6064
...Styled.defaultProps,

0 commit comments

Comments
 (0)