Library MCP Setup About Template Factory ↗
← Library / Overlays & Feedback UI SDK Agentic

Unified Feedback & Help Widget

Floating corner widget with Feedback and Help in one place: category chips and a readable message box with a real sent state, searchable help articles with a reader, and an Expand mode that opens a two-column view on desktop and stays single column on phones.

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/dialog @ui-sdk/react/tabs @ui-sdk/react/segmented-control @ui-sdk/react/field @ui-sdk/react/textarea @ui-sdk/react/input @ui-sdk/react/button
"use client";

import * as React from "react";
import {
  ArrowLeft,
  Bug,
  ChevronRight,
  CircleCheck,
  CircleHelp,
  ExternalLink,
  Heart,
  LifeBuoy,
  Lightbulb,
  LoaderCircle,
  Maximize2,
  MessageSquare,
  Minimize2,
  Search,
  Send,
  X,
  type LucideIcon,
} from "lucide-react";
import { Button } from "@ui-sdk/react/button";
import { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogTitle, DialogTrigger } from "@ui-sdk/react/dialog";
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/react/field";
import { Input } from "@ui-sdk/react/input";
import { SegmentedControl, SegmentedControlItem } from "@ui-sdk/react/segmented-control";
import { Tabs, TabsList, TabsPanel, TabsTab } from "@ui-sdk/react/tabs";
import { Textarea } from "@ui-sdk/react/textarea";

const card =
  "rounded-2xl border border-[#d8e0ea] bg-white shadow-[0_18px_44px_rgba(15,23,42,0.12)] dark:border-slate-400/20 dark:bg-[#111827] dark:shadow-[0_24px_60px_rgba(0,0,0,0.5)]";
const labelCls = "block text-[13px] font-semibold leading-snug text-slate-800 dark:text-slate-200";
const hintCls = "text-xs leading-relaxed text-slate-600 dark:text-slate-400";
const errorCls = "text-xs font-semibold text-red-800 dark:text-red-300";
const fieldBase =
  "w-full min-w-0 rounded-[10px] border-[1.5px] border-slate-300 bg-white text-sm font-medium text-slate-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] outline-none transition-[border-color,box-shadow] hover:border-slate-400 focus:border-sky-600 focus:ring-[3px] focus:ring-sky-600/25 dark:border-slate-400/35 dark:bg-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_2px_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55 dark:focus:border-sky-400 dark:focus:ring-sky-400/30";
const textareaCls = `${fieldBase} min-h-[124px] resize-y px-3.5 py-3 leading-relaxed`;
const btnBase =
  "inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-[10px] font-bold transition hover:-translate-y-px active:translate-y-px disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500";
const btnMd = "h-11 px-4 text-sm";
const btnSm = "h-9 px-3 text-[13px]";
const btnPrimary = `${btnBase} border border-sky-300/60 bg-linear-to-b from-sky-300 via-sky-400 to-sky-600 text-[#031521] shadow-[inset_0_1px_0_rgba(255,255,255,0.55),inset_0_-2px_0_rgba(3,55,86,0.35),0_8px_20px_rgba(2,132,199,0.25)] hover:brightness-105`;
const btnGhost = `${btnBase} border border-slate-300 bg-linear-to-b from-white to-slate-100 text-slate-900 shadow-[inset_0_1px_0_rgba(255,255,255,0.95),inset_0_-1.5px_0_rgba(15,23,42,0.08),0_1px_2px_rgba(15,23,42,0.06)] hover:border-slate-400 dark:border-slate-400/35 dark:from-[#243047] dark:to-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.09),inset_0_-1.5px_0_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55`;

const hairline = "border-[#d8e0ea] dark:border-slate-400/20";
const tabCls =
  "inline-flex h-9 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap rounded-lg px-3 text-[13px] font-semibold text-slate-600 transition hover:bg-slate-900/5 hover:text-slate-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500 data-selected:bg-sky-700 data-selected:font-bold data-selected:text-white dark:text-slate-400 dark:hover:bg-slate-400/15 dark:hover:text-slate-50 dark:data-selected:bg-sky-400 dark:data-selected:text-[#031521]";
const chipCls =
  "inline-flex h-10 cursor-pointer items-center justify-center gap-1.5 rounded-[10px] border-[1.5px] border-slate-300 bg-white text-[13px] font-semibold text-slate-800 transition hover:border-slate-400 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500 data-checked:border-sky-700 data-checked:bg-sky-700 data-checked:font-bold data-checked:text-white dark:border-slate-400/35 dark:bg-[#182234] dark:text-slate-200 dark:hover:border-slate-400/55 dark:data-checked:border-sky-400 dark:data-checked:bg-sky-400 dark:data-checked:text-[#031521]";
const iconBtn = `${btnGhost} size-9 shrink-0`;

export type FeedbackCategory = "Idea" | "Bug" | "Question" | "Praise";
type WidgetView = "feedback" | "help";

export interface HelpArticle {
  id: string;
  title: string;
  summary: string;
  steps: string[];
  keywords?: string[];
  /** Full article link. Falls back to helpCenterUrl. */
  url?: string;
}

const CATEGORIES: { value: FeedbackCategory; icon: LucideIcon }[] = [
  { value: "Idea", icon: Lightbulb },
  { value: "Bug", icon: Bug },
  { value: "Question", icon: CircleHelp },
  { value: "Praise", icon: Heart },
];

const DEFAULT_ARTICLES: HelpArticle[] = [
  {
    id: "connect",
    title: "Connect Snow to Claude Code",
    summary: "Paste one link and your agent can browse every component.",
    steps: [
      "Open Settings and choose MCP.",
      "Copy your server URL and API token.",
      "Paste the setup command into your terminal.",
      "Ask Claude to list your Snow components.",
    ],
    keywords: ["mcp", "cursor", "codex", "agent", "token"],
  },
  {
    id: "install",
    title: "Add a component to your app",
    summary: "Copy the code yourself or ask your agent to add it by name.",
    steps: [
      "Open the component you want.",
      "Press Copy code, or ask your agent for it by name.",
      "Save it in your components folder.",
      "Swap in your own words and data.",
    ],
    keywords: ["copy", "code", "install", "use"],
  },
  {
    id: "theme",
    title: "Match your brand colors",
    summary: "Change one set of colors and every component follows.",
    steps: [
      "Open the style constants at the top of the file.",
      "Replace the sky blue values with your brand color.",
      "Check both light and dark mode before you ship.",
    ],
    keywords: ["dark", "light", "color", "style", "design"],
  },
  {
    id: "safe-agents",
    title: "Let an agent press buttons safely",
    summary: "Decide which actions need your OK before an agent can run them.",
    steps: [
      "Risky buttons carry a plain-English warning.",
      "Your app shows that warning before the agent continues.",
      "Passwords and API tokens are never shared with agents.",
    ],
    keywords: ["agent", "confirm", "permission", "security"],
  },
  {
    id: "billing",
    title: "Change or cancel your plan",
    summary: "Switch plans or cancel any time from Settings.",
    steps: [
      "Open Settings and choose Billing.",
      "Pick a new plan, or choose Cancel plan.",
      "Your work stays available until the end of the period you paid for.",
    ],
    keywords: ["price", "subscription", "refund", "invoice"],
  },
];

function ArticleList({
  articles,
  activeId,
  onOpen,
}: {
  articles: HelpArticle[];
  activeId?: string | null;
  onOpen: (id: string) => void;
}) {
  return (
    <ul className="grid gap-1">
      {articles.map((article) => (
        <li key={article.id}>
          <Button
            aria-current={article.id === activeId ? "true" : undefined}
            onClick={() => onOpen(article.id)}
            className="group flex w-full cursor-pointer items-center gap-2.5 rounded-[10px] px-3 py-2.5 text-left transition hover:bg-slate-900/5 focus-visible:outline-2 focus-visible:outline-sky-500 aria-[current=true]:bg-sky-700 aria-[current=true]:text-white dark:hover:bg-slate-400/15 dark:aria-[current=true]:bg-sky-400 dark:aria-[current=true]:text-[#031521]"
          >
            <span className="min-w-0 flex-1">
              <span className="block text-sm font-semibold">{article.title}</span>
              <span className="block text-[12.5px] leading-snug text-slate-600 group-aria-[current=true]:text-white dark:text-slate-400 dark:group-aria-[current=true]:text-[#031521]">
                {article.summary}
              </span>
            </span>
            <ChevronRight className="size-4 shrink-0" aria-hidden="true" />
          </Button>
        </li>
      ))}
    </ul>
  );
}

export function FeedbackHelpWidget({
  productName = "Snow",
  articles = DEFAULT_ARTICLES,
  helpCenterUrl = "https://help.wynter.ai/snow",
  launcherLabel = "Feedback & help",
  replyNote = "A real person reads every note. Replies usually land within a day.",
  defaultOpen = false,
  defaultView = "feedback",
  onSubmitFeedback,
}: {
  productName?: string;
  articles?: HelpArticle[];
  helpCenterUrl?: string;
  launcherLabel?: string;
  replyNote?: string;
  defaultOpen?: boolean;
  defaultView?: WidgetView;
  onSubmitFeedback?: (feedback: { category: FeedbackCategory; message: string }) => Promise<void> | void;
}) {
  const [open, setOpen] = React.useState(defaultOpen);
  const [expanded, setExpanded] = React.useState(false);
  const [view, setView] = React.useState<WidgetView>(defaultView);
  const [category, setCategory] = React.useState<FeedbackCategory>("Idea");
  const [message, setMessage] = React.useState("");
  const [error, setError] = React.useState("");
  const [status, setStatus] = React.useState<"idle" | "sending" | "sent">("idle");
  const [query, setQuery] = React.useState("");
  const [articleId, setArticleId] = React.useState<string | null>(null);
  const errorId = React.useId();

  const words = query.toLowerCase().trim().split(/\s+/).filter(Boolean);
  const matches = articles.filter((item) => {
    const haystack = `${item.title} ${item.summary} ${(item.keywords ?? []).join(" ")}`.toLowerCase();
    return words.every((word) => haystack.includes(word));
  });
  const picked = articles.find((item) => item.id === articleId) ?? null;
  // The wide view always has an article open beside the list.
  const shown = picked ?? (expanded ? (matches[0] ?? null) : null);

  const submit = async (event: React.FormEvent<HTMLFormElement>) => {
    event.preventDefault();
    if (status === "sending") return;
    if (message.trim().length < 3) {
      setError("Write a few words first so we know what to look at.");
      return;
    }
    setStatus("sending");
    try {
      await onSubmitFeedback?.({ category, message: message.trim() });
      setStatus("sent");
    } catch {
      setStatus("idle");
      setError("That didn't send. Check your connection and try again.");
    }
  };

  const startOver = (nextMessage = "") => {
    setStatus("idle");
    setError("");
    setMessage(nextMessage);
  };

  const paneCls = expanded ? "grid gap-5 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]" : "grid gap-4";

  return (
    <Dialog key={expanded ? "wide" : "compact"} open={open} onOpenChange={setOpen} modal={expanded} closeOnOutsidePress={expanded}>
      <div className={open ? "hidden" : "fixed right-3.5 bottom-3.5 z-40"}>
        <DialogTrigger className={`${btnPrimary} ${btnMd}`}>
          <MessageSquare className="size-4" aria-hidden="true" />
          <span>{launcherLabel}</span>
        </DialogTrigger>
      </div>
      {expanded && <DialogBackdrop className="fixed inset-0 z-40 bg-slate-900/45 backdrop-blur-[3px] dark:bg-[#04070d]/70" />}
      <DialogContent
        className={`${card} fixed z-50 flex flex-col overflow-hidden p-0 text-slate-900 dark:text-slate-50 ${
          expanded
            ? "inset-0 m-auto h-[min(34rem,calc(100dvh-1.75rem))] w-[min(55rem,calc(100vw-1.75rem))]"
            : "top-auto right-3.5 bottom-3.5 left-auto m-0 max-h-[calc(100dvh-1.75rem)] w-[min(25rem,calc(100vw-1.75rem))]"
        }`}
      >
        <DialogTitle className="sr-only">{productName} feedback and help</DialogTitle>
        <Tabs
          value={view}
          onValueChange={(next) => {
            if (next) setView(next);
          }}
          className="flex min-h-0 flex-1 flex-col"
        >
          <div className={`flex items-center gap-2 border-b p-2.5 ${hairline}`}>
            <TabsList
              aria-label="Feedback or help"
              className={`mr-auto flex gap-0.5 rounded-[11px] border bg-slate-50 p-[3px] dark:bg-[#162033] ${hairline}`}
            >
              <TabsTab value="feedback" className={tabCls}>
                <MessageSquare className="size-3.5" aria-hidden="true" />
                Feedback
              </TabsTab>
              <TabsTab value="help" className={tabCls}>
                <LifeBuoy className="size-3.5" aria-hidden="true" />
                Help
              </TabsTab>
            </TabsList>
            <Button aria-label="Expand" aria-pressed={expanded} onClick={() => setExpanded((value) => !value)} className={iconBtn}>
              {expanded ? <Minimize2 className="size-4" aria-hidden="true" /> : <Maximize2 className="size-4" aria-hidden="true" />}
            </Button>
            <DialogClose aria-label="Close" className={iconBtn}>
              <X className="size-4" aria-hidden="true" />
            </DialogClose>
          </div>

          <TabsPanel value="feedback" className="min-h-0 flex-1 overflow-y-auto p-4">
            <div className={paneCls}>
              {status === "sent" ? (
                <div role="status" className="grid content-start justify-items-start gap-2 rounded-xl bg-emerald-50 p-4 dark:bg-emerald-400/15">
                  <CircleCheck className="size-6 text-emerald-700 dark:text-emerald-300" aria-hidden="true" />
                  <strong className="text-base font-bold">Thanks, it&apos;s in.</strong>
                  <p className="text-[13px] text-slate-700 dark:text-slate-200">
                    Filed under {category}. {replyNote}
                  </p>
                  <Button onClick={() => startOver()} className={`${btnGhost} ${btnSm} mt-1`}>
                    Send another
                  </Button>
                </div>
              ) : (
                <form noValidate onSubmit={submit} className="grid content-start gap-3.5">
                  <Field name="category" className="flex min-w-0 flex-col gap-1.5">
                    <FieldLabel className={labelCls}>What kind of feedback?</FieldLabel>
                    <SegmentedControl
                      value={category}
                      onValueChange={(next) => {
                        if (next) setCategory(next);
                      }}
                      className="grid grid-cols-2 gap-1.5 sm:grid-cols-4"
                    >
                      {CATEGORIES.map(({ value, icon: Icon }) => (
                        <SegmentedControlItem key={value} value={value} className={chipCls}>
                          <Icon className="size-3.5" aria-hidden="true" />
                          {value}
                        </SegmentedControlItem>
                      ))}
                    </SegmentedControl>
                  </Field>

                  <Field name="message" invalid={Boolean(error)} className="flex min-w-0 flex-col gap-1.5">
                    <FieldLabel className={labelCls}>Your message</FieldLabel>
                    <Textarea
                      rows={4}
                      required
                      aria-describedby={error ? errorId : undefined}
                      value={message}
                      onValueChange={(value) => {
                        setMessage(value);
                        if (error) setError("");
                      }}
                      className={`${textareaCls} data-invalid:border-red-500 dark:data-invalid:border-red-400`}
                    />
                    <FieldDescription className={hintCls}>{replyNote}</FieldDescription>
                    {error && (
                      <p id={errorId} role="alert" className={errorCls}>
                        {error}
                      </p>
                    )}
                  </Field>

                  <Button
                    type="submit"
                    disabled={status === "sending"}
                    data-agent-confirm="Sends this feedback to the team"
                    className={`${btnPrimary} ${btnMd} w-full`}
                  >
                    {status === "sending" ? (
                      <LoaderCircle className="size-4 animate-spin" aria-hidden="true" />
                    ) : (
                      <Send className="size-4" aria-hidden="true" />
                    )}
                    <span>{status === "sending" ? "Sending…" : "Send feedback"}</span>
                  </Button>
                </form>
              )}

              {expanded && (
                <aside className="max-sm:hidden">
                  <h3 className="mb-2 px-3 text-sm font-bold tracking-tight">Quick answers</h3>
                  <ArticleList
                    articles={articles.slice(0, 3)}
                    onOpen={(id) => {
                      setArticleId(id);
                      setView("help");
                    }}
                  />
                </aside>
              )}
            </div>
          </TabsPanel>

          <TabsPanel value="help" className="min-h-0 flex-1 overflow-y-auto p-4">
            <div className={paneCls}>
              <div className={picked ? (expanded ? "grid content-start gap-3 max-sm:hidden" : "hidden") : "grid content-start gap-3"}>
                <div className="relative">
                  <Search
                    className="pointer-events-none absolute top-1/2 left-3.5 size-4 -translate-y-1/2 text-slate-600 dark:text-slate-400"
                    aria-hidden="true"
                  />
                  <Input
                    type="search"
                    aria-label="Search help articles"
                    placeholder="Search help articles"
                    value={query}
                    onValueChange={setQuery}
                    className={`${fieldBase} h-11 pr-3.5 pl-10 placeholder:text-slate-600 dark:placeholder:text-slate-400`}
                  />
                </div>
                {matches.length > 0 ? (
                  <ArticleList articles={matches} activeId={expanded ? shown?.id : null} onOpen={setArticleId} />
                ) : (
                  <div className="grid justify-items-center gap-2.5 px-3 py-6 text-center">
                    <p className="text-sm text-slate-600 dark:text-slate-400">No articles match &ldquo;{query.trim()}&rdquo;.</p>
                    <Button
                      onClick={() => {
                        startOver(query.trim());
                        setCategory("Question");
                        setView("feedback");
                      }}
                      className={`${btnGhost} ${btnSm}`}
                    >
                      Ask it as feedback instead
                    </Button>
                  </div>
                )}
              </div>

              {shown && (
                <article className={picked ? "grid content-start gap-3" : "grid content-start gap-3 max-sm:hidden"}>
                  <Button
                    onClick={() => setArticleId(null)}
                    className={`${btnGhost} ${btnSm} justify-self-start ${expanded ? "sm:hidden" : ""}`}
                  >
                    <ArrowLeft className="size-3.5" aria-hidden="true" />
                    <span>All articles</span>
                  </Button>
                  <h3 className="text-[17px] font-bold tracking-tight">{shown.title}</h3>
                  <p className="text-sm leading-relaxed text-slate-700 dark:text-slate-300">{shown.summary}</p>
                  <ol className="grid list-decimal gap-2 pl-5 text-sm leading-relaxed text-slate-800 dark:text-slate-200">
                    {shown.steps.map((step) => (
                      <li key={step}>{step}</li>
                    ))}
                  </ol>
                  <a
                    href={shown.url ?? helpCenterUrl}
                    target="_blank"
                    rel="noopener noreferrer"
                    className={`${btnGhost} ${btnSm} justify-self-start`}
                  >
                    <span>Open in Help Center</span>
                    <ExternalLink className="size-3.5" aria-hidden="true" />
                  </a>
                </article>
              )}
            </div>
          </TabsPanel>
        </Tabs>
      </DialogContent>
    </Dialog>
  );
}

export default FeedbackHelpWidget;