Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

FAQs

2 examples. Resize any preview to see it at phone and tablet widths.

FAQ

Free

Questions grouped by topic with a sliding tab, live search that highlights matches and opens the results, spring accordions and an empty state.

Hide code
components/blocks/faq.tsx
"use client";

import { useId, useMemo, useState } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { Plus, Search } from "lucide-react";
import { cn } from "@/lib/utils";

const groups = {
  Billing: [
    ["Can I change plans later?", "Yes. Upgrades apply right away and are prorated to the day. Downgrades take effect at the end of your billing period."],
    ["Do you offer refunds?", "Annual plans can be refunded in full within 14 days. Monthly plans can be canceled at any time and won't renew."],
    ["Is there a discount for startups?", "Companies under two years old with less than $1M raised get 50% off the Team plan for a year."],
  ],
  Product: [
    ["Is there a free plan?", "The Starter plan is free forever for up to 3 projects and 10k events a month. No card required."],
    ["Can I self-host?", "Self-hosting is available on the Enterprise plan with a Docker image and a Helm chart."],
    ["Which frameworks are supported?", "Next.js, Remix, Astro, SvelteKit and any server that can make HTTP requests."],
  ],
  Security: [
    ["Where is my data stored?", "In AWS us-east-1 by default, or eu-central-1 if you pick the EU region when creating a workspace."],
    ["Do you support SSO?", "SAML and OIDC single sign-on are included on Team and Enterprise, along with SCIM provisioning."],
  ],
} as const;
type Group = keyof typeof groups;
const ring = "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";

function highlight(text: string, q: string) {
  if (!q) return text;
  const i = text.toLowerCase().indexOf(q.toLowerCase());
  if (i < 0) return text;
  return (
    <>
      {text.slice(0, i)}
      <mark className="rounded-[2px] bg-amber-300/40 text-inherit dark:bg-amber-400/25">{text.slice(i, i + q.length)}</mark>
      {text.slice(i + q.length)}
    </>
  );
}

const all = (Object.keys(groups) as Group[]).flatMap((g) => groups[g].map(([q, a]) => ({ g, q: q as string, a: a as string })));
const match = (tab: Group | "All", query: string) =>
  all.filter((it) => (tab === "All" || it.g === tab) && (!query || `${it.q} ${it.a}`.toLowerCase().includes(query.toLowerCase())));

export default function FaqBlock() {
  const reduce = useReducedMotion();
  const uid = useId();
  const [tab, setTab] = useState<Group | "All">("All");
  const [q, setQ] = useState("");
  const [open, setOpen] = useState<string | null>("Can I change plans later?");
  const query = q.trim();

  const items = useMemo(() => match(tab, query), [tab, query]);

  return (
    <section className="max-w-[100vw] min-h-full w-full bg-background px-4 py-16 sm:px-6">
      <div className="mx-auto grid max-w-5xl gap-10 lg:grid-cols-[280px_1fr]">
        <div>
          <h2 className="text-2xl font-semibold tracking-tight sm:text-3xl">Questions, answered</h2>
          <p className="mt-2 text-sm text-muted-foreground">Can&apos;t find it here? Email support@northwind.dev and a human replies within a day.</p>
          <div className="relative mt-6">
            <Search className="pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" aria-hidden />
            <label htmlFor={`${uid}-q`} className="sr-only">Search questions</label>
            <input
              id={`${uid}-q`}
              type="search"
              value={q}
              onChange={(e) => {
                setQ(e.target.value);
                const first = e.target.value.trim() && match(tab, e.target.value.trim())[0];
                if (first) setOpen(first.q);
              }}
              placeholder="Search questions"
              className="h-9 w-full rounded-md border border-border bg-card pl-8 pr-3 text-sm shadow-[inset_0_1px_2px_rgb(0_0_0/0.06)] outline-none transition-[border-color,box-shadow] placeholder:text-muted-foreground focus:border-foreground/30 focus:shadow-[0_0_0_3px_color-mix(in_oklab,var(--foreground)_8%,transparent)]"
            />
          </div>
          <div role="tablist" aria-label="Topics" className="mt-4 flex flex-wrap gap-1 lg:flex-col">
            {(["All", ...Object.keys(groups)] as (Group | "All")[]).map((g) => (
              <button
                key={g}
                role="tab"
                type="button"
                aria-selected={tab === g}
                onClick={() => setTab(g)}
                className={cn(
                  "relative h-8 rounded-md px-2.5 text-left text-[13px] font-medium transition-colors",
                  tab === g ? "text-foreground" : "text-muted-foreground hover:text-foreground",
                  ring,
                )}
              >
                {tab === g ? <motion.span layoutId={`${uid}-tab`} transition={{ type: "spring", stiffness: 500, damping: 38 }} className="absolute inset-0 rounded-md bg-muted" /> : null}
                <span className="relative flex items-center justify-between gap-3">
                  {g}
                  <span className="text-xs tabular-nums text-muted-foreground">{g === "All" ? Object.values(groups).flat().length : groups[g].length}</span>
                </span>
              </button>
            ))}
          </div>
        </div>

        <div className="min-w-0">
          <p className="sr-only" aria-live="polite">{items.length} questions</p>
          <ul className="divide-y divide-border border-y border-border">
            <AnimatePresence initial={false} mode="popLayout">
              {items.map((it) => {
                const isOpen = open === it.q;
                const id = `${uid}-${it.q.replace(/\W/g, "")}`;
                return (
                  <motion.li key={it.q} layout={!reduce} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.18 }}>
                    <h3>
                      <button
                        type="button"
                        aria-expanded={isOpen}
                        aria-controls={id}
                        onClick={() => setOpen(open === it.q ? null : it.q)}
                        className={cn("group flex w-full items-center justify-between gap-4 py-4 text-left text-[15px] font-medium", ring)}
                      >
                        <span>{highlight(it.q, query)}</span>
                        <span className={cn("grid size-6 shrink-0 place-items-center rounded-md border border-border bg-card shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_1px_rgb(0_0_0/0.05)] transition-colors group-hover:bg-muted", isOpen && "bg-muted")}>
                          <motion.span animate={{ rotate: isOpen ? 45 : 0 }} transition={{ type: "spring", stiffness: 500, damping: 30 }}>
                            <Plus className="size-3.5" aria-hidden />
                          </motion.span>
                        </span>
                      </button>
                    </h3>
                    <AnimatePresence initial={false}>
                      {isOpen ? (
                        <motion.div
                          id={id}
                          initial={{ height: 0, opacity: 0 }}
                          animate={{ height: "auto", opacity: 1 }}
                          exit={{ height: 0, opacity: 0 }}
                          transition={reduce ? { duration: 0 } : { type: "spring", stiffness: 420, damping: 38 }}
                          className="overflow-hidden"
                        >
                          <p className="max-w-prose pb-4 pr-10 text-sm leading-relaxed text-muted-foreground">{highlight(it.a, query)}</p>
                        </motion.div>
                      ) : null}
                    </AnimatePresence>
                  </motion.li>
                );
              })}
            </AnimatePresence>
          </ul>
          {!items.length ? (
            <div className="py-12 text-center">
              <p className="text-sm font-medium">No questions match &ldquo;{query}&rdquo;</p>
              <button type="button" onClick={() => (setQ(""), setTab("All"))} className={cn("mt-2 rounded-sm text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground", ring)}>
                Clear search
              </button>
            </div>
          ) : null}
        </div>
      </div>
    </section>
  );
}

Two-Column FAQ

Free

Questions grouped by topic with every answer visible, for pages where nothing should hide behind a click.