diff --git a/packages/ui/src/Grid/index.stories.tsx b/packages/ui/src/Grid/index.stories.tsx index 13d2847812..2327e4a823 100644 --- a/packages/ui/src/Grid/index.stories.tsx +++ b/packages/ui/src/Grid/index.stories.tsx @@ -28,8 +28,8 @@ export const Demo: Story = { render: function Render() { return ( - - + + mobile=12 diff --git a/packages/ui/src/Grid/index.tsx b/packages/ui/src/Grid/index.tsx index 3f86ec2989..91472dc6b7 100644 --- a/packages/ui/src/Grid/index.tsx +++ b/packages/ui/src/Grid/index.tsx @@ -3,12 +3,19 @@ import styled from 'styled-components'; import { AsTransientProps, asTransientProps } from '../utils/asTransientProps'; import { media } from '../utils/media'; -interface GridContainerProps { +type GridElement = 'div' | 'main' | 'section'; + +interface BaseGridProps extends Record { + /** Which element to use. Defaults to `'div'`. */ + as?: GridElement; +} + +interface GridContainerProps extends BaseGridProps { /** Whether this is a grid container, vs. an item. */ container: true; } -interface GridItemProps extends Record { +interface GridItemProps extends BaseGridProps { /** Whether this is a grid container, vs. an item. */ container?: false; /** @@ -74,12 +81,18 @@ const Item = styled.div>>` * A responsive grid component that makes 12-column layouts super easy to build. * * Pass the `container` prop to the root `` component; then, any nested - * children ``s will be treated as grid items. + * children ``s will be treated as grid items. You can customize which + * HTML element to use for each grid container or item by passing the element's + * name via the optional `as` prop. + * + * Use the `` component — rather than styling your own HTML elements + * with `display: grid` — to ensure consistent behavior (such as grid gutters) + * throughout your app. * * @example * ```tsx - * - * This will span the full width on all screen sizes. + * + * This will span the full width on all screen sizes. * * So will this. * @@ -105,9 +118,11 @@ const Item = styled.div>>` * * ``` */ -export const Grid = ({ container, children, ...props }: GridProps) => +export const Grid = ({ container, children, as = 'div', ...props }: GridProps) => container ? ( - {children} + {children} ) : ( - {children} + + {children} + );