xonecas.io
70160
Ce

cel-tui / files

cel-tui / packages / components / src / vdivider.ts

1.6 KB
1import { Text, VStack } from "@cel-tui/core";
2import type { Color, ContainerNode } from "@cel-tui/types";
3
4/** Props for the {@link VDivider} component. */
5export interface VDividerProps {
6  /**
7   * Character to repeat down the height.
8   * @default "│"
9   */
10  char?: string;
11  /** Foreground color of the divider character. */
12  fgColor?: Color;
13}
14
15// Pre-built content string: 500 lines is enough for any terminal.
16// Paint clips to the container rect, so excess lines are free.
17const MAX_LINES = 500;
18
19/**
20 * Vertical divider that fills the available height.
21 *
22 * Renders a single character on each row within a 1-cell-wide container.
23 * Best used inside an `HStack` to separate columns.
24 *
25 * The container uses `height: "100%"` so it fills the parent's cross
26 * axis. In an HStack with the default `alignItems: "stretch"`, it
27 * automatically matches sibling heights.
28 *
29 * @param props - Divider character and color.
30 * @returns A container node 1 cell wide, full parent height.
31 *
32 * @example
33 * // Default thin vertical line
34 * VDivider()
35 *
36 * // Double line with color
37 * VDivider({ char: "║", fgColor: "color08" })
38 *
39 * // Separate sidebar from content
40 * HStack({ height: "100%" }, [
41 *   VStack({ width: 20 }, [Text("sidebar")]),
42 *   VDivider({ fgColor: "color08" }),
43 *   VStack({ flex: 1 }, [Text("content")]),
44 * ])
45 */
46export function VDivider(props: VDividerProps = {}): ContainerNode {
47  const { char = "│", fgColor } = props;
48  const content = Array.from({ length: MAX_LINES }, () => char).join("\n");
49  return VStack({ width: 1, height: "100%" }, [Text(content, { fgColor })]);
50}