Skip to content
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

[react] Create Hidden component #146

Merged
merged 9 commits into from
Jun 19, 2024
Merged

[react] Create Hidden component #146

merged 9 commits into from
Jun 19, 2024

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jun 18, 2024

Summary

With a flip perspective, I am able to create the Hidden with the same API using the existing generateAtomics fn.

Instead of declaring xs, … xl as conditions, I use the prop name xsUp, xsDown, xsOnly, … xlUp, xlDown, xlOnly as conditions.

In the component, it reads the runtime theme to find the breakpoint keys and compose the display atomic object:

// user code
<Hidden smUp>

// runtime
atomic({
  display: {
    smUp: 'none', // this will get the className for `smUp`
  }
})

Test

See packages/pigment-css-react/tests/generateAtomics.test.js

@siriwatknp siriwatknp added the component: Hidden The React component. label Jun 18, 2024
Comment on lines +7 to +23
const hiddenAtomics = generateAtomics(({ theme }) => {
const conditions = {};

for (let i = 0; i < theme.breakpoints.keys.length; i += 1) {
const breakpoint = theme.breakpoints.keys[i];
conditions[`${theme.breakpoints.keys[i]}Only`] = theme.breakpoints.only(breakpoint);
conditions[`${theme.breakpoints.keys[i]}Up`] = theme.breakpoints.up(breakpoint);
conditions[`${theme.breakpoints.keys[i]}Down`] = theme.breakpoints.down(breakpoint);
}

return {
conditions,
properties: {
display: ['none'],
},
};
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gist of the logic.

@@ -6,5 +6,4 @@ export { generateAtomics, atomics } from './generateAtomics';
export { default as css } from './css';
export { default as createUseThemeProps } from './createUseThemeProps';
export { default as internal_createExtendSxProp } from './createExtendSxProp';
export { default as Box } from './Box';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brijeshb42 I have to remove this, otherwise the test fail due to "Cannot find a module ./Box". I believe that Box should be imported from @pigment-css/react/Box right?

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 18, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 19, 2024
@siriwatknp siriwatknp merged commit 690f15d into master Jun 19, 2024
17 of 18 checks passed
@siriwatknp siriwatknp deleted the react/hidden-css branch June 19, 2024 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Hidden The React component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants