import type { Meta, StoryObj } from "@storybook/react"; import type { ReactNode } from "react"; import type { GridItemProps, GridProps } from "."; import { Grid } from "."; import { Box } from "../Box"; import { Flex } from "../Flex"; import type { GridItem } from "./Item"; import { sizeOptions } from "../../utils"; import "./Grid.story.styles.css"; type StoryType = StoryObj; const meta: Meta = { title: "Layout/Grid", component: Grid, argTypes: { columns: { control: { type: "number" }, }, gap: { control: { type: "select" }, options: [...sizeOptions], }, rowGap: { control: { type: "select" }, options: [...sizeOptions], if: { arg: "gap", truthy: false, }, }, columnGap: { control: { type: "select" }, options: [...sizeOptions], if: { arg: "gap", truthy: false, }, }, alignContent: { control: { type: "select" }, options: [ "", "center", "space-around", "space-between", "space-evenly", "stretch", ], }, justifyContent: { control: { type: "select" }, options: [ "", "center", "start", "end", "space-around", "space-between", "space-evenly", ], }, alignItems: { control: { type: "select" }, options: ["", "center", "start", "end", "stretch", "baseline"], }, justifyItems: { control: { type: "select" }, options: ["", "start", "end", "center", "stretch"], }, }, decorators: [Story => ], }; type SharedProps = { children: ReactNode; }; const Card = ({ children, ...props }: SharedProps) => ( {children} ); const Square = ({ children, ...props }: SharedProps) => ( {children} ); const AlignSquare = ({ children, ...props }: SharedProps) => ( {children} ); export const AlignmentProperties: StoryType = { render: (args: GridProps) => ( 1 2 3 4 5 6 7 8 9 ), args: { columns: 12, gap: "xs", alignItems: "stretch", justifyItems: "stretch", className: "grid-example-fixed-size-grid", }, }; export const Default: StoryType = { render: (args: GridProps) => ( span=12 span=11 span=1 span=10 span=2 span=9 span=3 span=8 span=4 span=7 span=5 span=6 span=6 ), args: { columns: 12, gap: "xs", alignItems: "stretch", justifyItems: "stretch", }, }; export const EightColumns: StoryType = { render: (args: GridProps) => ( {[...new Array(8)].map((_, k) => ( span=1 ))} ), args: { columns: 8, gap: "xs", alignItems: "stretch", justifyItems: "stretch", className: "grid-example-eight-columns", }, }; export const Responsive: Meta = { render: (args: GridItemProps) => { const breakpointArgs = ["xs", "sm", "md", "lg", "xl", "xxl"]; const allArgs = Object.entries(args) .filter(([breakpoint]) => breakpointArgs.includes(breakpoint)) .map(([breakpoint, value]) => `${breakpoint}=${value}`) .join(" "); return ( {allArgs} lg=4 xs=5 span=5 ); }, args: { xs: 12, sm: 6, md: 2, lg: 8, xl: 12, xxl: 4, }, parameters: { controls: { exclude: ["columns"], }, }, }; export const ItemPositioning: Meta = { render: (args: GridItemProps) => ( 1 2 3 4 ), args: { alignSelf: "center", justifySelf: "end", }, argTypes: { alignSelf: { control: { type: "select" }, options: ["", "center", "start", "end", "stretch"], }, justifySelf: { control: { type: "select" }, options: ["", "center", "start", "end", "stretch"], }, }, parameters: { controls: { exclude: [ "columns", "gap", "rowGap", "columnGap", "alignContent", "justifyContent", "alignItems", "justifyItems", ], }, }, }; export default meta;