{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"segmented-pill-tabs-for-switching-views","type":"registry:component","title":"Segmented Pill Tabs for Switching Views","description":"","dependencies":[],"files":[{"path":"components/we-inc/segmented-pill-tabs-for-switching-views.tsx","type":"registry:component","content":"import { useRef, useState, type KeyboardEvent } from \"react\";\n\n// Three views of the same race list. Edit labels and rows here.\nconst views = [\"List\", \"Map\", \"Calendar\"] as const;\nconst races = [\n  { name: \"Cobbler's Ridge 25K\", date: \"Sat 8 Nov\", place: \"Ashby Woods\", climb: \"740 m\" },\n  { name: \"Lantern Night Trail 12K\", date: \"Fri 21 Nov\", place: \"Old Quarry\", climb: \"310 m\" },\n  { name: \"Frostback Fell Race\", date: \"Sun 7 Dec\", place: \"High Cairn\", climb: \"1,120 m\" },\n];\n\nexport default function SegmentedPillTabsForSwitchingViews() {\n  const [active, setActive] = useState(0);\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n\n  const onKey = (e: KeyboardEvent<HTMLDivElement>) => {\n    const last = views.length - 1;\n    const next = { ArrowRight: active === last ? 0 : active + 1, ArrowLeft: active === 0 ? last : active - 1, Home: 0, End: last }[e.key];\n    if (next === undefined) return;\n    e.preventDefault();\n    setActive(next);\n    refs.current[next]?.focus();\n  };\n\n  return (\n    <div className=\"bg-stone-950 px-4 py-12 sm:px-8\">\n      <div className=\"mx-auto max-w-xl\">\n        <div className=\"flex flex-wrap items-center justify-between gap-4\">\n          <h2 className=\"text-lg font-semibold text-stone-100\">Upcoming races</h2>\n          <div role=\"tablist\" aria-label=\"Race view\" onKeyDown={onKey} className=\"relative grid grid-cols-3 rounded-full bg-stone-800 p-1\">\n            <span\n              aria-hidden=\"true\"\n              className=\"absolute inset-y-1 left-1 w-[calc((100%-0.5rem)/3)] rounded-full bg-amber-400 transition-transform duration-300 ease-out motion-reduce:transition-none\"\n              style={{ transform: `translateX(${active * 100}%)` }}\n            />\n            {views.map((v, i) => (\n              <button\n                key={v}\n                ref={(el) => { refs.current[i] = el; }}\n                id={`spt-tab-${i}`}\n                role=\"tab\"\n                type=\"button\"\n                aria-selected={i === active}\n                aria-controls={`spt-panel-${i}`}\n                tabIndex={i === active ? 0 : -1}\n                onClick={() => setActive(i)}\n                className={`relative h-10 rounded-full px-5 text-sm font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-200 ${i === active ? \"text-stone-950\" : \"text-stone-300 hover:text-white\"}`}\n              >\n                {v}\n              </button>\n            ))}\n          </div>\n        </div>\n\n        <div id=\"spt-panel-0\" role=\"tabpanel\" aria-labelledby=\"spt-tab-0\" tabIndex={0} hidden={active !== 0} className=\"mt-6 rounded-2xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-200\">\n          <ul className=\"divide-y divide-stone-800 rounded-2xl bg-stone-900\">\n            {races.map((r) => (\n              <li key={r.name} className=\"flex items-center justify-between gap-4 p-4\">\n                <div>\n                  <p className=\"font-medium text-stone-100\">{r.name}</p>\n                  <p className=\"text-sm text-stone-400\">{r.date} · {r.place}</p>\n                </div>\n                <span className=\"shrink-0 text-sm tabular-nums text-amber-300\">{r.climb}</span>\n              </li>\n            ))}\n          </ul>\n        </div>\n        <div id=\"spt-panel-1\" role=\"tabpanel\" aria-labelledby=\"spt-tab-1\" tabIndex={0} hidden={active !== 1} className=\"mt-6 rounded-2xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-200\">\n          <svg viewBox=\"0 0 400 210\" className=\"h-auto w-full rounded-2xl bg-stone-900\" role=\"img\" aria-label=\"Map with three race starts marked\">\n            <path d=\"M0 150 C80 120 120 170 200 130 S330 80 400 110\" fill=\"none\" stroke=\"#44403c\" strokeWidth=\"18\" />\n            <path d=\"M40 0 C70 60 30 120 90 210\" fill=\"none\" stroke=\"#292524\" strokeWidth=\"10\" />\n            {[[110, 70], [240, 120], [330, 55]].map(([x, y], i) => (\n              <g key={i}><circle cx={x} cy={y} r=\"14\" fill=\"#fbbf24\" opacity=\".25\" /><circle cx={x} cy={y} r=\"6\" fill=\"#fbbf24\" /></g>\n            ))}\n          </svg>\n        </div>\n        <div id=\"spt-panel-2\" role=\"tabpanel\" aria-labelledby=\"spt-tab-2\" tabIndex={0} hidden={active !== 2} className=\"mt-6 rounded-2xl bg-stone-900 p-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-200\">\n          <ul className=\"grid grid-cols-3 gap-3 text-center\">\n            {races.map((r) => (\n              <li key={r.name} className=\"rounded-xl bg-stone-800 p-3\">\n                <p className=\"text-xs uppercase tracking-wider text-stone-400\">{r.date.split(\" \")[0]}</p>\n                <p className=\"text-2xl font-semibold text-amber-300\">{r.date.split(\" \")[1]}</p>\n                <p className=\"text-xs text-stone-300\">{r.date.split(\" \")[2]}</p>\n              </li>\n            ))}\n          </ul>\n        </div>\n      </div>\n    </div>\n  );\n}\n"}]}
