import type { TailwindSize } from "./types" import "hono/jsx" import type { FC, PropsWithChildren, JSX } from "hono/jsx" import { Grid } from "./grid" import { Section } from "./section" import { H2 } from "./text" import { RedBox, GreenBox, BlueBox } from "./box" import { CodeExamples } from "./code" import { cn } from "./cn" export const VStack: FC = (props) => { return ( {props.children} ) } export const HStack: FC = (props) => { return ( {props.children} ) } const Stack: FC = (props) => { const gapPx = props.gap ? props.gap * 4 : 0 // Use CSS Grid when gridSizes (cols/rows) is provided if (props.gridSizes) { const gridTemplate = props.gridSizes.map(size => `${size}fr`).join(" ") const gridStyles: JSX.CSSProperties = { display: "grid", gap: `${gapPx}px`, maxWidth: props.maxWidth, } if (props.direction === "row") { gridStyles.gridTemplateColumns = gridTemplate } else { gridStyles.gridTemplateRows = gridTemplate } const combinedStyles = { ...gridStyles, ...props.style, } return
{props.children}
} // Default flexbox behavior const baseStyles: JSX.CSSProperties = { display: "flex", flexDirection: props.direction === "row" ? "row" : "column", flexWrap: props.wrap ? "wrap" : "nowrap", gap: `${gapPx}px`, maxWidth: props.maxWidth, } if (props.mainAxis) { baseStyles.justifyContent = getJustifyContent(props.mainAxis) } if (props.crossAxis) { baseStyles.alignItems = getAlignItems(props.crossAxis) } const combinedStyles = { ...baseStyles, ...props.style, } return
{props.children}
} export const Test = () => { const mainAxisOpts: MainAxisOpts[] = ["start", "center", "end", "between", "around", "evenly"] const crossAxisOpts: CrossAxisOpts[] = ["start", "center", "end", "stretch", "baseline"] return (
{/* API Usage Examples */} ...', '...', '...', '...', '...', '...', ]} /> {/* HStack layout matrix */}

HStack Layout

{/* Header row: blank + h labels */}
{mainAxisOpts.map((h) => (
h: {h}
))} {/* Each row: v label + HStack cells */} {crossAxisOpts.map((v) => [
v: {v}
, ...mainAxisOpts.map((h) => ( Aa Aa Aa )), ])}
{/* VStack layout matrix */}

VStack Layout

{/* Header row: blank + h labels */}
{crossAxisOpts.map((h) => (
h: {h}
))} {/* Each row: v label + VStack cells */} {mainAxisOpts.map((v) => [
v: {v}
, ...crossAxisOpts.map((h) => ( Aa Aa Aa )), ])}
{/* Custom column sizing */}

HStack with Custom Column Sizing

cols=[7, 3] (70%/30% split)
70% width
30% width
cols=[2, 1] (66%/33% split)
2/3 width
1/3 width
cols=[1, 2, 1] (25%/50%/25% split)
25%
50%
25%
With maxWidth="600px"
70% of max 600px
30% of max 600px
{/* Custom row sizing */}

VStack with Custom Row Sizing

rows=[2, 1] (2/3 and 1/3 height)
2/3 height
1/3 height
) } type StackDirection = "row" | "col" type StackProps = { direction: StackDirection mainAxis?: string crossAxis?: string wrap?: boolean gap?: TailwindSize maxWidth?: string gridSizes?: number[] // cols for row, rows for col componentName?: string // for data-howl attribute class?: string style?: JSX.CSSProperties children?: any } type MainAxisOpts = "start" | "center" | "end" | "between" | "around" | "evenly" type CrossAxisOpts = "start" | "center" | "end" | "stretch" | "baseline" type CommonStackProps = PropsWithChildren & { wrap?: boolean gap?: TailwindSize maxWidth?: string class?: string style?: JSX.CSSProperties } type VStackProps = CommonStackProps & { v?: MainAxisOpts // main axis for vertical stack h?: CrossAxisOpts // cross axis for vertical stack rows?: number[] // custom row sizing (e.g., [7, 3] for 70%/30%) } type HStackProps = CommonStackProps & { h?: MainAxisOpts // main axis for horizontal stack v?: CrossAxisOpts // cross axis for horizontal stack cols?: number[] // custom column sizing (e.g., [7, 3] for 70%/30%) } function getJustifyContent(axis: string): string { const map: Record = { start: "flex-start", center: "center", end: "flex-end", between: "space-between", around: "space-around", evenly: "space-evenly", } return map[axis] || "flex-start" } function getAlignItems(axis: string): string { const map: Record = { start: "flex-start", center: "center", end: "flex-end", stretch: "stretch", baseline: "baseline", } return map[axis] || "stretch" }