Library MCP Setup About Template Factory ↗
← Library / Forms & Settings UI SDK Agentic

Inline Builder Context & Picker Strip

MSAI full-width builder context strip where picking happens inline via anchored dropdowns instead of modal detours. Icon-led cells omit noisy uppercase eyebrow text on the bar and keep explanations in accessible tooltips.

Install UI SDK & packages

npm install @ui-sdk/react @ui-sdk/core lucide-react

Give your agent the UI SDK skill

npx skills add vercel-labs/ui --skill ui-sdk

UI SDK entries: @ui-sdk/react/popover @ui-sdk/react/button
"use client";

import * as React from "react";
import { Check, ChevronDown, MessageSquare, Sparkles, User, Users } from "lucide-react";
import type { LucideIcon } from "lucide-react";
import { Button } from "@ui-sdk/react/button";
import { Popover, PopoverContent, PopoverTrigger } from "@ui-sdk/react/popover";

export interface ContextOption {
  id: string;
  name: string;
  sub?: string;
}

export interface ContextCell {
  id: string;
  label: string;
  icon: LucideIcon;
  options: ContextOption[];
  selectedId: string;
}

export interface BuilderContextBarProps {
  cells?: ContextCell[];
  onChange?: (cellId: string, optionId: string) => void;
  onSave?: () => void;
}

const DEFAULT_CELLS: ContextCell[] = [
  {
    id: "character",
    label: "Character picker",
    icon: User,
    selectedId: "wynter",
    options: [
      { id: "wynter", name: "Wynter Jones", sub: "Direct solo builder" },
      { id: "russell", name: "Founder Storyteller", sub: "High-energy stage voice" },
    ],
  },
  {
    id: "voice",
    label: "Voice picker",
    icon: MessageSquare,
    selectedId: "plain",
    options: [
      { id: "plain", name: "Plain & practical", sub: "Zero hype, short sentences" },
      { id: "editorial", name: "Editorial essay", sub: "Story-led newsletter cadence" },
    ],
  },
  {
    id: "audience",
    label: "Audience picker",
    icon: Users,
    selectedId: "solo",
    options: [
      { id: "solo", name: "Solo SaaS founders", sub: "Shipping fast with AI" },
      { id: "agency", name: "Marketing operators", sub: "Running client funnels" },
    ],
  },
];

/**
 * MSAI rule: changing a builder's context (who is speaking, what voice, who it's for)
 * is a SELECTION, not a modal CRUD flow — keep it inline right on the strip.
 */
export function BuilderContextBar({ cells = DEFAULT_CELLS, onChange, onSave }: BuilderContextBarProps) {
  const [selected, setSelected] = React.useState<Record<string, string>>(
    Object.fromEntries(cells.map((c) => [c.id, c.selectedId])),
  );
  const [openCell, setOpenCell] = React.useState<string | null>(null);

  return (
    <div className="flex flex-wrap items-center gap-2 rounded-2xl border border-slate-200 bg-white px-3 py-2 shadow-sm dark:border-slate-800 dark:bg-[#111827]">
      {cells.map((cell) => {
        const Icon = cell.icon;
        const cur = cell.options.find((o) => o.id === selected[cell.id]) || cell.options[0];
        return (
          <Popover
            key={cell.id}
            name={cell.label}
            open={openCell === cell.id}
            onOpenChange={(o) => setOpenCell(o ? cell.id : null)}
          >
            <PopoverTrigger asChild>
              <button
                type="button"
                aria-label={`${cell.label}: ${cur?.name}`}
                title={cell.label}
                className="inline-flex h-9 cursor-pointer items-center gap-2 rounded-xl border border-slate-200 bg-slate-50 px-3 text-xs font-bold text-slate-800 transition hover:border-slate-300 dark:border-slate-700/80 dark:bg-[#162033] dark:text-slate-100"
              >
                <Icon className="h-3.5 w-3.5 text-sky-400" />
                <span>{cur?.name}</span>
                <ChevronDown className="h-3.5 w-3.5 text-slate-400" />
              </button>
            </PopoverTrigger>
            <PopoverContent align="start" className="w-64 p-1.5">
              {cell.options.map((opt) => {
                const on = opt.id === cur?.id;
                return (
                  <button
                    key={opt.id}
                    type="button"
                    onClick={() => {
                      setSelected((prev) => ({ ...prev, [cell.id]: opt.id }));
                      onChange?.(cell.id, opt.id);
                      setOpenCell(null);
                    }}
                    className={`flex w-full cursor-pointer items-center justify-between rounded-lg px-2.5 py-2 text-left text-xs ${
                      on ? "bg-sky-500/15 font-bold" : "hover:bg-slate-100 dark:hover:bg-slate-800/70"
                    }`}
                  >
                    <span>
                      <span className="block font-semibold">{opt.name}</span>
                      {opt.sub && <span className="block text-[11px] text-slate-400">{opt.sub}</span>}
                    </span>
                    {on && <Check className="h-3.5 w-3.5 text-sky-400" />}
                  </button>
                );
              })}
            </PopoverContent>
          </Popover>
        );
      })}

      <div className="ml-auto flex items-center gap-2">
        <Button
          name="Save context"
          onClick={onSave}
          className="inline-flex h-9 items-center gap-1.5 rounded-xl bg-sky-500 px-3.5 text-xs font-bold text-slate-950"
        >
          <Sparkles className="h-3.5 w-3.5" /> Apply context
        </Button>
      </div>
    </div>
  );
}

export default BuilderContextBar;