Model Selector
SaveA searchable model picker grouped by provider with context sizes and capability tags, plus a reasoning effort select with rising bars.
- Category
- AI elements
- Version
- 0.1.0
- Frameworks
- Next.js, Vite + React
- Styling
- Tailwind CSS v4
Preview
Model Selector preview
Installation
npx @shakenui/cli add model-selectorReview the plan first. A dry run lists every file and package without changing anything:
npx @shakenui/cli add model-selector --dry-runUsage
model-selector-example.tsx
"use client";
import { useState } from "react";
import { type ModelOption, ModelSelector, ReasoningEffort } from "@/components/shaken/agent/model-selector";
const models: ModelOption[] = [
{ id: "claude-sonnet-5-5", name: "Claude Sonnet 5.5", provider: "Anthropic", context: 200_000, capabilities: ["vision", "tools", "reasoning"] },
{ id: "claude-haiku-5-5", name: "Claude Haiku 5.5", provider: "Anthropic", context: 200_000, capabilities: ["vision", "tools", "fast"] },
{ id: "gpt-5", name: "GPT-5", provider: "OpenAI", context: 400_000, capabilities: ["vision", "tools", "reasoning"] },
{ id: "gpt-5-mini", name: "GPT-5 mini", provider: "OpenAI", context: 400_000, capabilities: ["tools", "fast"] },
{ id: "gemini-2-5-pro", name: "Gemini 2.5 Pro", provider: "Google", context: 1_000_000, capabilities: ["vision", "audio", "reasoning"] },
{
id: "gemini-2-5-flash",
name: "Gemini 2.5 Flash",
provider: "Google",
context: 1_000_000,
capabilities: ["vision", "fast"],
description: "Not enabled for this workspace",
disabled: true,
},
];
export default function ModelSelectorExample() {
const [model, setModel] = useState("claude-sonnet-5-5");
const [effort, setEffort] = useState("medium");
return (
<div className="flex flex-wrap items-center gap-1 rounded-xl border border-zinc-950/10 p-1.5 dark:border-white/10">
<ModelSelector models={models} value={model} onValueChange={setModel} />
<span aria-hidden="true" className="h-4 w-px bg-zinc-950/10 dark:bg-white/10" />
<ReasoningEffort value={effort} onValueChange={setEffort} />
</div>
);
}API
| Prop | Type | Default | Description |
|---|---|---|---|
| ModelSelector models | { id, name, provider, context?, capabilities?, description?, disabled? }[] | — | Models in order; they group by provider. capabilities are vision, tools, reasoning, files, audio, or fast. |
| ModelSelector value / defaultValue / onValueChange | string / string / (id) => void | first enabled model | The selected model id. |
| ModelSelector searchPlaceholder | string | "Search models" | Placeholder of the search field. Search matches name, provider, and capability words. |
| ReasoningEffort levels | { value, label, description? }[] | Low, Medium, High | Levels from least to most effort. |
| ReasoningEffort value / defaultValue / onValueChange | string / string / (value) => void | "medium" | The selected level. |
| side | "top" | "bottom" | "bottom" | Popup side for either control, for example top in a composer. |
| disabled | boolean | false | Disables the trigger. |
Accessibility
- The model list is a Base UI Combobox with the search field inside the popup: arrows move, Enter picks, Escape closes, and focus returns to the trigger.
- Triggers have accessible names that include their purpose ("Model: Claude Sonnet 4.5", "Reasoning effort: Medium").
- An empty search is announced politely by the Combobox empty state. Disabled models stay visible with a reason and are skipped by the keyboard.
- Reasoning effort is a Base UI Select with role="listbox" options; the bars are decorative and the level is text.
- With reduced motion both popups appear without scale.
Files
Installed into src/components/shaken, or components/shaken when the project has no src directory.
src/components/shaken/agent/model-selector.tsxmodel-selector- npm packages: @base-ui/react@^1.9.0React and Tailwind CSS v4 required
Source
The exact source the CLI installs, from /r/items/react/model-selector/0.1.0.json.
agent/model-selector.tsxShowHide
agent/model-selector.tsx
"use client";
import { Combobox } from "@base-ui/react/combobox";
import { Select } from "@base-ui/react/select";
import { type ReactNode, useMemo, useState } from "react";
function cx(...classes: Array<string | false | null | undefined>) {
return classes.filter(Boolean).join(" ");
}
const ease = "ease-[cubic-bezier(0.23,1,0.32,1)]";
// Shared by both popups: the overlay surface and the 160ms enter, 110ms exit from the trigger.
const popupSurface = cx(
"origin-(--transform-origin) rounded-xl outline-none",
"border border-zinc-950/10 bg-white text-zinc-950 shadow-[0_12px_32px_-8px_rgb(0_0_0/0.18)]",
"dark:border-white/15 dark:bg-black dark:text-white dark:shadow-[0_16px_48px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]",
`transition-[opacity,scale] duration-160 ${ease} motion-reduce:transition-none`,
"data-[starting-style]:opacity-0 motion-safe:data-[starting-style]:scale-96",
"data-[ending-style]:opacity-0 data-[ending-style]:duration-110 data-[ending-style]:ease-out motion-safe:data-[ending-style]:scale-98",
);
const triggerBase = cx(
"group inline-flex h-8 max-w-full min-w-0 cursor-pointer items-center gap-2 rounded-lg px-2 text-sm select-none",
"text-zinc-700 transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none",
"hover:bg-zinc-950/[0.04] hover:text-zinc-950 data-[popup-open]:bg-zinc-950/[0.06] data-[popup-open]:text-zinc-950",
"dark:text-zinc-300 dark:hover:bg-white/[0.06] dark:hover:text-white dark:data-[popup-open]:bg-white/[0.09] dark:data-[popup-open]:text-white",
"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500",
"disabled:pointer-events-none disabled:opacity-45",
);
const itemBase = cx(
"flex cursor-default items-start gap-2.5 rounded-md px-2 py-2 outline-none select-none",
"data-[highlighted]:bg-zinc-950/[0.05] dark:data-[highlighted]:bg-white/[0.08]",
"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-45",
);
// ---------------------------------------------------------------------------
// Model selector
export type ModelCapability = "vision" | "tools" | "reasoning" | "files" | "audio" | "fast";
const capabilityLabels: Record<ModelCapability, string> = {
vision: "Vision",
tools: "Tools",
reasoning: "Reasoning",
files: "Files",
audio: "Audio",
fast: "Fast",
};
export interface ModelOption {
id: string;
/** Display name, for example "Claude Sonnet 5.5". */
name: string;
/** Groups the list and labels the monogram on the trigger. */
provider: string;
/** Context window in tokens. Shown as "200K context". */
context?: number;
capabilities?: ModelCapability[];
/** A short note under the name, for example "Best for long documents". */
description?: ReactNode;
/** Keeps the model visible but not selectable. Say why in `description`. */
disabled?: boolean;
}
export interface ModelSelectorProps {
models: ModelOption[];
/** Selected model id. Pair with `onValueChange`. */
value?: string;
/** Initial model id when uncontrolled. Defaults to the first enabled model. */
defaultValue?: string;
onValueChange?: (id: string) => void;
/** @default "Search models" */
searchPlaceholder?: string;
disabled?: boolean;
/** Classes for the trigger button. */
className?: string;
/** Popup side relative to the trigger. @default "bottom" */
side?: "top" | "bottom";
}
const compact = new Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 });
function matches(model: ModelOption, query: string) {
const words = query.toLowerCase().trim().split(/\s+/).filter(Boolean);
if (!words.length) return true;
const haystack = [model.name, model.provider, ...(model.capabilities ?? []).map((capability) => capabilityLabels[capability])].join(" ").toLowerCase();
return words.every((word) => haystack.includes(word));
}
/**
* A model picker: a quiet trigger with the model's name that opens a searchable list grouped
* by provider. Each row shows the context size and capability badges. Type to filter by name,
* provider, or capability ("vision", "reasoning"); arrows move, Enter picks.
*/
export function ModelSelector({
models,
value: valueProp,
defaultValue,
onValueChange,
searchPlaceholder = "Search models",
disabled = false,
className,
side = "bottom",
}: ModelSelectorProps) {
const [uncontrolled, setUncontrolled] = useState(() => defaultValue ?? models.find((model) => !model.disabled)?.id);
const id = valueProp ?? uncontrolled;
const selected = models.find((model) => model.id === id) ?? null;
const [query, setQuery] = useState("");
const groups = useMemo(() => {
const byProvider = new Map<string, ModelOption[]>();
for (const model of models) byProvider.set(model.provider, [...(byProvider.get(model.provider) ?? []), model]);
return Array.from(byProvider, ([provider, items]) => ({ value: provider, items }));
}, [models]);
return (
<Combobox.Root
items={groups}
value={selected}
onValueChange={(model: ModelOption | null) => {
if (!model) return;
if (valueProp === undefined) setUncontrolled(model.id);
onValueChange?.(model.id);
}}
itemToStringLabel={(model: ModelOption) => model.name}
isItemEqualToValue={(a: ModelOption, b: ModelOption) => a.id === b.id}
filter={(model: ModelOption, search: string) => matches(model, search)}
onInputValueChange={setQuery}
disabled={disabled}
>
<Combobox.Trigger className={cx(triggerBase, className)}>
{selected ? <Monogram provider={selected.provider} /> : null}
<span className="sr-only">Model: </span>
<span className="min-w-0 truncate font-medium">{selected ? selected.name : "Choose a model"}</span>
<Chevron />
</Combobox.Trigger>
<Combobox.Portal>
<Combobox.Positioner side={side} align="start" sideOffset={6} className="z-50 outline-none">
<Combobox.Popup className={cx(popupSurface, "flex max-h-[min(28rem,var(--available-height))] w-[min(24rem,calc(100vw-2rem))] flex-col overflow-hidden")}>
<div className="flex items-center gap-2 border-b border-zinc-950/[0.07] px-3 dark:border-white/[0.08]">
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" className="size-4 shrink-0 text-zinc-400 dark:text-zinc-500">
<circle cx="7" cy="7" r="4.25" />
<path d="m10.25 10.25 3 3" />
</svg>
<Combobox.Input
aria-label="Search models"
placeholder={searchPlaceholder}
className="h-11 min-w-0 flex-1 bg-transparent text-sm text-zinc-950 outline-none placeholder:text-zinc-400 dark:text-white dark:placeholder:text-zinc-500"
/>
</div>
<Combobox.Empty className="text-sm text-zinc-500 empty:hidden">
<p className="px-4 py-6 text-center">No models match “{query.trim()}”</p>
</Combobox.Empty>
<Combobox.List className="min-h-0 flex-1 overflow-y-auto overscroll-contain p-1.5 empty:hidden">
{(group: { value: string; items: ModelOption[] }) => (
<Combobox.Group key={group.value} items={group.items} className="not-first:mt-1.5">
<Combobox.GroupLabel className="px-2 pt-1.5 pb-1 text-xs font-medium text-zinc-500 select-none">{group.value}</Combobox.GroupLabel>
<Combobox.Collection>
{(model: ModelOption) => (
<Combobox.Item key={model.id} value={model} disabled={model.disabled} className={itemBase}>
<ModelRow model={model} />
<Combobox.ItemIndicator className="mt-0.5 flex size-4 shrink-0 items-center justify-center text-zinc-950 dark:text-white">
<Check />
</Combobox.ItemIndicator>
</Combobox.Item>
)}
</Combobox.Collection>
</Combobox.Group>
)}
</Combobox.List>
</Combobox.Popup>
</Combobox.Positioner>
</Combobox.Portal>
</Combobox.Root>
);
}
function ModelRow({ model }: { model: ModelOption }) {
const capabilities = model.capabilities ?? [];
return (
<div className="min-w-0 flex-1">
<p className="truncate text-sm leading-5 text-zinc-950 dark:text-white">{model.name}</p>
{model.description != null ? <p className="text-xs leading-5 text-zinc-500">{model.description}</p> : null}
{model.context != null || capabilities.length ? (
<div className="mt-1 flex flex-wrap items-center gap-1">
{model.context != null ? (
<span className="mr-1.5 font-mono text-[11px] text-zinc-500 tabular-nums">{compact.format(model.context)} context</span>
) : null}
{capabilities.map((capability) => (
<span
key={capability}
className="inline-flex h-[18px] items-center gap-1 rounded-[5px] border border-zinc-950/10 px-1.5 text-[11px] leading-none text-zinc-600 dark:border-white/10 dark:text-zinc-400 [&_svg]:size-3 [&_svg]:shrink-0"
>
<CapabilityIcon capability={capability} />
{capabilityLabels[capability]}
</span>
))}
</div>
) : null}
</div>
);
}
/** The provider's initial in a small hairline square. No logos: they belong to their owners. */
function Monogram({ provider }: { provider: string }) {
return (
<span
aria-hidden="true"
className="flex size-5 shrink-0 items-center justify-center rounded-md border border-zinc-950/10 text-[11px] leading-none font-semibold text-zinc-600 dark:border-white/15 dark:text-zinc-300"
>
{provider.trim().charAt(0).toUpperCase()}
</span>
);
}
function CapabilityIcon({ capability }: { capability: ModelCapability }) {
const paths: Record<ModelCapability, ReactNode> = {
vision: (
<>
<path d="M1.75 8S4 3.75 8 3.75 14.25 8 14.25 8 12 12.25 8 12.25 1.75 8 1.75 8Z" />
<circle cx="8" cy="8" r="2" />
</>
),
tools: <path d="M9.75 2.5a3.25 3.25 0 0 0-3 4.5L2.5 11.25 4.75 13.5 9 9.25a3.25 3.25 0 0 0 4.5-3l-2 1.25-1.75-.5-.5-1.75Z" />,
reasoning: <path d="M8 2.25 9.4 6.6 13.75 8 9.4 9.4 8 13.75 6.6 9.4 2.25 8 6.6 6.6Z" />,
files: <path d="M4 1.75h5L12.25 5v9.25H4ZM9 1.75V5h3.25" />,
audio: <path d="M3 6.5v3M5.75 4.5v7M8.5 2.5v11M11.25 5v6M14 7v2" />,
fast: <path d="M9 1.75 3.5 9H8l-1 5.25L12.5 7H8Z" />,
};
return (
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.4} strokeLinecap="round" strokeLinejoin="round">
{paths[capability]}
</svg>
);
}
// ---------------------------------------------------------------------------
// Reasoning effort
export interface ReasoningEffortLevel {
value: string;
label: string;
/** One line about the trade-off, shown in the list. */
description?: ReactNode;
}
export const defaultEffortLevels: ReasoningEffortLevel[] = [
{ value: "low", label: "Low", description: "Quick replies for simple asks" },
{ value: "medium", label: "Medium", description: "Balanced speed and depth" },
{ value: "high", label: "High", description: "Thinks longer on hard problems" },
];
export interface ReasoningEffortProps {
/** Levels from least to most effort. The bars on the trigger fill in this order. */
levels?: ReasoningEffortLevel[];
value?: string;
/** @default "medium" when it exists, otherwise the first level */
defaultValue?: string;
onValueChange?: (value: string) => void;
disabled?: boolean;
/** Classes for the trigger button. */
className?: string;
/** Popup side relative to the trigger. @default "bottom" */
side?: "top" | "bottom";
}
/**
* How hard the model should think: a compact select whose trigger shows rising bars filled up
* to the chosen level, with a one-line trade-off for each level in the list.
*/
export function ReasoningEffort({
levels = defaultEffortLevels,
value: valueProp,
defaultValue,
onValueChange,
disabled = false,
className,
side = "bottom",
}: ReasoningEffortProps) {
const [uncontrolled, setUncontrolled] = useState(
() => defaultValue ?? levels.find((level) => level.value === "medium")?.value ?? levels[0]?.value ?? "",
);
const value = valueProp ?? uncontrolled;
const index = Math.max(0, levels.findIndex((level) => level.value === value));
const current = levels[index];
return (
<Select.Root
value={value}
onValueChange={(next: string | null) => {
if (next == null) return;
if (valueProp === undefined) setUncontrolled(next);
onValueChange?.(next);
}}
items={levels.map((level) => ({ value: level.value, label: level.label }))}
disabled={disabled}
>
<Select.Trigger className={cx(triggerBase, className)}>
<EffortBars level={index + 1} total={levels.length} />
<span className="sr-only">Reasoning effort: </span>
<Select.Value className="min-w-0 truncate">{() => current?.label}</Select.Value>
<Chevron />
</Select.Trigger>
<Select.Portal>
<Select.Positioner side={side} align="start" sideOffset={6} alignItemWithTrigger={false} className="z-50 outline-none">
<Select.Popup className={cx(popupSurface, "w-64 p-1.5")}>
<Select.List>
{levels.map((level, levelIndex) => (
<Select.Item key={level.value} value={level.value} className={cx(itemBase, "items-center")}>
<EffortBars level={levelIndex + 1} total={levels.length} />
<div className="min-w-0 flex-1">
<Select.ItemText className="block text-sm leading-5 text-zinc-950 dark:text-white">{level.label}</Select.ItemText>
{level.description != null ? <p className="text-xs leading-5 text-zinc-500">{level.description}</p> : null}
</div>
<Select.ItemIndicator className="flex size-4 shrink-0 items-center justify-center text-zinc-950 dark:text-white">
<Check />
</Select.ItemIndicator>
</Select.Item>
))}
</Select.List>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>
);
}
/** Rising bars, filled up to `level` of `total`. The fill eases between levels. */
export function EffortBars({ level, total, className }: { level: number; total: number; className?: string }) {
const count = Math.max(1, total);
const gap = 1.5;
const width = (12 - gap * (count - 1)) / count;
return (
<svg aria-hidden="true" viewBox="0 0 16 16" className={cx("size-4 shrink-0", className)}>
{Array.from({ length: count }, (_, i) => {
const height = 4 + ((10 - 4) * i) / Math.max(1, count - 1);
return (
<rect
key={i}
x={2 + i * (width + gap)}
y={13 - height}
width={width}
height={height}
rx={0.75}
fill="currentColor"
className={cx("transition-[fill-opacity] duration-200 ease-out motion-reduce:transition-none", i < level ? "fill-current" : "")}
fillOpacity={i < level ? 1 : 0.22}
/>
);
})}
</svg>
);
}
function Chevron() {
return (
<svg
aria-hidden="true"
viewBox="0 0 16 16"
fill="none"
className="size-3.5 shrink-0 text-zinc-400 transition-colors duration-150 group-hover:text-current motion-reduce:transition-none dark:text-zinc-500"
>
<path d="m4.5 6.25 3.5 3.5 3.5-3.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
);
}
function Check() {
return (
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.6} strokeLinecap="round" strokeLinejoin="round" className="size-4">
<path d="m3.75 8.25 2.75 2.75 5.75-6" />
</svg>
);
}