xonecas.io
70160
Ce

cel-tui / files

cel-tui / packages / core / src / primitives / stacks.ts

1.3 KB
1import type { ContainerNode, ContainerProps, Node } from "@cel-tui/types";
2
3/**
4 * Create a vertical stack container — children laid out top to bottom.
5 *
6 * Equivalent to CSS `flex-direction: column`. Main axis is vertical,
7 * cross axis is horizontal.
8 *
9 * @param props - Layout, sizing, scrolling, focus, and interaction props.
10 * @param children - Ordered child nodes.
11 * @returns A container node for the UI tree.
12 *
13 * @example
14 * VStack({ flex: 1, gap: 1 }, [
15 *   Text("Hello"),
16 *   Text("World"),
17 * ])
18 */
19export function VStack(props: ContainerProps, children: Node[]): ContainerNode {
20  return { type: "vstack", props, children };
21}
22
23/**
24 * Create a horizontal stack container — children laid out left to right.
25 *
26 * Equivalent to CSS `flex-direction: row`. Main axis is horizontal,
27 * cross axis is vertical.
28 *
29 * @param props - Layout, sizing, scrolling, focus, and interaction props.
30 * @param children - Ordered child nodes.
31 * @returns A container node for the UI tree.
32 *
33 * @example
34 * HStack({ height: 1, gap: 1 }, [
35 *   Text("Name", { bold: true }),
36 *   VStack({ flex: 1 }, []),
37 *   Text("value", { fgColor: "color08" }),
38 * ])
39 */
40export function HStack(props: ContainerProps, children: Node[]): ContainerNode {
41  return { type: "hstack", props, children };
42}