70160
Ce
cel-tui / files
cel-tui / packages / core / src / primitives / text.ts
922 bytes
1import type { TextNode, TextProps } from "@cel-tui/types"; 2 3/** 4 * Create a styled text leaf node. 5 * 6 * Text has no children and no sizing props — the parent container 7 * controls the box. Width is always parent-assigned. Height is intrinsic, 8 * computed from content, newlines (`\n`), and word-wrapping at the given width. 9 * 10 * Whitespace is always preserved. Content that exceeds the box is 11 * hard-clipped (no ellipsis). 12 * 13 * @param content - The text string to display. 14 * @param props - Styling, repeat, and wrapping props. 15 * @returns A text node for the UI tree. 16 * 17 * @example 18 * // Simple styled text 19 * Text("Hello", { bold: true, fgColor: "color06" }) 20 * 21 * // Horizontal divider 22 * Text("─", { repeat: "fill" }) 23 * 24 * // Word-wrapped paragraph 25 * Text(paragraph, { wrap: "word" }) 26 */ 27export function Text(content: string, props: TextProps = {}): TextNode { 28 return { type: "text", content, props }; 29}