Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add ItemHeader and EmptyState

Bitti589f5869fb2e
diff --git a/src/components/ui/Pane.test.tsx b/src/components/ui/Pane.test.tsx
new file mode 100644
index 0000000..b107b33
--- /dev/null
+++ b/src/components/ui/Pane.test.tsx
@@ -0,0 +1,111 @@
+// @vitest-environment jsdom
+
+import "@testing-library/jest-dom/vitest";
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { useState } from "react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { PaneHeader } from "./Chrome";
+import { SelectorBar } from "./Controls";
+import { EmptyState, ItemHeader } from "./Pane";
+import { PropSection } from "./PropRow";
+
+beforeEach(() => localStorage.clear());
+afterEach(cleanup);
+
+describe("ItemHeader", () => {
+ it("names the item as a heading with a kind chip, a meta line and actions", () => {
+ const { container } = render(
+ <ItemHeader
+ id="clip-name"
+ color="var(--clip-generated)"
+ icon={<svg data-testid="glyph" />}
+ name="Lanterns drift upward"
+ meta="Generated video · V1 · 6.2 s"
+ actions={<button type="button">More</button>}
+ />,
+ );
+ expect(screen.getByRole("heading", { level: 2, name: "Lanterns drift upward" })).toHaveAttribute("id", "clip-name");
+ expect(screen.getByText("Generated video · V1 · 6.2 s")).toHaveClass("ui-item-header__meta");
+ expect(screen.getByRole("button", { name: "More" })).toBeInTheDocument();
+ const chip = container.querySelector(".ui-item-header__chip") as HTMLElement;
+ expect(chip).toHaveAttribute("aria-hidden", "true");
+ expect(chip).toContainElement(screen.getByTestId("glyph"));
+ expect(chip.style.getPropertyValue("--item-kind")).toBe("var(--clip-generated)");
+ });
+
+ it("takes an editable name and a custom chip, and drops the chip when given none", () => {
+ function Rename() {
+ const [name, setName] = useState("Shot 1");
+ return <ItemHeader name={<input className="ui-item-header__input" aria-label="Shot name" value={name} onChange={(event) => setName(event.target.value)} />} />;
+ }
+ const view = render(<Rename />);
+ expect(screen.queryByRole("heading")).not.toBeInTheDocument();
+ expect(view.container.querySelector(".ui-item-header__chip")).toBeNull();
+ fireEvent.change(screen.getByRole("textbox", { name: "Shot name" }), { target: { value: "Shot 2" } });
+ expect(screen.getByRole("textbox", { name: "Shot name" })).toHaveValue("Shot 2");
+ view.unmount();
+
+ const { container } = render(<ItemHeader name="Hero" chip={<img alt="" src="data:," />} level={3} />);
+ expect(screen.getByRole("heading", { level: 3, name: "Hero" })).toBeInTheDocument();
+ expect(container.querySelector(".ui-item-header__chip--custom img")).toBeInTheDocument();
+ });
+});
+
+describe("EmptyState", () => {
+ it("shows a glyph, a title, one sentence and an action", () => {
+ const onImport = vi.fn();
+ const { container } = render(
+ <EmptyState
+ icon={<svg data-testid="glyph" />}
+ title="No media yet"
+ description="Import video, images or audio."
+ action={<button type="button" onClick={onImport}>Import</button>}
+ />,
+ );
+ expect(screen.getByText("No media yet")).toHaveClass("ui-empty-state__title");
+ expect(screen.getByText("Import video, images or audio.")).toHaveClass("ui-empty-state__description");
+ expect(container.querySelector(".ui-empty-state__icon")).toHaveAttribute("aria-hidden", "true");
+ fireEvent.click(screen.getByRole("button", { name: "Import" }));
+ expect(onImport).toHaveBeenCalled();
+ });
+
+ it("needs only a title", () => {
+ const { container } = render(<EmptyState title="Nothing selected" />);
+ expect(container.querySelector(".ui-empty-state__icon, .ui-empty-state__description, .ui-empty-state__action")).toBeNull();
+ });
+});
+
+describe("PaneHeader as a toolbar", () => {
+ it("works with no title: compact views lead, actions trail", () => {
+ const onChange = vi.fn();
+ const { container } = render(
+ <PaneHeader
+ views={<SelectorBar compact aria-label="Sources" value="scenes" onChange={onChange} items={[{ value: "scenes", label: "Scenes" }, { value: "media", label: "Media" }]} />}
+ actions={<button type="button">Import</button>}
+ />,
+ );
+ expect(screen.queryByRole("heading")).not.toBeInTheDocument();
+ expect(screen.getByRole("tablist", { name: "Sources" })).toHaveClass("ui-selector-bar--compact");
+ expect(container.querySelector(".ui-pane-header__views")).toContainElement(screen.getByRole("tablist"));
+ expect(container.querySelector(".ui-pane-header__actions")).toContainElement(screen.getByRole("button", { name: "Import" }));
+ fireEvent.click(screen.getByRole("tab", { name: "Media" }));
+ expect(onChange).toHaveBeenCalledWith("media");
+ });
+});
+
+describe("PropSection summary", () => {
+ it("shows the summary in the header whether open or collapsed", () => {
+ render(<PropSection title="Transform" summary="1 changed"><span>rows</span></PropSection>);
+ const toggle = screen.getByRole("button", { name: /Transform/ });
+ expect(screen.getByText("1 changed")).toHaveClass("ui-prop-section__summary");
+ fireEvent.click(toggle);
+ expect(toggle).toHaveAttribute("aria-expanded", "false");
+ expect(screen.getByText("1 changed")).toBeVisible();
+ expect(screen.getByText("rows")).not.toBeVisible();
+ });
+
+ it("renders no summary element without one", () => {
+ const { container } = render(<PropSection title="Timing" summary={null} />);
+ expect(container.querySelector(".ui-prop-section__summary")).toBeNull();
+ });
+});
diff --git a/src/components/ui/Pane.tsx b/src/components/ui/Pane.tsx
new file mode 100644
index 0000000..89a96eb
--- /dev/null
+++ b/src/components/ui/Pane.tsx
@@ -0,0 +1,102 @@
+/* Pane anatomy: ItemHeader and EmptyState.
+
+ A pane is headed by what it holds, never by a title bar. When it shows one
+ selected thing, an ItemHeader names it; when it has views or actions, a
+ PaneHeader (Chrome.tsx) is its toolbar; when it has nothing to show, an
+ EmptyState says so and offers the way forward.
+
+ <ItemHeader
+ color="var(--clip-generated)" icon={<Sparkles size={16} />}
+ name={<input className="ui-item-header__input" value={name} … aria-label="Clip name" />}
+ meta="Generated video · V1 · 6.2 s"
+ actions={<button className="icon-button" aria-label="More">…</button>} />
+
+ <EmptyState icon={<Film size={32} />} title="No media yet"
+ description="Import video, images or audio to use them on the timeline."
+ action={<button className="secondary-button" …>Import</button>} />
+*/
+
+import type { CSSProperties, ReactNode } from "react";
+import { cx } from "./internal";
+
+/* --- ItemHeader ---------------------------------------------------------------
+ 48px (--item-header) on --surface-chrome with a --stroke-divider bottom
+ edge: a 28px kind chip, the name at 14px semibold over one muted 12px meta
+ line (kind, location, length), and actions (usually a ⋯ button) on the
+ trailing edge. The name is a heading when it is text; pass a node instead
+ to make it editable in place (an <input className="ui-item-header__input">
+ reads as the heading until it is hovered or focused). */
+
+export interface ItemHeaderProps {
+ /** The item's name: text (rendered as a heading) or a node such as an editable input. */
+ name: ReactNode;
+ /** One muted line under the name: kind, location, length. */
+ meta?: ReactNode;
+ /** The kind glyph shown white on the kind colour. */
+ icon?: ReactNode;
+ /** The chip's fill, a CSS colour — usually a kind token: "var(--clip-video)". */
+ color?: string;
+ /** Replaces the icon chip entirely (a thumbnail, a reference's art); still 28px. */
+ chip?: ReactNode;
+ /** Trailing controls, compact icon buttons. */
+ actions?: ReactNode;
+ /** Id for the name heading, so the pane can be aria-labelledby it. */
+ id?: string;
+ /** Heading level for a text name (default 2). */
+ level?: 2 | 3 | 4;
+ className?: string;
+}
+
+export function ItemHeader({ name, meta, icon, color, chip, actions, id, level = 2, className }: ItemHeaderProps) {
+ const Heading = `h${level}` as "h2";
+ const text = typeof name === "string" || typeof name === "number";
+ const hasChip = chip !== undefined || icon !== undefined || color !== undefined;
+ return (
+ <div className={cx("ui-item-header", className)}>
+ {hasChip && (
+ <span
+ className={cx("ui-item-header__chip", chip !== undefined && "ui-item-header__chip--custom")}
+ style={color ? ({ "--item-kind": color } as CSSProperties) : undefined}
+ aria-hidden="true"
+ >
+ {chip ?? icon}
+ </span>
+ )}
+ <div className="ui-item-header__text">
+ {text
+ ? <Heading id={id} className="ui-item-header__name">{name}</Heading>
+ : <div id={id} className="ui-item-header__name ui-item-header__name--custom">{name}</div>}
+ {meta && <div className="ui-item-header__meta">{meta}</div>}
+ </div>
+ {actions && <div className="ui-item-header__actions">{actions}</div>}
+ </div>
+ );
+}
+
+/* --- EmptyState ---------------------------------------------------------------
+ The compact empty state every pane shares: a 32px glyph, a 14px semibold
+ title, one muted sentence and at most one action, centred in whatever
+ contains it. The Library's large hero is the one exception and keeps its
+ own markup. */
+
+export interface EmptyStateProps {
+ title: ReactNode;
+ /** One muted sentence: why it is empty, or how to fill it. */
+ description?: ReactNode;
+ /** A 32px glyph. */
+ icon?: ReactNode;
+ /** One button: the way forward. */
+ action?: ReactNode;
+ className?: string;
+}
+
+export function EmptyState({ title, description, icon, action, className }: EmptyStateProps) {
+ return (
+ <div className={cx("ui-empty-state", className)}>
+ {icon && <span className="ui-empty-state__icon" aria-hidden="true">{icon}</span>}
+ <p className="ui-empty-state__title">{title}</p>
+ {description && <p className="ui-empty-state__description">{description}</p>}
+ {action && <div className="ui-empty-state__action">{action}</div>}
+ </div>
+ );
+}
diff --git a/src/components/ui/index.ts b/src/components/ui/index.ts
index 0e63b20..8cf2d99 100644
--- a/src/components/ui/index.ts
+++ b/src/components/ui/index.ts
@@ -27,7 +27,8 @@
SettingsCard <SettingsCard icon header description>{control}</SettingsCard>; onClick → chevron, href → external.
SettingsExpander <SettingsExpander icon header description control={…}>{<SettingsRow …/>}</SettingsExpander>
SettingsRow <SettingsRow header description>{control}</SettingsRow> (inside an expander).
- PropSection <PropSection title="Transform" persistKey="clip.transform" actions={…}>rows…</PropSection>
+ PropSection <PropSection title="Transform" persistKey="clip.transform" summary="1 changed" actions={…}>rows…</PropSection>
+ 28px header on chrome; `summary` is right-aligned and stays visible when collapsed.
PropRow <PropRow label htmlFor value defaultValue onReset scrub={{ value, onChange, step, min, max }}>{field}</PropRow>
ContextMenu <ContextMenu items position={{x,y}|{anchor}} onClose aria-label /> (controlled).
useContextMenu const menu = useContextMenu(); onContextMenu={(e) => menu.open(e, items)}; render {menu.element}.
@@ -43,13 +44,25 @@
ProgressRing <ProgressRing size={16|20|32} value? aria-label />
InfoBadge <InfoBadge value={3} severity="attention" /> or a dot without value.
Expander <Expander header description icon defaultExpanded>{content}</Expander>
- SelectorBar <SelectorBar items={[{value,label}]} value onChange aria-label /> (tablist).
+ SelectorBar <SelectorBar items={[{value,label}]} value onChange aria-label compact? /> (tablist;
+ compact = the 24px segmented form for a pane toolbar).
CommandBar <CommandBar aria-label end={…}><CommandBarButton icon label shortcut onClick /><CommandBarSeparator/></CommandBar>
- PaneHeader <PaneHeader title="Inspector" actions={…} />
+ PaneHeader <PaneHeader views={<SelectorBar compact …/>} actions={…} /> — the 36px pane toolbar on
+ chrome. `title` still works but a pane should not carry one (see ItemHeader).
+ ItemHeader <ItemHeader color="var(--clip-video)" icon={…} name="Clip" | name={<input className=
+ "ui-item-header__input" …/>} meta="Video · V1 · 6.2 s" actions={…} chip? id? level? />
+ — 48px, heads a pane that shows one selected thing.
+ EmptyState <EmptyState icon={<Film size={32}/>} title="No media yet" description="…" action={…} />
NavPane/NavItem <NavPane aria-label footer={…}><NavItem icon label selected badge onClick /></NavPane>
Flyout <Flyout open anchor={buttonRef} onClose aria-label>…</Flyout> (light dismiss, acrylic).
TextField <TextField value onChange={(v) => …} icon trailing={<button className="ui-textfield__button" …/>} />
- StatusBar <StatusBar end={…}>items…</StatusBar> (24px).
+ StatusBar <StatusBar end={…}>items…</StatusBar> (24px, on chrome).
+
+ Shared CSS rules (ui.css), no component:
+ .ui-selectable list rows, tiles, cards: selected by aria-selected / aria-pressed / .is-selected →
+ accent-soft + 3×16 pill (--card: accent ring instead; --separated: --line under a row).
+ Toggle on-state .icon-button--checked, .ui-cmd--pressed, .icon-button / .ui-cmd / .ui-toggle-button
+ with aria-pressed="true": accent-soft fill, accent icon.
Non-component helpers live in src/lib:
lib/commands.ts useShortcut("Ctrl+S", fn, { enabled, allowInInput, scope, preventDefault, allowInModal }),
@@ -82,6 +95,7 @@ export {
type RadioGroupProps, type RadioProps, type SelectorBarItem, type SelectorBarProps, type SliderProps, type ToggleSwitchProps,
} from "./Controls";
export { Flyout, type FlyoutProps } from "./Flyout";
+export { EmptyState, ItemHeader, type EmptyStateProps, type ItemHeaderProps } from "./Pane";
export {
CommandBar, CommandBarButton, CommandBarSeparator, NavItem, NavPane, PaneHeader, StatusBar, TextField,
type CommandBarButtonProps, type CommandBarProps, type NavItemProps, type NavPaneProps, type PaneHeaderProps,