{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"react-tabs-with-sliding-underline-segmented-pills-vertical-and-icon-count-variants","type":"registry:component","title":"React Tabs with Sliding Underline, Segmented Pills, Vertical and Icon Count Variants","description":"Free accessible React tabs in four styles: sliding underline, segmented pill, vertical and icons with counts. Arrow keys, Home and End, Tailwind.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/react-tabs-with-sliding-underline-segmented-pills-vertical-and-icon-count-variants.tsx","type":"registry:component","content":"import { useEffect, useId, useRef, useState, type KeyboardEvent, type ReactNode } from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\n\n/* ---------- Content: edit the tabs here ---------- */\n\nconst underlineTabs = [\n  { label: \"Overview\", body: \"Fernleigh Ledger keeps every invoice, receipt and payout in one searchable place. Most teams finish setup in an afternoon.\" },\n  { label: \"Integrations\", body: \"Connect your bank feeds, payroll and storefront. Transactions arrive overnight and are matched to open invoices automatically.\" },\n  { label: \"Billing\", body: \"You are on the Team plan, billed yearly. Your next renewal is on 14 March for $1,140 across six seats.\" },\n  { label: \"Activity\", body: \"Priya approved three expense reports and Tomasz exported the Q3 profit and loss statement this morning.\" },\n];\n\nconst segmentTabs = [\n  { label: \"Day\", value: \"$2,480\", note: \"Revenue today, up from $2,110 yesterday\" },\n  { label: \"Week\", value: \"$16,920\", note: \"Revenue this week across 412 orders\" },\n  { label: \"Month\", value: \"$71,305\", note: \"Revenue in October so far, 18 days in\" },\n  { label: \"Year\", value: \"$604,770\", note: \"Revenue since January across all stores\" },\n];\n\nconst verticalTabs = [\n  { label: \"Profile\", title: \"Public profile\", body: \"Your name, photo and short bio appear on shared documents and in comment threads.\" },\n  { label: \"Security\", title: \"Sign-in and security\", body: \"Two-step sign-in is on. You last changed your password 41 days ago from a laptop in Lisbon.\" },\n  { label: \"Notifications\", title: \"Email notifications\", body: \"You get a daily summary at 8:00 and an instant email when someone mentions you.\" },\n  { label: \"Team\", title: \"Team members\", body: \"Six people share this workspace. Two invitations are still waiting to be accepted.\" },\n];\n\ntype IconName = \"inbox\" | \"flag\" | \"check\" | \"archive\";\nconst iconTabs: { label: string; icon: IconName; count: number; rows: string[] }[] = [\n  { label: \"Inbox\", icon: \"inbox\", count: 12, rows: [\"Refund request from Mara Okafor\", \"Shipping question on order 4471\", \"Invoice copy for Hollis & Reed\"] },\n  { label: \"Flagged\", icon: \"flag\", count: 3, rows: [\"Chargeback opened on order 4390\", \"Address mismatch on order 4462\"] },\n  { label: \"Solved\", icon: \"check\", count: 128, rows: [\"Password reset for Dev Kapoor\", \"Bulk discount for Linden School\"] },\n  { label: \"Archive\", icon: \"archive\", count: 0, rows: [] },\n];\n\n/** Preview only: the first two demos step through their tabs until someone touches them. Set to false in your app. */\nconst DEMO_AUTOPLAY = true;\n\n/* ---------- Shared keyboard behaviour (WAI-ARIA tabs pattern) ---------- */\n\nfunction useTabs(count: number, orientation: \"horizontal\" | \"vertical\" = \"horizontal\", autoplay = false) {\n  const [active, setActive] = useState(0);\n  const [touched, setTouched] = useState(false);\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n  const baseId = useId();\n  const reduce = useReducedMotion();\n\n  useEffect(() => {\n    if (!DEMO_AUTOPLAY || !autoplay || touched || reduce) return;\n    const t = window.setInterval(() => setActive((a) => (a + 1) % count), 1400);\n    return () => window.clearInterval(t);\n  }, [autoplay, touched, reduce, count]);\n\n  const focusTab = (i: number) => {\n    setTouched(true);\n    setActive(i);\n    refs.current[i]?.focus();\n  };\n\n  const onKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {\n    const next = orientation === \"vertical\" ? \"ArrowDown\" : \"ArrowRight\";\n    const prev = orientation === \"vertical\" ? \"ArrowUp\" : \"ArrowLeft\";\n    let target: number | null = null;\n    if (e.key === next) target = (active + 1) % count;\n    else if (e.key === prev) target = (active - 1 + count) % count;\n    else if (e.key === \"Home\") target = 0;\n    else if (e.key === \"End\") target = count - 1;\n    if (target !== null) {\n      e.preventDefault();\n      focusTab(target);\n    }\n  };\n\n  const tabProps = (i: number) => ({\n    ref: (el: HTMLButtonElement | null) => {\n      refs.current[i] = el;\n    },\n    id: `${baseId}-tab-${i}`,\n    role: \"tab\" as const,\n    type: \"button\" as const,\n    \"aria-selected\": active === i,\n    \"aria-controls\": `${baseId}-panel-${i}`,\n    tabIndex: active === i ? 0 : -1,\n    onClick: () => {\n      setTouched(true);\n      setActive(i);\n    },\n    onFocus: () => setTouched(true),\n    onKeyDown,\n  });\n\n  const panelProps = (i: number) => ({\n    id: `${baseId}-panel-${i}`,\n    role: \"tabpanel\" as const,\n    \"aria-labelledby\": `${baseId}-tab-${i}`,\n    tabIndex: 0,\n    hidden: active !== i,\n  });\n\n  return { active, tabProps, panelProps, layoutKey: baseId };\n}\n\nfunction useSpring() {\n  const reduce = useReducedMotion();\n  return reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 520, damping: 40, mass: 0.9 };\n}\n\n/* ---------- Variant 1: underline with sliding indicator ---------- */\n\nfunction UnderlineTabs() {\n  const { active, tabProps, panelProps, layoutKey } = useTabs(underlineTabs.length, \"horizontal\", true);\n  const spring = useSpring();\n  return (\n    <div>\n      <div role=\"tablist\" aria-label=\"Account sections\" className=\"flex gap-1 overflow-x-auto border-b border-stone-200 [scrollbar-width:none] [mask-image:linear-gradient(to_right,black_85%,transparent)] sm:[mask-image:none]\">\n        {underlineTabs.map((t, i) => (\n          <button\n            key={t.label}\n            {...tabProps(i)}\n            className={`relative shrink-0 rounded-t-md px-3 pb-3 pt-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#1d4ed8] ${\n              active === i ? \"text-stone-900\" : \"text-stone-600 hover:text-stone-900\"\n            }`}\n          >\n            {t.label}\n            {active === i && (\n              <motion.span\n                layoutId={`${layoutKey}-underline`}\n                transition={spring}\n                className=\"absolute inset-x-2 -bottom-px h-[2px] rounded-full bg-blue-700\"\n              />\n            )}\n          </button>\n        ))}\n      </div>\n      {underlineTabs.map((t, i) => (\n        <div key={t.label} {...panelProps(i)} className=\"-mx-2 mt-2 rounded-md px-2 py-2 text-sm leading-6 text-stone-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1d4ed8]\">\n          {t.body}\n        </div>\n      ))}\n    </div>\n  );\n}\n\n/* ---------- Variant 2: pill / segmented control ---------- */\n\nfunction SegmentedTabs() {\n  const { active, tabProps, panelProps, layoutKey } = useTabs(segmentTabs.length, \"horizontal\", true);\n  const spring = useSpring();\n  return (\n    <div>\n      <div role=\"tablist\" aria-label=\"Revenue period\" className=\"grid grid-cols-4 rounded-full bg-stone-200/70 p-1\">\n        {segmentTabs.map((t, i) => (\n          <button\n            key={t.label}\n            {...tabProps(i)}\n            className={`relative h-10 rounded-full text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1d4ed8] ${\n              active === i ? \"text-stone-900\" : \"text-stone-600 hover:text-stone-900\"\n            }`}\n          >\n            {active === i && (\n              <motion.span\n                layoutId={`${layoutKey}-pill`}\n                transition={spring}\n                className=\"absolute inset-0 rounded-full bg-white shadow-[0_1px_2px_rgba(28,25,23,0.12),0_2px_8px_rgba(28,25,23,0.06)]\"\n              />\n            )}\n            <span className=\"relative z-10\">{t.label}</span>\n          </button>\n        ))}\n      </div>\n      {segmentTabs.map((t, i) => (\n        <div key={t.label} {...panelProps(i)} className=\"rounded-md pt-5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1d4ed8] focus-visible:ring-offset-4\">\n          <p className=\"text-3xl font-semibold tracking-tight text-stone-900 [font-variant-numeric:tabular-nums]\">{t.value}</p>\n          <p className=\"mt-1 text-sm text-stone-600\">{t.note}</p>\n        </div>\n      ))}\n    </div>\n  );\n}\n\n/* ---------- Variant 3: vertical ---------- */\n\nfunction VerticalTabs() {\n  const { active, tabProps, panelProps, layoutKey } = useTabs(verticalTabs.length, \"vertical\");\n  const spring = useSpring();\n  return (\n    <div className=\"flex gap-5\">\n      <div role=\"tablist\" aria-label=\"Settings\" aria-orientation=\"vertical\" className=\"flex w-32 shrink-0 flex-col gap-0.5 border-l border-stone-200 sm:w-36\">\n        {verticalTabs.map((t, i) => (\n          <button\n            key={t.label}\n            {...tabProps(i)}\n            className={`relative -ml-px h-10 rounded-r-md pl-4 pr-2 text-left text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#0f766e] ${\n              active === i ? \"text-[#0f766e]\" : \"text-stone-600 hover:text-stone-900\"\n            }`}\n          >\n            {active === i && (\n              <motion.span\n                layoutId={`${layoutKey}-rail`}\n                transition={spring}\n                className=\"absolute inset-y-1 left-0 w-[2px] rounded-full bg-[#0f766e]\"\n              />\n            )}\n            {active === i && (\n              <motion.span\n                layoutId={`${layoutKey}-wash`}\n                transition={spring}\n                className=\"absolute inset-y-0 left-[2px] right-0 rounded-r-md bg-[#0f766e]/[0.07]\"\n              />\n            )}\n            <span className=\"relative z-10\">{t.label}</span>\n          </button>\n        ))}\n      </div>\n      {verticalTabs.map((t, i) => (\n        <div key={t.label} {...panelProps(i)} className=\"min-w-0 flex-1 rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#0f766e]\">\n          <h3 className=\"text-sm font-semibold text-stone-900\">{t.title}</h3>\n          <p className=\"mt-1.5 text-sm leading-6 text-stone-600\">{t.body}</p>\n        </div>\n      ))}\n    </div>\n  );\n}\n\n/* ---------- Variant 4: icons and counts ---------- */\n\nfunction Icon({ name }: { name: IconName }) {\n  const paths: Record<IconName, ReactNode> = {\n    inbox: <path d=\"M3 12h4l1.5 2.5h3L13 12h4M4.5 5h11l1.5 7v3.5a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V12l1.5-7Z\" />,\n    flag: <path d=\"M5 17V3.5m0 0h9l-2 3.5 2 3.5H5\" />,\n    check: <path d=\"m4.5 10.5 3.5 3.5 7.5-8\" />,\n    archive: <path d=\"M3 4.5h14v3H3zM4.5 7.5V16h11V7.5M8 10.5h4\" />,\n  };\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.6} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      {paths[name]}\n    </svg>\n  );\n}\n\nfunction IconCountTabs() {\n  const { active, tabProps, panelProps, layoutKey } = useTabs(iconTabs.length);\n  const spring = useSpring();\n  return (\n    <div>\n      <div role=\"tablist\" aria-label=\"Support queues\" className=\"flex gap-0.5 overflow-x-auto [scrollbar-width:none] [mask-image:linear-gradient(to_right,black_82%,transparent)] sm:[mask-image:none]\">\n        {iconTabs.map((t, i) => (\n          <button\n            key={t.label}\n            {...tabProps(i)}\n            aria-label={`${t.label}, ${t.count} ${t.count === 1 ? \"conversation\" : \"conversations\"}`}\n            className={`relative flex h-10 shrink-0 items-center gap-1.5 rounded-lg px-2.5 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#fbbf24] ${\n              active === i ? \"text-white\" : \"text-stone-400 hover:text-stone-100\"\n            }`}\n          >\n            {active === i && (\n              <motion.span layoutId={`${layoutKey}-chip`} transition={spring} className=\"absolute inset-0 rounded-lg bg-white/[0.09] ring-1 ring-inset ring-white/10\" />\n            )}\n            <span className=\"relative z-10\"><Icon name={t.icon} /></span>\n            <span className=\"relative z-10\">{t.label}</span>\n            {t.count > 0 && <span\n              className={`relative z-10 min-w-[1.5rem] rounded-full px-1.5 py-0.5 text-center text-xs font-semibold [font-variant-numeric:tabular-nums] transition-colors ${\n                active === i ? \"bg-[#fbbf24] text-stone-950\" : \"bg-white/[0.08] text-stone-400\"\n              }`}\n            >\n              {t.count}\n            </span>}\n          </button>\n        ))}\n      </div>\n      {iconTabs.map((t, i) => (\n        <div key={t.label} {...panelProps(i)} className=\"mt-4 rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#fbbf24]\">\n          {t.rows.length ? (\n            <ul className=\"divide-y divide-white/[0.07] border-y border-white/[0.07]\">\n              {t.rows.map((r) => (\n                <li key={r} className=\"py-2.5 text-sm text-stone-300\">{r}</li>\n              ))}\n            </ul>\n          ) : (\n            <p className=\"py-2.5 text-sm text-stone-400\">Nothing archived yet. Closed conversations move here after 30 days.</p>\n          )}\n        </div>\n      ))}\n    </div>\n  );\n}\n\n/* ---------- Showcase ---------- */\n\nfunction Card({ title, dark, children }: { title: string; dark?: boolean; children: ReactNode }) {\n  return (\n    <section\n      className={`min-w-0 rounded-2xl p-5 sm:p-6 ${\n        dark ? \"bg-[#161412] shadow-[0_1px_0_rgba(255,255,255,0.06)_inset,0_10px_30px_-12px_rgba(0,0,0,0.5)]\" : \"bg-white shadow-[0_0_0_1px_rgba(28,25,23,0.06),0_8px_24px_-12px_rgba(28,25,23,0.18)]\"\n      }`}\n    >\n      <h2 className={`mb-4 text-xs font-semibold uppercase tracking-[0.12em] ${dark ? \"text-stone-400\" : \"text-stone-500\"}`}>{title}</h2>\n      {children}\n    </section>\n  );\n}\n\nexport default function ReactTabsVariants() {\n  return (\n    <div className=\"flex min-h-[640px] items-center bg-[#f3f1ec] px-4 py-10 font-['Inter_Tight','Inter',ui-sans-serif,system-ui,sans-serif] sm:px-8 sm:py-14\">\n      <div className=\"mx-auto grid w-full max-w-5xl gap-5 md:grid-cols-2\">\n        <Card title=\"Underline\">\n          <UnderlineTabs />\n        </Card>\n        <Card title=\"Segmented\">\n          <SegmentedTabs />\n        </Card>\n        <Card title=\"Vertical\">\n          <VerticalTabs />\n        </Card>\n        <Card title=\"Icons and counts\" dark>\n          <IconCountTabs />\n        </Card>\n      </div>\n    </div>\n  );\n}\n"}]}
