xonecas.io
70160
Ce

cel-tui / commit e551c70

feat(components): upgrade Button props, add VDivider

Button: style props now go on the HStack container (not Text),
enabling bgColor fill, focusStyle overrides, and style inheritance.
Added focused, onFocus, onBlur, focusStyle, onKeyPress, padding.

VDivider: new vertical divider component — 1-cell-wide VStack
with height 100%, renders a character on each row. Matches the
horizontal Divider API (char, fgColor).

xonecas2026-04-04 e551c7090fd8826e3a71b5d5b6a4904ad5311f82 parent b1f40b1

4 files changed

TODO.md+0−4
@@ -18,12 +18,8 @@ Remaining work, known bugs, and planned improvements.
1818
1919 ## API Improvements
2020
21-- ❌ **Upgrade `Button` component** — `Button` from `@cel-tui/components` doesn't forward `focusStyle`, `fgColor`, `bgColor`, or other container/style props to the underlying HStack. With uncontrolled focus and focusStyle now available, Button should accept these to be useful for keyboard navigation without inline HStack wrappers.
22-
2321 - ❌ **`repeat: "fill"` should claim flex space in HStack** — `Text(" ", { repeat: "fill" })` inside an HStack gets width 0 because its intrinsic width is 0 and no flex distributes remaining space. The workaround is `VStack({ flex: 1 }, [Text(" ", { repeat: "fill" })])`, which is non-obvious. Fix: either make `repeat: "fill"` imply flex behavior in the layout engine, or document the workaround prominently. The former is preferred.
2422
25-- ❌ **`VDivider` component** — Drawing a vertical divider requires `VStack({ width: 1, height: "100%" }, [Text("│", { repeat: "fill" })])`. A `VDivider({ char, fgColor })` component would match the existing horizontal `Divider` and reduce boilerplate.
26-
2723 ## Not Yet Implemented
2824
2925 - ❌ Bracketed paste mode support
packages/components/src/button.ts+48−14
@@ -1,21 +1,45 @@
1-import type { Color, ContainerNode } from "@cel-tui/types";
1+import type { ContainerNode, StyleProps } from "@cel-tui/types";
22 import { HStack, Text } from "@cel-tui/core";
33
4-/** Props for the {@link Button} component. */
5-export interface ButtonProps {
4+/**
5+ * Props for the {@link Button} component.
6+ *
7+ * Extends {@link StyleProps} — all style props (`fgColor`, `bgColor`,
8+ * `bold`, `italic`, `underline`) are set on the container and inherited
9+ * by the label text. This enables `focusStyle` to override them when
10+ * the button is focused.
11+ */
12+export interface ButtonProps extends StyleProps {
613 /** Called on mouse click or Enter when focused. */
714 onClick: () => void;
8- /** Render the label in bold. */
9- bold?: boolean;
10- /** Label text color. */
11- fgColor?: Color;
12- /** Label background color. */
13- bgColor?: Color;
1415 /**
1516 * Whether the button participates in focus traversal.
1617 * @default true
1718 */
1819 focusable?: boolean;
20+ /**
21+ * Whether this button is currently focused (controlled mode).
22+ * When provided, the app owns focus state and must update it
23+ * via {@link onFocus}/{@link onBlur}.
24+ */
25+ focused?: boolean;
26+ /** Called when the button receives focus. */
27+ onFocus?: () => void;
28+ /** Called when the button loses focus. */
29+ onBlur?: () => void;
30+ /**
31+ * Style overrides applied when focused. Overridden values
32+ * participate in inheritance — the label text sees the
33+ * focused styles as its defaults.
34+ */
35+ focusStyle?: StyleProps;
36+ /**
37+ * Key event handler. Receives keys that bubble up to this button.
38+ * Return `false` to keep bubbling.
39+ */
40+ onKeyPress?: (key: string) => boolean | void;
41+ /** Internal padding in cells. */
42+ padding?: { x?: number; y?: number };
1943 }
2044
2145 /**
@@ -25,20 +49,30 @@ export interface ButtonProps {
2549 * a styled `Text` node. Focusable by default — reachable via Tab and
2650 * activated with Enter.
2751 *
52+ * Style props are set on the container, not the text — this means
53+ * `bgColor` fills the button rect and `focusStyle` can override
54+ * any style when focused.
55+ *
2856 * @param label - Button text.
29- * @param props - Click handler and styling.
57+ * @param props - Click handler, styling, and focus configuration.
3058 * @returns A clickable container node.
3159 *
3260 * @example
61+ * // Basic styled button
3362 * Button("[Send]", { onClick: handleSend, bold: true, fgColor: "cyan" })
3463 *
3564 * @example
65+ * // Button with focus style (keyboard navigation)
66+ * Button("[OK]", {
67+ * onClick: handleOk,
68+ * bgColor: "brightBlack",
69+ * focusStyle: { bgColor: "green", fgColor: "black" },
70+ * })
71+ *
72+ * @example
3673 * // Mouse-only button (not in Tab order)
3774 * Button("✕", { onClick: handleClose, focusable: false })
3875 */
3976 export function Button(label: string, props: ButtonProps): ContainerNode {
40- const { onClick, bold, fgColor, bgColor, focusable } = props;
41- return HStack({ onClick, focusable }, [
42- Text(label, { bold, fgColor, bgColor }),
43- ]);
77+ return HStack(props, [Text(label)]);
4478 }
packages/components/src/index.ts+1−0
@@ -18,6 +18,7 @@
1818
1919 export { Spacer } from "./spacer.js";
2020 export { Divider, type DividerProps } from "./divider.js";
21+export { VDivider, type VDividerProps } from "./vdivider.js";
2122 export { Button, type ButtonProps } from "./button.js";
2223 export {
2324 Select,
packages/components/src/vdivider.ts+50−0
@@ -0,0 +1,50 @@
1+import type { Color, ContainerNode } from "@cel-tui/types";
2+import { VStack, Text } from "@cel-tui/core";
3+
4+/** Props for the {@link VDivider} component. */
5+export 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.
17+const 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: "brightBlack" })
38+ *
39+ * // Separate sidebar from content
40+ * HStack({ height: "100%" }, [
41+ * VStack({ width: 20 }, [Text("sidebar")]),
42+ * VDivider({ fgColor: "brightBlack" }),
43+ * VStack({ flex: 1 }, [Text("content")]),
44+ * ])
45+ */
46+export 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+}