import { tr } from '../lib/i18n'; /** * Strata primitives. * * These wrap the kit's own component classes (`st-*` from ui/components.css) * rather than inventing a parallel set, so the app and the design reference stay * the same system. Anything added here is a documented extension that only uses * kit tokens — see src/styles/app.css. */ import { createContext, useContext, useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type AriaAttributes, type CSSProperties, type ReactNode } from 'react'; import { createPortal } from 'react-dom'; import { cx, userError } from '../lib/format'; import { plainFailure } from '../lib/plain-errors'; import { dismissActionError, dismissToast, holdToast, releaseToast, useStore } from '../lib/store'; import { isTopSurface, useSurfaceFocus } from '../lib/focus'; import { measureFrame, placeAnchored } from '../lib/overlay-place'; /* -------------------------------------------------------------------- icon */ export type IconName = 'pause' | 'play' | 'activity' | 'plus' | 'shield' | 'computer' // Authored for the shell: see docs/design-system-notes.md. | 'panel' | 'search' | 'sliders' | 'folder' | 'folder-plus' | 'file' | 'ellipsis' | 'pencil' | 'pin' | 'x' | 'attach' | 'bolt' | 'branch' | 'chat' | 'check' | 'chevron' | 'clock' | 'copy' | 'cpu' | 'disk' | 'download' | 'error' | 'experts' | 'gauge' | 'gpu' | 'image' | 'info' | 'expand' | 'contract' | 'layers' | 'models' | 'skills' | 'engine' | 'family-qwen' | 'model-file' | 'link' | 'memory' | 'mic' | 'moon' | 'new-chat' | 'refresh' | 'send' | 'settings' | 'stop' | 'sun' | 'thermometer' | 'thinking' | 'tool' | 'trash' | 'warning'; export function Icon({ name, size, className, style, }: { name: IconName; size?: number; className?: string; style?: CSSProperties; }) { return (); } /* ------------------------------------------------------------------ button */ type BtnProps = AriaAttributes & { children?: ReactNode; variant?: 'primary' | 'secondary' | 'danger' | 'ghost'; size?: 'sm' | 'md' | 'lg'; icon?: IconName; iconRight?: IconName; block?: boolean; title?: string; disabled?: boolean; active?: boolean; type?: 'button' | 'submit'; onClick?: () => void; className?: string; }; export function Btn({ children, variant = 'secondary', size = 'md', icon, iconRight, block, title, disabled, active, type = 'button', onClick, className, ...aria }: BtnProps) { return (); } export function IconBtn({ name, title, onClick, disabled, active, size = 19, }: { name: IconName; title: string; onClick?: () => void; disabled?: boolean; /** Renders in the pressed state — used by the sidebar's search toggle. */ active?: boolean; size?: number; }) { return (); } /* ------------------------------------------------------------------- panel */ export function Panel({ children, className, pad, }: { children: ReactNode; className?: string; pad?: boolean; accent?: boolean; }) { return
{tr(children)}
; } export function PanelHead({ title, sub, right, icon, }: { title: ReactNode; sub?: ReactNode; right?: ReactNode; icon?: IconName; }) { return (
{tr(icon ? : null)}
{/* A real h3 so the document has an outline below the h2 section heads; styled exactly as before. */}

{tr(title)}

{tr(sub ?
{tr(sub)}
: null)}
{tr(right)}
); } /* -------------------------------------------------------------------- pill */ export function Pill({ children, tone = 'plain', dot, badge, className, }: { children: ReactNode; tone?: 'plain' | 'accent' | 'info' | 'warn' | 'danger'; dot?: boolean; /** `badge` renders the 24px badge treatment instead of the 30px status pill. */ badge?: boolean; className?: string; }) { const toneClass = { plain: undefined, accent: badge ? 'st-badge--generating' : 'st-pill--accent', info: badge ? 'st-badge--reading' : 'st-pill--info', warn: badge ? 'st-badge--queued' : 'st-pill--warn', danger: badge ? 'st-badge--error' : 'st-pill--danger', }[tone]; return ( {tr(dot && !badge ? : null)} {tr(children)} ); } /* --------------------------------------------------------------------- bar */ export function Bar({ value, tone = 'accent', size, indeterminate, label = 'Progress', }: { value: number; tone?: 'accent' | 'info' | 'warn' | 'danger'; size?: 'sm' | 'lg'; indeterminate?: boolean; label?: string; }) { return (
); } /* ---------------------------------------------------------------- segments */ export function Seg({ value, options, onChange, ariaLabel, panelId, }: { value: T; /** `title` explains a label that has to stay short to fit the control. */ options: { value: T; label: string; icon?: IconName; title?: string; disabled?: boolean; }[]; onChange: (v: T) => void; ariaLabel?: string; /** Supply the associated panel ID for actual tabs; omit for segmented values. */ panelId?: string; }) { return (
{tr(options.map((o) => ()))}
); } /* ------------------------------------------------------------------- steps */ export interface StepDef { n: number; label: string; } export function Steps({ steps, current }: { steps: StepDef[]; current: number; }) { return (

{tr("Step ")}{tr(current)}{tr(" of ")}{tr(steps.length)} · {tr(steps.find(s => s.n === current)?.label)}

{tr(steps.map((s) => { const state = s.n < current ? 'done' : s.n === current ? 'active' : 'todo'; return (
{tr(s.n)} · {tr(s.label)}
); }))}
); } /* ------------------------------------------------------------------ fields */ const FieldContext = createContext<{ label: string; description?: string; } | null>(null); export function Field({ label, hint, impact, children, wide, }: { label: ReactNode; hint?: ReactNode; /** What the current value actually costs. Shown where the choice is made * rather than only in a summary elsewhere on the screen. */ impact?: ReactNode; children: ReactNode; wide?: boolean; }) { const id = useId(); return (
{tr(label)}
{tr(hint ?
{tr(hint)}
: null)} {tr(impact ?
{tr(impact)}
: null)}
{tr(children)}
); } /** * A listbox styled as a Strata field. * * This replaces a native `