LayerDialog
A second layer slides over the first (add model → review values); Back returns.
function Wizard() {
const [open, setOpen] = useState(false);
const [view, setView] = useState<"pick" | "review" | "custom">("pick");
const [model, setModel] = useState("");
const [custom, setCustom] = useState("");
const [query, setQuery] = useState("");
const m = models.find((x) => x.model === model);
const start = () => {
setView("pick");
setModel("");
setCustom("");
setQuery("");
setOpen(true);
};
const close = () => setOpen(false);
const add = (id: string) => {
close();
toast.success(`Added ${id}`);
};
const addCustom = () => custom.trim() && add(custom.trim());
const pick = {
title: "Add model",
description: "Pick a model from the KPMR catalogue.",
toolbar: (
<Input type="search" size="sm" aria-label="Search models" placeholder="Search" value={query} onChange={(e) => setQuery(e.target.value)} data-autofocus />
),
content: (
<div className="flex flex-col gap-12">
<List
aria-label="Models in KPMR"
density="compact"
items={models
.filter((x) => x.model.includes(query.trim().toLowerCase()))
.map((x) => ({
id: x.model,
textValue: x.model,
title: <ModelLabel provider={x.provider} providerName={providerNames[x.provider]} model={x.model} name={x.name} />,
}))}
onOpen={(item) => {
setModel(item.id);
setView("review");
}}
/>
</div>
),
footerStart: (
<Button variant="ghost" leadingIcon={icons.add} onClick={() => setView("custom")}>
Add a custom model
</Button>
),
};
const second = {
review: {
title: `Review ${model}`,
description: "Prices come from KPMR; you can override them.",
content: m && (
<div className="flex flex-col gap-16">
<ModelLabel provider={m.provider} providerName={providerNames[m.provider]} model={m.model} name={m.name} capabilities={m.capabilities} />
<KeyValue
items={[
{ label: "Input", value: `$${m.input} / M` },
{ label: "Output", value: `$${m.output} / M` },
{ label: "Context", value: `${m.context.toLocaleString("en-US")} tokens` },
]}
/>
</div>
),
footer: (
<Button variant="primary" onClick={() => add(model)}>
Add model
</Button>
),
},
custom: {
title: "Add a custom model",
description: "The id the provider knows the model by.",
content: <Input label="Model id" placeholder="acme-internal-1" value={custom} onChange={(e) => setCustom(e.target.value)} />,
footer: (
<Button variant="primary" disabled={!custom.trim()} onClick={addCustom}>
Add model
</Button>
),
},
};
return (
<>
<Button variant="primary" onClick={start}>
Add model
</Button>
<LayerDialog
open={open}
onOpenChange={(o) => !o && close()}
layer={view === "pick" ? 0 : 1}
onLayerChange={(l) => l === 0 && setView("pick")}
onSubmit={view === "review" ? () => add(model) : view === "custom" ? addCustom : undefined}
layers={view === "pick" ? [pick] : [pick, second[view]]}
/>
</>
);
}import { LayerDialog } from "@logicplanes/kaeso-ui";Props
anchor"top" | "center" = topWhere it sits: with a fixed top edge (default), so the title stays put on layers of different heights, or centered.
busybooleanKeeps the dialog open while work it started is underway: Escape, a press outside, the close circle, Dialog.Close, Enter and ⌘Enter do nothing, so a request is never abandoned or sent twice.
defaultOpenbooleanWhether it starts open, when the component keeps its own state.
hideClosebooleanHide the close circle (rare).
inlinebooleanRender without a portal and backdrop, for documentation and state matrices.
layernumberThe visible layer; layers above the first slide over it.
layersDialogLayer[]The layers, each with its title, content and footer, and optionally a toolbar and a footer start; one shows at a time, and the ones below it stay mounted and hidden.
onLayerChange((layer: number) => void)Called with the index of the layer shown.
onOpenChange((open: boolean) => void)Called when it opens or closes.
onSubmit(() => void)Enter in a single-line field and ⌘/Ctrl+Enter call this on every layer; pass the action of the layer shown.
openbooleanWhether it is open, when you control it.
persistentbooleanA press outside doesn't close it, for forms that would lose what was typed; Escape and the close circle still do. Every StepDialog is persistent.
size"md" | "sm" | "lg"The dialog's width.
triggerReactElement<unknown, string | JSXElementConstructor<any>>The trigger, a single element.