How an agent takes what you write: each mode with a line on what it's for, the current one ticked.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { type Mode, ModePicker } from "./ui/uicontext/components/kit/ModePicker.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const modes: ReadonlyArray<Mode> = [ { id: "work", label: "Work", description: "Does the task in your apps and hands back a file" }, { id: "ask", label: "Ask", description: "Answers from what it can read; changes nothing" }, { id: "plan", label: "Plan", description: "Writes the plan and waits for your go" },]const Message = UiSchema.TaggedEnum({ PickedMode: { mode: Schema.String } })const styles = stylex.create({ row: { display: "flex", alignItems: "center", gap: space.lg }, note: { color: color.muted, fontSize: font.sm },})export const Modes = Html.component({ name: "ModePickerExample", model: Schema.Struct({ mode: Schema.String }), message: Message,}).make({ init: () => ({ mode: "work" }), update: { PickedMode: ($, { mode }) => $.evolve({ mode }) }, view: (h, model) => h.div.attrs(sx(styles.row)).children( ModePicker(h, { modes, value: model.mode, onPick: (mode) => Message.PickedMode({ mode }) }), h.span.attrs({ role: "status", ...sx(styles.note) }).children(modes.find((m) => m.id === model.mode)?.description ?? ""), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/mode-pickerUsage
import { ModePicker } from "./ui/uicontext/components/kit/ModePicker.ts"const Message = UiSchema.TaggedEnum({ PickedMode: { mode: Schema.String } })// the mode is yours: pass the current one, store what the menu asks forexport const Mode = (h: Html.H<typeof Message.Type>, mode: string) => ModePicker(h, { modes: [ { id: "work", label: "Work", description: "Does the task in your apps" }, { id: "ask", label: "Ask", description: "Answers; changes nothing" }, ], value: mode, onPick: (picked) => Message.PickedMode({ mode: picked }), })API reference
Options
| Name | Type | Description |
|---|---|---|
key | string | Names the picker among others in the same view |
modesrequired | Mode[] | — |
valuerequired | string | The current mode's id |
onPickrequired | (mode: string) => Message | — |
size | "sm" | "md" | "sm" in a composer, "md" beside a title |
disabled | boolean | — |