/** * The render-parameters UI for `TemplatedTextField`: the add/remove editor * (`KwargsEditor`) for editable values, and the read-only listing * (`ReadOnlyKwargs`) shown beside a read-only stored id. */ import { type ReactNode, useState } from 'react'; import { CloseIcon } from './icons'; import { TextInput } from './inputs'; import { Button } from './primitives'; import type { KwargRow } from './templated-text-kwargs'; /** The add/remove kwargs editor, revealed on demand and open when kwargs already exist. */ export function KwargsEditor({ label, rows, disabled, onChange, }: { readonly label: string; readonly rows: readonly KwargRow[]; readonly disabled: boolean; readonly onChange: (rows: KwargRow[]) => void; }): ReactNode { const [open, setOpen] = useState(rows.length > 0); const groupLabel = `${label} render parameters`; if (!open) { // Wrapped so the ghost button keeps its content width and stays left-aligned // in the field's column, marking it as this field's own disclosure rather than // a full-width control floating between two fields. return (
); } return (
Render parameters {rows.map((row, index) => (
{ const next = [...rows]; next[index] = { ...row, key: event.target.value }; onChange(next); }} /> { const next = [...rows]; next[index] = { ...row, value: event.target.value }; onChange(next); }} />
))}
); } /** * The render parameters of a read-only stored value, as read-only text — the * values in normal weight, NOT the muted disabled inputs a reader could mistake * for empty placeholders. Renders nothing when there are no kwargs. */ export function ReadOnlyKwargs({ label, rows, }: { readonly label: string; readonly rows: readonly KwargRow[]; }): ReactNode { if (rows.length === 0) return null; return (
Render parameters {rows.map((row) => (
{row.key} : {row.value}
))}
); }