8000 FEAT: support flag for the skip style property by Mobydack · Pull Request #33 · quarkly/atomize · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

FEAT: support flag for the skip style property #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/atomic-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ const defaultConfig = { useAliases: true };

export const isTemplate = arg => isArray(arg);

export const makeComponent = (styled, tag, styles, config, other) => {
export const makeComponent = (styled, tag, _styles, config, other) => {
const { forwardCssProperties } = config;
const defaultProps = isPlainObject(other) ? other : undefined;
const rulesCreator = bootstrap(config, defaultProps);
const rules = isArray(other) ? other : [];
const cleanProps = typeof tag === 'string';

const pureCSS =
typeof forwardCssProperties === 'boolean' ? !forwardCssProperties : typeof tag === 'string';
const denieList = ['cssObject'];
if (cleanProps) denieList.push('theme');

if (pureCSS) denieList.push('theme');

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

if (config.name) {
Expand All @@ -49,9 +51,11 @@ export const makeComponent = (styled, tag, styles, config, other) => {

export const makeAtom = styled => (tag, config = {}, defaultProps) => {
const styles = config.styles || defaultStyles;

if (isTemplate(config)) {
return makeComponent(styled, tag, styles, {}, config);
}

return makeComponent(styled, tag, styles, { ...defaultConfig, ...config }, defaultProps);
};

Expand Down
70 changes: 70 additions & 0 deletions test/sc-integration/__snapshots__/clear-props.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`atomize filter props keys test cleaning style props with forwardCssProperties = false isn't included styles 1`] = `
.c0 {
color: red;
}

<div
className="c0"
color_passed="red"
/>
`;

exports[`atomize filter props keys test cleaning style props with forwardCssProperties = false isn't included styles 2`] = `
.c0 {
color: red;
}

<div
className="c0"
color_passed="red"
/>
`;

exports[`atomize filter props keys test cleaning style props with forwardCssProperties = true isn't included styles 1`] = `
.c0 {
color: red;
}

<div
className="c0"
color="red"
color_passed="red"
/>
`;

exports[`atomize filter props keys test cleaning style props with forwardCssProperties = true isn't included styles 2`] = `
.c0 {
color: red;
}

<div
className="c0"
color="red"
color_passed="red"
/>
`;

exports[`atomize filter props keys test cleaning style props with forwardCssProperties = undefined isn't included styles 1`] = `
.c0 {
color: red;
}

<div
className="c0"
color="red"
color_passed="red"
/>
`;

exports[`atomize filter props keys test cleaning style props with forwardCssProperties = undefined isn't included styles 2`] = `
.c0 {
color: red;
}

<div
className="c0"
color_passed="red"
/>
`;
30 changes: 30 additions & 0 deletions test/sc-integration/clear-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,34 @@ describe('atomize filter props keys', () => {
/>
`);
});

describe.each([undefined, false, true])(
'test cleaning style props with forwardCssProperties = %p',
forwardCssProperties => {
const Primitive = atomize('div')({
effects: { hover: ':hover' },
aliases: true,
forwardCssProperties,
});

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

test("isn't included styles", () => {
const treeComponent = renderer
.create(<ComponentWithoutStylesProp color="red" color_passed="red" />)
.toJSON();
const treePrimitive = renderer
.create(<Primitive color="red" color_passed="red" />)
.toJSON();

expect(treeComponent).toMatchSnapshot();

expect(treePrimitive).toMatchSnapshot();
});
},
);
});
0