Skip to content

Commit

Permalink
fix: pass atomize props to component
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed May 20, 2021
1 parent c9105ce commit 2bfe757
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/atomic-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const makeComponent = (styled, tag, styles, config, other) => {
const defaultProps = isPlainObject(other) ? other : undefined;
const rulesCreator = bootstrap(config, defaultProps);
const rules = isArray(other) ? other : [];
const cleanProps = typeof tag === 'string';

const Component = normalize(
styled(tag).withConfig({
Expand All @@ -23,6 +24,7 @@ export const makeComponent = (styled, tag, styles, config, other) => {
return cssObject;
}),
rulesCreator,
cleanProps,
);

if (config.name) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/normalize-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const normalizer = props => {
}, {});
};

export default (Tag, cb) =>
export default (Tag, cb, cleanProps) =>
React.forwardRef((props, ref) => {
const { cssObject, cleanedProps } = cb(props);
return React.createElement(Tag, {
ref,
...normalizer(cleanedProps),
...normalizer(cleanProps ? cleanedProps : props),
cssObject,
});
});
22 changes: 22 additions & 0 deletions test/sc-integration/clear-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const Element = atomize('div')({
aliases: true,
});

// eslint-disable-next-line react/jsx-props-no-spreading
const Child = props => <div {...props} />;

const ElementWithComponent = atomize(Child)({
effects: { hover: ':hover' },
aliases: true,
});

describe('atomize filter props keys', () => {
test('filter', () => {
const tree = renderer.create(<Element color="red" />).toJSON();
Expand Down Expand Up @@ -47,4 +55,18 @@ describe('atomize filter props keys', () => {
/>
`);
});
test('pass to fn children', () => {
const tree = renderer.create(<ElementWithComponent color="red" color_passed="red" />).toJSON();
expect(tree).toMatchInlineSnapshot(`
.c0 {
color: red;
}
<div
className="c0"
color="red"
color_passed="red"
/>
`);
});
});

0 comments on commit 2bfe757

Please sign in to comment.