diff --git a/packages/canon/report.api.md b/packages/canon/report.api.md index 093c2e10a3..c27b8da09b 100644 --- a/packages/canon/report.api.md +++ b/packages/canon/report.api.md @@ -200,7 +200,11 @@ export type Gap = Space | Partial>; // @public (undocumented) export const Grid: ForwardRefExoticComponent< GridProps & RefAttributes ->; +> & { + Item: ForwardRefExoticComponent< + GridItemProps & RefAttributes + >; +}; // @public (undocumented) export interface GridItemProps { diff --git a/packages/canon/src/components/Grid/Docs.mdx b/packages/canon/src/components/Grid/Docs.mdx index c9cefcb040..97c8dbbfb9 100644 --- a/packages/canon/src/components/Grid/Docs.mdx +++ b/packages/canon/src/components/Grid/Docs.mdx @@ -22,11 +22,11 @@ import { spacingProperties } from '../../layout/sprinkles.css'; The grid component is made of two parts: the grid container and the grid item. Import all parts and piece them together. ( - + );`} language="tsx" @@ -137,12 +137,12 @@ export default () => ( - + Hello World - - + + Hello World - + `} language="tsx" @@ -160,13 +160,13 @@ export default () => ( code={` Hello World - - + + Hello World - - + + Hello World - + `} language="tsx" @@ -199,9 +199,9 @@ export default () => ( - + Hello World - + `} language="tsx" diff --git a/packages/canon/src/components/Grid/Grid.stories.tsx b/packages/canon/src/components/Grid/Grid.stories.tsx index 2b9369f7ea..bf1bcecfd7 100644 --- a/packages/canon/src/components/Grid/Grid.stories.tsx +++ b/packages/canon/src/components/Grid/Grid.stories.tsx @@ -16,7 +16,7 @@ import React from 'react'; import type { Meta, StoryObj } from '@storybook/react'; -import { Grid, GridItem } from './Grid'; +import { Grid } from './Grid'; import type { GridItemProps } from './types'; import { Box } from '../Box/Box'; import { argTypesSpacing, argTypesColor } from '../../../docs/utils/argTypes'; @@ -83,12 +83,12 @@ export const ColumnSizes: Story = { {Array.from({ length: 11 }, (_, i) => ( - + - - + + - + ))} @@ -103,18 +103,18 @@ export const RowAndColumns: Story = { render: args => ( - + - - + + - - + + - + ), diff --git a/packages/canon/src/components/Grid/Grid.tsx b/packages/canon/src/components/Grid/Grid.tsx index 6f46963322..2b61d1d3d4 100644 --- a/packages/canon/src/components/Grid/Grid.tsx +++ b/packages/canon/src/components/Grid/Grid.tsx @@ -18,8 +18,7 @@ import { createElement, forwardRef } from 'react'; import { GridItemProps, GridProps } from './types'; import { gridItemSprinkles, gridSprinkles } from './sprinkles.css'; -/** @public */ -export const Grid = forwardRef((props, ref) => { +const GridBase = forwardRef((props, ref) => { const { children, columns, @@ -50,30 +49,30 @@ export const Grid = forwardRef((props, ref) => { ); }); +const GridItem = forwardRef((props, ref) => { + const { children, rowSpan, colSpan, start, end, className, style } = props; + + const sprinklesClassName = gridItemSprinkles({ + rowSpan, + colSpan, + start, + end, + }); + + const classNames = ['grid-item', sprinklesClassName, className] + .filter(Boolean) + .join(' '); + + return createElement( + 'div', + { + ref, + className: classNames, + style, + }, + children, + ); +}); + /** @public */ -export const GridItem = forwardRef( - (props, ref) => { - const { children, rowSpan, colSpan, start, end, className, style } = props; - - const sprinklesClassName = gridItemSprinkles({ - rowSpan, - colSpan, - start, - end, - }); - - const classNames = ['grid-item', sprinklesClassName, className] - .filter(Boolean) - .join(' '); - - return createElement( - 'div', - { - ref, - className: classNames, - style, - }, - children, - ); - }, -); +export const Grid = Object.assign(GridBase, { Item: GridItem });