import type { TailwindSize } from "./types" import "hono/jsx" import type { FC, PropsWithChildren, JSX } from "hono/jsx" import { VStack } from "./stack" import { Button } from "./button" import { Section } from "./section" import { H2, H3 } from "./text" import { CodeExamples } from "./code" import { cn } from "./cn" type GridProps = PropsWithChildren & { cols?: GridCols gap?: TailwindSize v?: keyof typeof alignItemsMap h?: keyof typeof justifyItemsMap class?: string style?: JSX.CSSProperties id?: string ref?: any } type GridCols = number | { sm?: number; md?: number; lg?: number; xl?: number } export const Grid: FC = (props) => { const { cols = 2, gap = 4, v, h, class: className, style, id, ref, children } = props const gapPx = gap * 4 const baseStyles: JSX.CSSProperties = { display: "grid", gridTemplateColumns: getColumnsValue(cols), gap: `${gapPx}px`, } if (v) { baseStyles.alignItems = alignItemsMap[v] } if (h) { baseStyles.justifyItems = justifyItemsMap[h] } const combinedStyles = { ...baseStyles, ...style, } return
{children}
} function getColumnsValue(cols: GridCols): string { if (typeof cols === "number") { return `repeat(${cols}, minmax(0, 1fr))` } // For responsive grids, we'll use the largest value // In a real implementation, you'd want media queries which require CSS // For now, let's use the largest value specified const largestCols = cols.xl || cols.lg || cols.md || cols.sm || 1 return `repeat(${largestCols}, minmax(0, 1fr))` } const alignItemsMap = { start: "start", center: "center", end: "end", stretch: "stretch", } as const const justifyItemsMap = { start: "start", center: "center", end: "end", stretch: "stretch", } as const export const Test = () => { return (
{/* API Usage Examples */} ...', '...', '...', '...', ]} />

Grid Examples

{/* Simple 3-column grid */}

Simple 3 columns: cols=3

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
{/* Responsive grid */}

Responsive: cols={sm: 1, md: 2, lg: 3}

Card 1
Card 2
Card 3
Card 4
{/* More responsive examples */}

More responsive: cols={sm: 2, lg: 4, xl: 6}

Item A
Item B
Item C
Item D
Item E
Item F
{/* Payment method example */}

Payment buttons example

{/* Alignment examples */}

Alignment: v="center" h="center"

Item 1
Item 2
Item 3

Alignment: v="start" h="end"

Left
Right
) }