Skip to content

Commit

Permalink
Simplify attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
sonaye committed Jul 11, 2018
1 parent 4b5f8b6 commit 06e456a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.0.5

- Simplify `attrs()` my making it just a thin wrapper that overwrites `defaultProps`..

# 0.0.4

- Support theming.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,5 @@ const Foo = styled.div({ background: '#eee' });

<Foo />; // <div style={{ background: '#eee' }} />
```

[![Edit shakl](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/52kw0jrn94?module=%2Fsrc%2FExample.js)
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"license": "MIT",
"name": "shakl",
"description": "A utility to create styled components in React Native.",
"version": "0.0.4",
"version": "0.0.5",
"main": "lib/index.js",
"react-native": "lib/rn.js",
"repository": {
Expand All @@ -13,9 +13,9 @@
"react": ">=16.3.0"
},
"devDependencies": {
"@types/jest": "23.1.4",
"@types/jest": "23.1.5",
"@types/react": "16.4.6",
"@types/react-native": "0.55.28",
"@types/react-native": "~0.55",
"@types/react-test-renderer": "16.0.1",
"babel-eslint": "8.2.5",
"babel-plugin-external-helpers": "6.22.0",
Expand All @@ -24,13 +24,13 @@
"babel-preset-stage-0": "6.24.1",
"benchmark": "2.1.4",
"emotion": "9.2.5",
"eslint": "5.0.1",
"eslint": "~4",
"eslint-config-airbnb": "17.0.0",
"eslint-plugin-import": "2.13.0",
"eslint-plugin-jsx-a11y": "6.1.0",
"eslint-plugin-react": "7.10.0",
"glamorous-native": "1.4.0",
"jest": "23.3.0",
"jest": "23.4.0",
"react": "16.3.1",
"react-emotion": "9.2.5",
"react-native": "0.55.4",
Expand Down
11 changes: 10 additions & 1 deletion src/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ const styled = (Comp, { name, multi, ...opts } = {}) => style => {
Styled.displayName = name || `styled(${Comp.displayName || Comp.name})`;

Styled.extend = more => styled(Styled, { name })(more);
Styled.attrs = attrs => styled(Styled, { name, attrs })();

Styled.attrs = attrs => {
Styled.defaultProps = {
...Styled.defaultProps,
...attrs
};

return Styled;
};

Styled.withComponent = comp => styled(Styled, { comp })(style);
Styled.withChild = child => styled(Styled, { name, child })();
Styled.withTheme = () => withTheme(Styled);
Expand Down

0 comments on commit 06e456a

Please sign in to comment.