Skip to content

Commit

Permalink
Improve gridAtomics
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Jun 18, 2024
1 parent e5568d3 commit daa5ae3
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/pigment-css-react/src/Grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ function isGridComponent(element) {
return element.type.muiName === 'Grid' || element.type?._payload?.value?.muiName === 'Grid';
}

export const gridAtomics = generateAtomics(({ theme }) => ({
conditions: Object.keys(theme.breakpoints.values).reduce((acc, breakpoint) => {
acc[breakpoint] = `@media (min-width: ${theme.breakpoints.values[breakpoint]}${
theme.breakpoints.unit ?? 'px'
})`;
return acc;
}, {}),
defaultCondition: theme.breakpoints?.keys?.[0] ?? 'xs',
export const gridAtomics = generateAtomics(({ theme }) => {
const conditions = {};
Object.entries(theme.breakpoints.values)
.sort((a, b) => a[1] - b[1])
.forEach(([breakpoint, value]) => {
conditions[breakpoint] = `@media (min-width: ${value}${theme.breakpoints.unit ?? 'px'})`;
});
return {
conditions,
defaultCondition: theme.breakpoints?.keys?.[0],
properties: {
flexDirection: ['column', 'column-reverse', 'row', 'row-reverse'],
'--Grid-parent-column-count': ['--Grid-parent-column-count'],
Expand All @@ -36,9 +38,6 @@ export const gridAtomics = generateAtomics(({ theme }) => ({
'--Grid-self-offset': ['--Grid-self-offset'],
'--Grid-self-margin-left': ['--Grid-self-margin-left'],
},
shorthands: {
direction: ['flexDirection'],
},
unitless: ['--Grid-parent-column-count', '--Grid-self-column-span', '--Grid-self-offset'],
multipliers: {
'--Grid-parent-column-spacing': Array.isArray(theme.vars?.spacing)
Expand Down Expand Up @@ -96,7 +95,7 @@ export const gridAtomics = generateAtomics(({ theme }) => ({
return 'var(--Grid-fixed-offset)';
},
},
}));
}});

const GridComponent = styled('div')({
'--Grid-fixed-width':
Expand Down Expand Up @@ -159,7 +158,7 @@ const Grid = React.forwardRef(function Grid(
const selfRowSpacing = rowSpacing ?? spacing ?? unstable_parent_row_spacing ?? 0;

const gridAtomicsObj = {
direction,
flexDirection: direction,
};

if (unstable_parent_columns !== undefined) {
Expand Down

0 comments on commit daa5ae3

Please sign in to comment.