{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"sliding-tabs","type":"registry:ui","title":"Sliding tabs","description":"Accessible tabs with a spring animated sliding pill, arrow key navigation and a soft content crossfade.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/sliding-tabs/sliding-tabs.tsx","type":"registry:ui","target":"components/facade/sliding-tabs.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SlidingTab {\n  /** Unique value for the tab. */\n  value: string;\n  /** Label shown in the tab list. */\n  label: React.ReactNode;\n  /** Optional icon shown before the label. */\n  icon?: React.ReactNode;\n  /** Panel content. */\n  content?: React.ReactNode;\n  disabled?: boolean;\n}\n\nexport interface SlidingTabsProps {\n  tabs: SlidingTab[];\n  /** Controlled value. */\n  value?: string;\n  /** Initial value when uncontrolled. Defaults to the first tab. */\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** Accessible label for the tab list. */\n  label?: string;\n  /** Stretch tabs to fill the width. */\n  fullWidth?: boolean;\n  className?: string;\n  listClassName?: string;\n  panelClassName?: string;\n}\n\nexport function SlidingTabs({\n  tabs,\n  value,\n  defaultValue,\n  onValueChange,\n  label = \"Tabs\",\n  fullWidth = false,\n  className,\n  listClassName,\n  panelClassName,\n}: SlidingTabsProps) {\n  const reduce = useReducedMotion();\n  const id = React.useId();\n  const [internal, setInternal] = React.useState(defaultValue ?? tabs[0]?.value ?? \"\");\n  const active = value ?? internal;\n  const refs = React.useRef<Map<string, HTMLButtonElement>>(new Map());\n\n  const select = (v: string) => {\n    if (value === undefined) setInternal(v);\n    onValueChange?.(v);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const enabled = tabs.filter((t) => !t.disabled);\n    const idx = enabled.findIndex((t) => t.value === active);\n    let next: SlidingTab | undefined;\n    if (e.key === \"ArrowRight\") next = enabled[(idx + 1) % enabled.length];\n    else if (e.key === \"ArrowLeft\") next = enabled[(idx - 1 + enabled.length) % enabled.length];\n    else if (e.key === \"Home\") next = enabled[0];\n    else if (e.key === \"End\") next = enabled[enabled.length - 1];\n    if (!next) return;\n    e.preventDefault();\n    select(next.value);\n    refs.current.get(next.value)?.focus();\n  };\n\n  const current = tabs.find((t) => t.value === active);\n\n  return (\n    <div className={cn(\"w-full\", className)}>\n      <div\n        role=\"tablist\"\n        aria-label={label}\n        aria-orientation=\"horizontal\"\n        onKeyDown={onKeyDown}\n        className={cn(\n          \"relative inline-flex items-center gap-1 rounded-full bg-muted p-1\",\n          fullWidth && \"flex w-full\",\n          listClassName,\n        )}\n      >\n        {tabs.map((t) => {\n          const selected = t.value === active;\n          return (\n            <button\n              key={t.value}\n              ref={(el) => {\n                if (el) refs.current.set(t.value, el);\n                else refs.current.delete(t.value);\n              }}\n              type=\"button\"\n              role=\"tab\"\n              id={`${id}-tab-${t.value}`}\n              aria-selected={selected}\n              aria-controls={`${id}-panel-${t.value}`}\n              tabIndex={selected ? 0 : -1}\n              disabled={t.disabled}\n              onClick={() => select(t.value)}\n              className={cn(\n                \"relative inline-flex h-9 items-center justify-center gap-1.5 rounded-full px-4 text-sm font-medium transition-colors duration-200\",\n                \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-muted\",\n                \"disabled:pointer-events-none disabled:opacity-40 [&_svg]:size-4\",\n                fullWidth && \"flex-1\",\n                selected ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\",\n              )}\n            >\n              {selected ? (\n                <motion.span\n                  layoutId={`${id}-pill`}\n                  aria-hidden\n                  className=\"absolute inset-0 rounded-full bg-background shadow-sm shadow-foreground/[0.08] dark:bg-foreground/[0.12] dark:shadow-none\"\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 380, damping: 34 }}\n                />\n              ) : null}\n              <span className=\"relative z-10 inline-flex items-center gap-1.5\">\n                {t.icon}\n                {t.label}\n              </span>\n            </button>\n          );\n        })}\n      </div>\n\n      <div className={cn(\"relative mt-4\", panelClassName)}>\n        <AnimatePresence mode=\"wait\" initial={false}>\n          {current ? (\n            <motion.div\n              key={current.value}\n              role=\"tabpanel\"\n              id={`${id}-panel-${current.value}`}\n              aria-labelledby={`${id}-tab-${current.value}`}\n              tabIndex={0}\n              initial={reduce ? { opacity: 0 } : { opacity: 0, y: 6 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={reduce ? { opacity: 0 } : { opacity: 0, y: -4 }}\n              transition={{ duration: 0.3, ease: [0.16, 1, 0.3, 1] }}\n              className=\"rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n            >\n              {current.content}\n            </motion.div>\n          ) : null}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nexport default SlidingTabs;\n"}],"categories":["navigation"],"meta":{"tier":"free","demo":"import { ArrowRight, Building2, Home, Key, MapPin, Search } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\nimport { SlidingTabs } from \"./sliding-tabs\";\n\nfunction Field({ label, children }: { label: string; children: ReactNode }) {\n  return (\n    <label className=\"flex h-14 min-w-0 flex-1 flex-col justify-center rounded-xl bg-background px-4 transition-shadow focus-within:ring-2 focus-within:ring-ring dark:bg-foreground/[0.08]\">\n      <span className=\"text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground\">{label}</span>\n      {children}\n    </label>\n  );\n}\n\nconst inputCls =\n  \"mt-0.5 w-full bg-transparent text-[15px] font-medium text-foreground placeholder:text-muted-foreground/70 focus:outline-none\";\n\nfunction SearchPane({ cta, priceLabel, pricePlaceholder }: { cta: string; priceLabel: string; pricePlaceholder: string }) {\n  return (\n    <div className=\"flex flex-col gap-2 rounded-[24px] bg-muted p-3 sm:flex-row sm:items-center\">\n      <Field label=\"Location\">\n        <span className=\"mt-0.5 flex items-center gap-2\">\n          <MapPin className=\"size-4 shrink-0 text-muted-foreground\" />\n          <input className=\"w-full bg-transparent text-[15px] font-medium text-foreground focus:outline-none\" defaultValue=\"Austin, TX\" aria-label=\"Location\" />\n        </span>\n      </Field>\n      <Field label={priceLabel}>\n        <input className={inputCls} placeholder={pricePlaceholder} aria-label={priceLabel} />\n      </Field>\n      <Field label=\"Beds\">\n        <input className={inputCls} placeholder=\"Any\" aria-label=\"Beds\" />\n      </Field>\n      <button\n        type=\"button\"\n        className=\"inline-flex h-14 shrink-0 items-center justify-center gap-2 rounded-full bg-brand px-6 text-[15px] font-medium text-brand-foreground transition-colors hover:bg-brand/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-muted\"\n      >\n        <Search className=\"size-4\" />\n        {cta}\n      </button>\n    </div>\n  );\n}\n\nfunction SellPane() {\n  return (\n    <div className=\"flex flex-col gap-5 rounded-[24px] bg-muted p-6 sm:flex-row sm:items-center\">\n      <div className=\"flex-1\">\n        <p className=\"text-[15px] font-semibold tracking-[-0.01em]\">Homes in 78704 sold for 3.2% over asking last quarter</p>\n        <p className=\"mt-1 text-[15px] text-muted-foreground\">Get a free valuation from a local agent within 24 hours.</p>\n      </div>\n      <button\n        type=\"button\"\n        className=\"group inline-flex h-12 shrink-0 items-center justify-center gap-2 rounded-full bg-brand px-6 text-[15px] font-medium text-brand-foreground transition-colors hover:bg-brand/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-muted\"\n      >\n        Value my home\n        <ArrowRight className=\"size-4 transition-transform group-hover:translate-x-0.5\" />\n      </button>\n    </div>\n  );\n}\n\nexport default function Demo() {\n  return (\n    <div className=\"w-full max-w-2xl\">\n      <h3 className=\"mb-6 font-display text-[28px] font-semibold tracking-[-0.03em] sm:text-[34px]\">Your next move, in Austin</h3>\n      <SlidingTabs\n        label=\"Search mode\"\n        tabs={[\n          {\n            value: \"buy\",\n            label: \"Buy\",\n            icon: <Home />,\n            content: <SearchPane cta=\"Search\" priceLabel=\"Max price\" pricePlaceholder=\"$750,000\" />,\n          },\n          {\n            value: \"rent\",\n            label: \"Rent\",\n            icon: <Key />,\n            content: <SearchPane cta=\"Search\" priceLabel=\"Monthly budget\" pricePlaceholder=\"$2,800 / mo\" />,\n          },\n          { value: \"sell\", label: \"Sell\", icon: <Building2 />, content: <SellPane /> },\n        ]}\n      />\n      <p className=\"mt-4 text-[13px] text-muted-foreground\">Use the arrow keys to switch tabs.</p>\n    </div>\n  );\n}\n"}}