xonecas.io
70160
Ce

cel-tui / files

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

953 bytes
1import { Text } from "@cel-tui/core";
2import type { Color, TextNode } from "@cel-tui/types";
3
4/** Props for the {@link Divider} component. */
5export interface DividerProps {
6  /**
7   * Character to repeat across the width.
8   * @default "─"
9   */
10  char?: string;
11  /** Foreground color of the divider character. */
12  fgColor?: Color;
13}
14
15/**
16 * Horizontal divider that fills the available width.
17 *
18 * Renders a single character repeated to fill the parent's width
19 * using `Text` with `repeat: "fill"`.
20 *
21 * @param props - Divider character and color.
22 * @returns A text node that fills the available width.
23 *
24 * @example
25 * // Default thin line
26 * Divider()
27 *
28 * // Thick line with color
29 * Divider({ char: "━", fgColor: "color08" })
30 *
31 * // Double line
32 * Divider({ char: "═" })
33 */
34export function Divider(props: DividerProps = {}): TextNode {
35  const { char = "─", fgColor } = props;
36  return Text(char, { repeat: "fill", fgColor });
37}