For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
18

Model Menu

Model and reasoning-effort selector with protocol-family locking.

"use client";

import { useState } from "react";

Installation

$ pnpm dlx shadcn@latest add https://motif.sweetretry.com/r/model-menu.json

Usage

import {
  ModelMenu,
  ModelMenuContent,
  ModelMenuEffort,
  ModelMenuModels,
  ModelMenuTrigger,
} from "@/components/ui/motif/model-menu";
 
export function Composer() {
  const [model, setModel] = useState("deepseek-v4-flash");
  const [effort, setEffort] = useState<ReasoningEffort | null>(null);
 
  return (
    <ModelMenu
      effort={effort}
      models={MODELS}
      onEffortChange={setEffort}
      onValueChange={setModel}
      value={model}
    >
      <ModelMenuTrigger />
      <ModelMenuContent>
        <ModelMenuModels />
        <ModelMenuEffort />
      </ModelMenuContent>
    </ModelMenu>
  );
}

Each model declares its supported thinking options and default:

{
  id: "claude-sonnet-5-5",
  name: "Claude Sonnet 5.5",
  provider: "anthropic",
  family: "anthropic",
  thinking: { options: ["low", "medium", "high", "xhigh", "max"], default: "high" },
}

Parts

PartRole
ModelMenuRoot state provider for value, effort, models, and family lock
ModelMenuTriggerDisplays provider mark, model name, effort, and chevron (children overrides)
ModelMenuContentUpward-opening menu panel
ModelMenuModelsModel radio list; accepts label and lockedLabel headings
ModelMenuEffortSubmenu row for reasoning effort; omitted when the model has ≤1 option

Behavior & Accessibility

  • Unlike Model Select (searchable catalog), ModelMenu pairs chat models with per-model reasoning steps.
  • The user's effort selection is preserved across model switches; use effortOf(model, effort) to resolve the effective step (falling back to the model's default when unsupported).
  • Passing family disables models from other protocol families under lockedLabel.
  • Built on Radix radio groups for arrow-key navigation; trigger aria-label announces model and effort together while provider marks are aria-hidden.

Component source

index.tsx
"use client";

import { useCallback, useMemo, useState } from "react";

import { DropdownMenu } from "@/components/ui/dropdown-menu";

import { ModelMenuContext } from "./context";
import type { ModelMenuState } from "./context";
import type { ChatModel, ModelMenuProps, ReasoningEffort } from "./types";

export {
  ModelMenuContent,
  ModelMenuEffort,
  ModelMenuModels,
  ModelMenuTrigger,
  EFFORT_LABELS,
} from "./parts";
export type {
  ModelMenuContentProps,
  ModelMenuEffortProps,
  ModelMenuModelsProps,
  ModelMenuTriggerProps,
} from "./parts";
export { useModelMenu } from "./context";
export type { ModelMenuState } from "./context";
export { REASONING_EFFORTS } from "./types";
export type { ChatModel, ModelMenuProps, ReasoningEffort } from "./types";

/** The step a turn runs at: the pick when the model offers it, else the model's default. */
export const effortOf = (
  model: ChatModel,
  wanted: ReasoningEffort | null | undefined
): ReasoningEffort | null => {
  if (!model.thinking) {
    return null;
  }
  const { options, default: start } = model.thinking;
  return wanted && options.includes(wanted) ? wanted : start;
};

/* -- Which model answers, and how hard it thinks ------------------------------
 * A chat model is two choices that read as one: the model, and the thinking step it runs
 * at. They live in one menu because the second depends on the first: each vendor tells a
 * different set of steps apart, so the thinking control lists the steps of the model in
 * use and nothing else.
 *
 * The thinking pick is held as a wish. Switch to a model that lacks the step and the
 * trigger shows that model's default; switch back and the pick returns. A pick that was
 * silently rewritten on every model change would lose the user's intent on the first hop.
 *
 * A conversation that has a turn is stored in its protocol's shape, so it can move only
 * between models of the same `family`. The others stay in the list, disabled, under a
 * heading that says why: a model that vanished would read as a model that does not exist.
 *
 * The root owns the state and draws nothing but the menu shell. The trigger, the model
 * list and the thinking control are parts, and a caller leaves out whichever it has no
 * use for.
 * --------------------------------------------------------------------------- */

export const ModelMenu = ({
  children,
  defaultEffort = null,
  defaultValue,
  disabled = false,
  effort,
  family,
  models,
  onEffortChange,
  onValueChange,
  value,
}: ModelMenuProps) => {
  const [picked, setPicked] = useState(() => defaultValue ?? models[0]?.id);
  const [wished, setWished] = useState(defaultEffort);
  const [open, setOpen] = useState(false);
  const selected = value === undefined ? picked : value;
  const wanted = effort === undefined ? wished : effort;

  const active = models.find((model) => model.id === selected) ?? models[0];

  const allows = useCallback(
    (model: ChatModel) =>
      family === undefined ||
      model.family === undefined ||
      model.family === family,
    [family]
  );

  const pickModel = useCallback(
    (id: string) => {
      if (value === undefined) {
        setPicked(id);
      }
      onValueChange?.(id);
    },
    [onValueChange, value]
  );

  const pickEffort = useCallback(
    (next: ReasoningEffort) => {
      if (effort === undefined) {
        setWished(next);
      }
      onEffortChange?.(next);
    },
    [effort, onEffortChange]
  );

  const state = useMemo<ModelMenuState | null>(
    () =>
      active
        ? {
            active,
            allows,
            disabled,
            effort: effortOf(active, wanted),
            locked: models.some((model) => !allows(model)),
            models,
            open,
            pickEffort,
            pickModel,
          }
        : null,
    [active, allows, disabled, models, open, pickEffort, pickModel, wanted]
  );

  // A menu with no model in it has nothing to say and nothing to pick.
  if (!state) {
    return null;
  }

  return (
    <DropdownMenu onOpenChange={setOpen} open={open}>
      <ModelMenuContext.Provider value={state}>
        {children}
      </ModelMenuContext.Provider>
    </DropdownMenu>
  );
};
parts.tsx
"use client";

import { Check, ChevronDown } from "lucide-react";
import { useState } from "react";
import type { ComponentProps, ReactNode } from "react";

import {
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { ProviderLogo } from "@/components/ui/motif/provider-logo";
import { cn } from "@/lib/utils";

import { ModelMenuContext, useModelMenu } from "./context";
import type { ReasoningEffort } from "./types";

/** How each step reads on screen. */
export const EFFORT_LABELS: Record<ReasoningEffort, string> = {
  high: "High",
  low: "Low",
  max: "Max",
  medium: "Medium",
  minimal: "Minimal",
  off: "Off",
  xhigh: "Extra high",
};

const LABEL = "px-2 pt-2 pb-1 font-normal text-muted-foreground text-xs";

/** A radio row with its mark at the end. The stock row keeps a gutter on the left for its
 *  dot, which pushes every row off the axis the headings and the thinking row sit on; so
 *  the stock dot is hidden and a check trails the row instead. */
const PICK = "gap-2.5 py-2 pl-2 [&>span:first-child]:hidden";

const Picked = ({ on }: { on: boolean }) =>
  on ? <Check className="ml-auto size-4 text-foreground" /> : null;

/* -- Trigger -------------------------------------------------------------------
 * Mark, name, step, chevron. The mark is read at a glance, the name is the part that
 * changes and so the part that truncates, and the step trails in the muted tone because
 * it qualifies the model rather than competing with it.
 * --------------------------------------------------------------------------- */

export interface ModelMenuTriggerProps extends ComponentProps<"button"> {
  /** Replaces the face. The button, its states and its label stay. */
  children?: ReactNode;
}

export const ModelMenuTrigger = ({
  children,
  className,
  ...props
}: ModelMenuTriggerProps) => {
  const { active, disabled, effort } = useModelMenu();
  const step = effort ? EFFORT_LABELS[effort] : null;

  return (
    <DropdownMenuTrigger asChild disabled={disabled}>
      <button
        aria-label={
          step
            ? `Model: ${active.name}, thinking ${step.toLowerCase()}`
            : `Model: ${active.name}`
        }
        className={cn(
          "flex h-10 min-w-0 max-w-64 shrink cursor-pointer items-center gap-2 rounded-full pr-2 pl-2.5 text-sm outline-none transition-colors duration-150 ease-out hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent",
          className
        )}
        type="button"
        {...props}
      >
        {children ?? (
          <>
            <ProviderLogo
              className="size-5 text-foreground"
              provider={active.provider}
            />
            <span className="truncate text-foreground">{active.name}</span>
            {step ? (
              <span className="shrink-0 text-muted-foreground">{step}</span>
            ) : null}
            <ChevronDown className="size-4 shrink-0 text-muted-foreground/60" />
          </>
        )}
      </button>
    </DropdownMenuTrigger>
  );
};

/* -- Content -------------------------------------------------------------------
 * Opens upward: the menu sits in a composer at the foot of the window, and unfolding over
 * the draft would cover the thing being decided about. Radix flips it when there is no
 * room above.
 *
 * A pick closes the menu, and the same click changes what it would draw. Drawn live, the
 * menu rewrites itself while it fades, and if its height changes, opening upward, its top
 * edge jumps. So the content holds the state it showed while
 * open and lets the trigger alone answer the pick. The thinking row needs it too: its
 * step changes with the model, and it vanishes for a model with nothing to choose.
 * --------------------------------------------------------------------------- */

export type ModelMenuContentProps = ComponentProps<typeof DropdownMenuContent>;

export const ModelMenuContent = ({
  align = "start",
  className,
  side = "top",
  ...props
}: ModelMenuContentProps) => {
  const live = useModelMenu();
  const [held, setHeld] = useState(live);
  if (live.open && held !== live) {
    setHeld(live);
  }

  return (
    <ModelMenuContext.Provider value={live.open ? live : held}>
      <DropdownMenuContent
        align={align}
        className={cn("w-60", className)}
        side={side}
        {...props}
      />
    </ModelMenuContext.Provider>
  );
};

/* -- Models --------------------------------------------------------------------
 * Every model, in the caller's order. Under a family lock the ones that cannot take the
 * conversation over stay where they are, disabled, and the heading names the reason.
 * --------------------------------------------------------------------------- */

export interface ModelMenuModelsProps {
  className?: string;
  /** Heading over the list. */
  label?: string;
  /** Heading while a lock greys models out: the reason, said once for all of them. */
  lockedLabel?: string;
}

export const ModelMenuModels = ({
  className,
  label = "Model",
  lockedLabel = "Same protocol as this conversation",
}: ModelMenuModelsProps) => {
  const { active, allows, locked, models, pickModel } = useModelMenu();

  return (
    <DropdownMenuGroup className={className}>
      <DropdownMenuLabel className={LABEL}>
        {locked ? lockedLabel : label}
      </DropdownMenuLabel>
      <DropdownMenuRadioGroup onValueChange={pickModel} value={active.id}>
        {models.map((model) => (
          <DropdownMenuRadioItem
            className={PICK}
            disabled={!allows(model)}
            key={model.id}
            value={model.id}
          >
            <ProviderLogo
              className="size-4.5 text-foreground"
              provider={model.provider}
            />
            <span className="truncate">{model.name}</span>
            <Picked on={model.id === active.id} />
          </DropdownMenuRadioItem>
        ))}
      </DropdownMenuRadioGroup>
    </DropdownMenuGroup>
  );
};

/* -- Thinking ------------------------------------------------------------------
 * One row under the models: the heading, the step in use, and a submenu of the steps the
 * model offers, weakest first, as the vendor lists them. Folded away, the step list no
 * longer sets the menu's height, so switching between models of three and five steps
 * leaves the menu the same size. A model with one step or none has nothing to choose, so
 * the part draws nothing, not even its rule.
 * --------------------------------------------------------------------------- */

export interface ModelMenuEffortProps {
  className?: string;
  /** Heading on the row that opens the steps. */
  label?: string;
}

export const ModelMenuEffort = ({
  className,
  label = "Thinking",
}: ModelMenuEffortProps) => {
  const { active, effort, pickEffort } = useModelMenu();
  const options = active.thinking?.options ?? [];

  if (!effort || options.length < 2) {
    return null;
  }

  return (
    <>
      <DropdownMenuSeparator />
      <DropdownMenuSub>
        <DropdownMenuSubTrigger className={cn("gap-2 py-2", className)}>
          <span className="flex-1">{label}</span>
          <span className="text-muted-foreground">{EFFORT_LABELS[effort]}</span>
        </DropdownMenuSubTrigger>
        <DropdownMenuSubContent className="w-36">
          <DropdownMenuRadioGroup
            onValueChange={(next) => pickEffort(next as ReasoningEffort)}
            value={effort}
          >
            {options.map((option) => (
              <DropdownMenuRadioItem
                className={PICK}
                key={option}
                value={option}
              >
                {EFFORT_LABELS[option]}
                <Picked on={option === effort} />
              </DropdownMenuRadioItem>
            ))}
          </DropdownMenuRadioGroup>
        </DropdownMenuSubContent>
      </DropdownMenuSub>
    </>
  );
};
context.ts
"use client";

import { createContext, useContext } from "react";

import type { ChatModel, ReasoningEffort } from "./types";

/** What a part needs from the root: the catalogue, the model in use, the step it runs
 *  at, and the two ways to change them. */
export interface ModelMenuState {
  /** The model in use. */
  active: ChatModel;
  /** Whether `model` can take over this conversation. */
  allows: (model: ChatModel) => boolean;
  disabled: boolean;
  /** The step the active model runs at: the pick when it offers it, else its default.
   *  `null` when the model has no thinking control. */
  effort: ReasoningEffort | null;
  /** Whether a family lock is greying any model out. */
  locked: boolean;
  models: ChatModel[];
  /** Whether the menu is open. The content freezes on the last open state while it
   *  animates out. */
  open: boolean;
  pickEffort: (effort: ReasoningEffort) => void;
  pickModel: (id: string) => void;
}

export const ModelMenuContext = createContext<ModelMenuState | null>(null);

export const useModelMenu = () => {
  const context = useContext(ModelMenuContext);
  if (!context) {
    throw new Error("ModelMenu parts must be used within a ModelMenu.");
  }

  return context;
};
types.ts
import type { ReactNode } from "react";

import type { ProviderId } from "@/components/ui/motif/provider-logo";

/** The steps a vendor tells apart when it is asked how hard to think, weakest first.
 *  A model offers the subset its API accepts; no model offers them all. */
export const REASONING_EFFORTS = [
  "off",
  "minimal",
  "low",
  "medium",
  "high",
  "xhigh",
  "max",
] as const;

export type ReasoningEffort = (typeof REASONING_EFFORTS)[number];

/** One chat model the conversation can run on. */
export interface ChatModel {
  /** What `value` and `onValueChange` trade in. */
  id: string;
  name: string;
  provider: ProviderId;
  /**
   * The protocol the model is spoken to in. A conversation stores its history in one
   * protocol's shape, so once it has a turn it can only move between models that share
   * this. Omit it and the model is never locked out.
   */
  family?: string;
  /** The thinking steps this model offers, and the one a turn runs at without a pick.
   *  Omit it, or offer one step, and the menu draws no thinking control for it. */
  thinking?: {
    options: readonly ReasoningEffort[];
    default: ReasoningEffort;
  };
}

export interface ModelMenuProps {
  children: ReactNode;
  /** Model the menu opens on when it holds the choice itself. Defaults to the first. */
  defaultValue?: string;
  /** Thinking step the menu starts on when it holds the pick itself. */
  defaultEffort?: ReasoningEffort | null;
  disabled?: boolean;
  /**
   * The user's thinking pick, controlled. It is a wish, not a setting: a model that does
   * not offer it runs at its own default, and the pick comes back when the user returns
   * to a model that does. `null` means "the model's default".
   */
  effort?: ReasoningEffort | null;
  /**
   * The family the conversation is locked to, or omit it before the first turn. Models
   * of another family stay listed and disabled, so the user sees why they cannot switch
   * instead of wondering where they went.
   */
  family?: string;
  models: ChatModel[];
  onEffortChange?: (effort: ReasoningEffort) => void;
  onValueChange?: (id: string) => void;
  value?: string;
}