import { define } from 'forge' import { theme } from './theme' import { H2 } from './text' import { RedBox, GreenBox, BlueBox } from './box' import { Grid } from './grid' import { Section } from './section' export const VStack = define('VStack', { display: 'flex', flexDirection: 'column', variants: { gap: { 0: { gap: 0 }, 1: { gap: theme('spacing-1') }, 2: { gap: theme('spacing-2') }, 3: { gap: theme('spacing-3') }, 4: { gap: theme('spacing-4') }, 6: { gap: theme('spacing-6') }, 8: { gap: theme('spacing-8') }, 12: { gap: theme('spacing-12') }, }, v: { start: { justifyContent: 'flex-start' }, center: { justifyContent: 'center' }, end: { justifyContent: 'flex-end' }, between: { justifyContent: 'space-between' }, around: { justifyContent: 'space-around' }, evenly: { justifyContent: 'space-evenly' }, }, h: { start: { alignItems: 'flex-start' }, center: { alignItems: 'center' }, end: { alignItems: 'flex-end' }, stretch: { alignItems: 'stretch' }, baseline: { alignItems: 'baseline' }, }, wrap: { flexWrap: 'wrap', }, }, render({ props, parts: { Root } }) { const { rows, style, ...rest } = props const gridStyle = rows ? { display: 'grid', gridTemplateRows: rows.map((r: number) => `${r}fr`).join(' '), ...style } : style return {props.children} }, }) export const HStack = define('HStack', { display: 'flex', flexDirection: 'row', variants: { gap: { 0: { gap: 0 }, 1: { gap: theme('spacing-1') }, 2: { gap: theme('spacing-2') }, 3: { gap: theme('spacing-3') }, 4: { gap: theme('spacing-4') }, 6: { gap: theme('spacing-6') }, 8: { gap: theme('spacing-8') }, 12: { gap: theme('spacing-12') }, }, h: { start: { justifyContent: 'flex-start' }, center: { justifyContent: 'center' }, end: { justifyContent: 'flex-end' }, between: { justifyContent: 'space-between' }, around: { justifyContent: 'space-around' }, evenly: { justifyContent: 'space-evenly' }, }, v: { start: { alignItems: 'flex-start' }, center: { alignItems: 'center' }, end: { alignItems: 'flex-end' }, stretch: { alignItems: 'stretch' }, baseline: { alignItems: 'baseline' }, }, wrap: { flexWrap: 'wrap', }, }, render({ props, parts: { Root } }) { const { cols, style, ...rest } = props const gridStyle = cols ? { display: 'grid', gridTemplateColumns: cols.map((c: number) => `${c}fr`).join(' '), ...style } : style return {props.children} }, }) type MainAxisOpts = 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly' type CrossAxisOpts = 'start' | 'center' | 'end' | 'stretch' | 'baseline' export const Test = () => { const mainAxisOpts: MainAxisOpts[] = ['start', 'center', 'end', 'between', 'around', 'evenly'] const crossAxisOpts: CrossAxisOpts[] = ['start', 'center', 'end', 'stretch', 'baseline'] return ( {/* 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% cols=[7, 3] 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 ) }