Skip to content

Commit

Permalink
Update Grid component
Browse files Browse the repository at this point in the history
Signed-off-by: Charles de Dreuille <[email protected]>
  • Loading branch information
cdedreuille committed Dec 19, 2024
1 parent 9164389 commit 58ecccb
Show file tree
Hide file tree
Showing 12 changed files with 491 additions and 88 deletions.
14 changes: 14 additions & 0 deletions packages/canon/src/components/Grid/Grid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ export const Default: Story = {
),
};

export const Test: Story = {
args: {
columns: 12,
gap: 'md',
},
render: args => (
<Grid {...args}>
<FakeBox />
<FakeBox />
<FakeBox />
</Grid>
),
};

export const LargeGap: Story = {
args: {
gap: 'lg',
Expand Down
56 changes: 24 additions & 32 deletions packages/canon/src/components/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,54 @@

import { createElement, forwardRef } from 'react';
import { GridItemProps, GridProps } from './types';
import { gridItemSprinkles, gridSprinkles } from './sprinkles.css';
import { getClassNames } from '../../utils/getClassNames';

const GridBase = forwardRef<HTMLDivElement, GridProps>((props, ref) => {
const {
children,
columns,
gap = 'xs',
columns = 'auto',
className,
style,
...restProps
} = props;

const sprinklesClassName = gridSprinkles({
...restProps,
gap,
gridTemplateColumns: columns ? columns : 'auto',
});
const utilityClassNames = getClassNames({ gap, columns, ...restProps });

const classNames = ['grid', sprinklesClassName, className]
const classNames = ['canon-grid', utilityClassNames, className]
.filter(Boolean)
.join(' ');

return createElement(
'div',
{
ref,
className: classNames,
style,
},
return createElement('div', {
ref,
className: classNames,
style,
children,
);
});
});

const GridItem = forwardRef<HTMLDivElement, GridItemProps>((props, ref) => {
const { children, rowSpan, colSpan, start, end, className, style } = props;
const { children, className, style, ...restProps } = props;

const sprinklesClassName = gridItemSprinkles({
rowSpan,
colSpan,
start,
end,
});
const utilityClassNames = getClassNames(restProps);

const classNames = ['grid-item', sprinklesClassName, className]
// const sprinklesClassName = gridItemSprinkles({
// rowSpan,
// colSpan,
// start,
// end,
// });

const classNames = ['grid-item', utilityClassNames, className]
.filter(Boolean)
.join(' ');

return createElement(
'div',
{
ref,
className: classNames,
style,
},
return createElement('div', {
ref,
className: classNames,
style,
children,
);
});
});

/** @public */
Expand Down
2 changes: 1 addition & 1 deletion packages/canon/src/components/Grid/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.grid {
.canon-grid {
display: grid;
}
20 changes: 9 additions & 11 deletions packages/canon/src/components/Grid/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ColorProps } from '../../layout/types';
import { SpaceProps } from '../../layout/types';
import type { Breakpoint } from '../../types';
/** @public */
export type Columns = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;

import type { UtilityProps, SpaceProps } from '../../types';

/** @public */
export interface GridProps extends SpaceProps, ColorProps {
export interface GridProps extends SpaceProps {
children?: React.ReactNode;
columns?: Columns | Partial<Record<Breakpoint, Columns>>;
className?: string;
columns?: UtilityProps['columns'];
gap?: UtilityProps['gap'];
style?: React.CSSProperties;
}

/** @public */
export interface GridItemProps {
children: React.ReactNode;
rowSpan?: Columns | 'full';
colSpan?: Columns | 'full';
start?: Columns | 'auto';
end?: Columns | 'auto';
className?: string;
colSpan?: UtilityProps['colSpan'];
colEnd?: UtilityProps['colEnd'];
colStart?: UtilityProps['colStart'];
rowSpan?: UtilityProps['rowSpan'];
style?: React.CSSProperties;
}
52 changes: 52 additions & 0 deletions packages/canon/src/css/utilities/2xl.css
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,57 @@
.cu-2xl-wrap-reverse {
flex-wrap: wrap-reverse;
}

.cu-2xl-grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}

.cu-2xl-grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cu-2xl-grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cu-2xl-grid-cols-4 {
grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cu-2xl-grid-cols-5 {
grid-template-columns: repeat(5, minmax(0, 1fr));
}

.cu-2xl-grid-cols-6 {
grid-template-columns: repeat(6, minmax(0, 1fr));
}

.cu-2xl-grid-cols-7 {
grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cu-2xl-grid-cols-8 {
grid-template-columns: repeat(8, minmax(0, 1fr));
}

.cu-2xl-grid-cols-9 {
grid-template-columns: repeat(9, minmax(0, 1fr));
}

.cu-2xl-grid-cols-10 {
grid-template-columns: repeat(10, minmax(0, 1fr));
}

.cu-2xl-grid-cols-11 {
grid-template-columns: repeat(11, minmax(0, 1fr));
}

.cu-2xl-grid-cols-12 {
grid-template-columns: repeat(12, minmax(0, 1fr));
}

.cu-2xl-grid-cols-auto {
grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}
}
}
52 changes: 52 additions & 0 deletions packages/canon/src/css/utilities/lg.css
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,57 @@
.cu-lg-wrap-reverse {
flex-wrap: wrap-reverse;
}

.cu-lg-grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}

.cu-lg-grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cu-lg-grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cu-lg-grid-cols-4 {
grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cu-lg-grid-cols-5 {
grid-template-columns: repeat(5, minmax(0, 1fr));
}

.cu-lg-grid-cols-6 {
grid-template-columns: repeat(6, minmax(0, 1fr));
}

.cu-lg-grid-cols-7 {
grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cu-lg-grid-cols-8 {
grid-template-columns: repeat(8, minmax(0, 1fr));
}

.cu-lg-grid-cols-9 {
grid-template-columns: repeat(9, minmax(0, 1fr));
}

.cu-lg-grid-cols-10 {
grid-template-columns: repeat(10, minmax(0, 1fr));
}

.cu-lg-grid-cols-11 {
grid-template-columns: repeat(11, minmax(0, 1fr));
}

.cu-lg-grid-cols-12 {
grid-template-columns: repeat(12, minmax(0, 1fr));
}

.cu-lg-grid-cols-auto {
grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}
}
}
52 changes: 52 additions & 0 deletions packages/canon/src/css/utilities/md.css
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,57 @@
.cu-md-wrap-reverse {
flex-wrap: wrap-reverse;
}

.cu-md-grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}

.cu-md-grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cu-md-grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cu-md-grid-cols-4 {
grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cu-md-grid-cols-5 {
grid-template-columns: repeat(5, minmax(0, 1fr));
}

.cu-md-grid-cols-6 {
grid-template-columns: repeat(6, minmax(0, 1fr));
}

.cu-md-grid-cols-7 {
grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cu-md-grid-cols-8 {
grid-template-columns: repeat(8, minmax(0, 1fr));
}

.cu-md-grid-cols-9 {
grid-template-columns: repeat(9, minmax(0, 1fr));
}

.cu-md-grid-cols-10 {
grid-template-columns: repeat(10, minmax(0, 1fr));
}

.cu-md-grid-cols-11 {
grid-template-columns: repeat(11, minmax(0, 1fr));
}

.cu-md-grid-cols-12 {
grid-template-columns: repeat(12, minmax(0, 1fr));
}

.cu-md-grid-cols-auto {
grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}
}
}
52 changes: 52 additions & 0 deletions packages/canon/src/css/utilities/sm.css
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,57 @@
.cu-sm-wrap-reverse {
flex-wrap: wrap-reverse;
}

.cu-sm-grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}

.cu-sm-grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cu-sm-grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cu-sm-grid-cols-4 {
grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cu-sm-grid-cols-5 {
grid-template-columns: repeat(5, minmax(0, 1fr));
}

.cu-sm-grid-cols-6 {
grid-template-columns: repeat(6, minmax(0, 1fr));
}

.cu-sm-grid-cols-7 {
grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cu-sm-grid-cols-8 {
grid-template-columns: repeat(8, minmax(0, 1fr));
}

.cu-sm-grid-cols-9 {
grid-template-columns: repeat(9, minmax(0, 1fr));
}

.cu-sm-grid-cols-10 {
grid-template-columns: repeat(10, minmax(0, 1fr));
}

.cu-sm-grid-cols-11 {
grid-template-columns: repeat(11, minmax(0, 1fr));
}

.cu-sm-grid-cols-12 {
grid-template-columns: repeat(12, minmax(0, 1fr));
}

.cu-sm-grid-cols-auto {
grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}
}
}
Loading

0 comments on commit 58ecccb

Please sign in to comment.