{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "view-direction-switch",
  "type": "registry:component",
  "title": "Direction Switch",
  "description": "Switches between views with tabs or steps. Moving forward slides content to the left, moving back slides it to the right, and the container height eases to the new view.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "tabs",
    "steps",
    "transition",
    "direction",
    "slide",
    "height"
  ],
  "docs": "https://hyperblur.dev/effects/view-direction-switch",
  "files": [
    {
      "path": "registry/hyperblur/view-direction-switch.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/view-direction-switch.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface DirectionView {\n  id: string;\n  label: string;\n  content: React.ReactNode;\n}\n\nexport interface ViewDirectionSwitchProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  views?: DirectionView[];\n  value?: string;\n  defaultValue?: string;\n  onChange?: (id: string) => void;\n  controls?: \"tabs\" | \"steps\" | \"none\";\n  autoPlay?: number;\n  duration?: number;\n  accent?: string;\n}\n\nconst bar = (label: string, used: string, pct: number) => (\n  <div className=\"hb-za8-meter\">\n    <div className=\"hb-za8-meter-top\">\n      <span>{label}</span>\n      <b>{used}</b>\n    </div>\n    <div className=\"hb-za8-track\">\n      <i style={{ width: `${pct}%` }} />\n    </div>\n  </div>\n);\n\nconst defaults: DirectionView[] = [\n  {\n    id: \"plan\",\n    label: \"Plan\",\n    content: (\n      <div className=\"hb-za8-card\">\n        <div className=\"hb-za8-row\">\n          <div>\n            <b className=\"hb-za8-big\">Studio</b>\n            <span className=\"hb-za8-sub\">Billed monthly, renews on Nov 28</span>\n          </div>\n          <b className=\"hb-za8-price\">$24</b>\n        </div>\n        <button type=\"button\" className=\"hb-za8-btn\">Change plan</button>\n      </div>\n    ),\n  },\n  {\n    id: \"usage\",\n    label: \"Usage\",\n    content: (\n      <div className=\"hb-za8-card\">\n        {bar(\"Projects\", \"8 of 10\", 80)}\n        {bar(\"Storage\", \"41 of 50 GB\", 82)}\n        {bar(\"Seats\", \"4 of 5\", 80)}\n      </div>\n    ),\n  },\n  {\n    id: \"invoices\",\n    label: \"Invoices\",\n    content: (\n      <div className=\"hb-za8-card\">\n        {[\n          [\"Oct 28\", \"$24.00\"],\n          [\"Sep 28\", \"$24.00\"],\n          [\"Aug 28\", \"$24.00\"],\n          [\"Jul 28\", \"$19.00\"],\n        ].map(([date, amount]) => (\n          <div key={date} className=\"hb-za8-line\">\n            <span>{date}</span>\n            <span className=\"hb-za8-paid\">Paid</span>\n            <b>{amount}</b>\n          </div>\n        ))}\n      </div>\n    ),\n  },\n];\n\nconst css = `\n.hb-za8 {\n  --hb-za8-c: #2f7bff;\n  --hb-za8-t: 440ms;\n  --hb-za8-d: 1;\n  box-sizing: border-box;\n  position: relative;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-za8 *, .hb-za8 *::before, .hb-za8 *::after { box-sizing: border-box; }\n.hb-za8-tabs {\n  position: relative;\n  display: grid;\n  grid-template-columns: repeat(var(--hb-za8-n), minmax(0, 1fr));\n  padding: 3px;\n  margin-bottom: 10px;\n  background: #141414;\n  border: 1px solid #262626;\n  border-radius: 11px;\n}\n.hb-za8-pill {\n  position: absolute;\n  top: 3px;\n  bottom: 3px;\n  left: 3px;\n  width: calc((100% - 6px) / var(--hb-za8-n));\n  background: #262626;\n  border-radius: 8px;\n  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 4px 10px rgba(0, 0, 0, 0.3);\n  transform: translateX(calc(var(--hb-za8-i) * 100%));\n  transition: transform var(--hb-za8-t) cubic-bezier(0.22, 0.9, 0.24, 1);\n}\n.hb-za8-tab {\n  position: relative;\n  z-index: 1;\n  height: 30px;\n  margin: 0;\n  padding: 0 8px;\n  overflow: hidden;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 500;\n  color: #8f8f8f;\n  white-space: nowrap;\n  text-overflow: ellipsis;\n  background: transparent;\n  border: 0;\n  border-radius: 8px;\n  cursor: pointer;\n  transition: color 0.25s ease;\n}\n.hb-za8-tab:hover { color: #cfcfcf; }\n.hb-za8-tab[aria-selected=\"true\"] { color: #ffffff; }\n.hb-za8-tab:focus-visible { outline: 2px solid var(--hb-za8-c); outline-offset: -2px; }\n.hb-za8-stage { position: relative; overflow: hidden; }\n.hb-za8-view { position: relative; width: 100%; }\n.hb-za8-view[data-role=\"in\"] { animation: hb-za8-in var(--hb-za8-t) cubic-bezier(0.22, 0.9, 0.24, 1) both; }\n.hb-za8-view[data-role=\"out\"] {\n  position: absolute;\n  left: 0;\n  top: 0;\n  pointer-events: none;\n  animation: hb-za8-out var(--hb-za8-t) cubic-bezier(0.22, 0.9, 0.24, 1) both;\n}\n.hb-za8-steps { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }\n.hb-za8-dots { display: flex; align-items: center; gap: 6px; }\n.hb-za8-dot {\n  width: 6px;\n  height: 6px;\n  margin: 0;\n  padding: 0;\n  background: #333333;\n  border: 0;\n  border-radius: 999px;\n  cursor: pointer;\n  transition: width 0.35s cubic-bezier(0.22, 0.9, 0.24, 1), background 0.25s ease;\n}\n.hb-za8-dot[aria-current=\"step\"] { width: 18px; background: var(--hb-za8-c); }\n.hb-za8-dot:focus-visible { outline: 2px solid var(--hb-za8-c); outline-offset: 3px; }\n.hb-za8-nav {\n  height: 30px;\n  min-width: 68px;\n  margin: 0;\n  padding: 0 14px;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 600;\n  color: #ededed;\n  background: #171717;\n  border: 1px solid #2a2a2a;\n  border-radius: 999px;\n  cursor: pointer;\n  transition: background 0.2s ease, opacity 0.2s ease, transform 0.2s ease;\n}\n.hb-za8-nav[data-primary=\"true\"] { color: #0a0a0a; background: #ededed; border-color: #ededed; }\n.hb-za8-nav:hover:not(:disabled) { background: #202020; }\n.hb-za8-nav[data-primary=\"true\"]:hover:not(:disabled) { background: #ffffff; }\n.hb-za8-nav:active:not(:disabled) { transform: scale(0.96); }\n.hb-za8-nav:disabled { opacity: 0.35; cursor: not-allowed; }\n.hb-za8-nav:focus-visible { outline: 2px solid var(--hb-za8-c); outline-offset: 2px; }\n.hb-za8-card { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: #111111; border: 1px solid #262626; border-radius: 12px; }\n.hb-za8-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }\n.hb-za8-big { display: block; font-size: 16px; font-weight: 650; letter-spacing: -0.02em; }\n.hb-za8-sub { display: block; margin-top: 2px; font-size: 12px; color: #8f8f8f; }\n.hb-za8-price { font-size: 22px; font-weight: 650; letter-spacing: -0.03em; }\n.hb-za8-btn { align-self: flex-start; margin: 0; padding: 6px 12px; font: inherit; font-size: 12px; font-weight: 600; color: #ededed; background: #1c1c1c; border: 1px solid #2f2f2f; border-radius: 8px; cursor: pointer; }\n.hb-za8-meter { display: flex; flex-direction: column; gap: 5px; }\n.hb-za8-meter-top { display: flex; justify-content: space-between; font-size: 12px; color: #a1a1a1; }\n.hb-za8-meter-top b { font-weight: 600; color: #ededed; font-variant-numeric: tabular-nums; }\n.hb-za8-track { height: 5px; overflow: hidden; background: #262626; border-radius: 999px; }\n.hb-za8-track i { display: block; height: 100%; background: var(--hb-za8-c); border-radius: inherit; }\n.hb-za8-line { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: #cfcfcf; }\n.hb-za8-line span:first-child { flex: 1 1 auto; }\n.hb-za8-line b { font-weight: 600; color: #ededed; font-variant-numeric: tabular-nums; }\n.hb-za8-paid { padding: 1px 7px; font-size: 11px; color: #4cd08a; background: rgba(76, 208, 138, 0.12); border-radius: 999px; }\n@keyframes hb-za8-in {\n  from { opacity: 0; transform: translateX(calc(var(--hb-za8-d) * 34px)); filter: blur(3px); }\n  to { opacity: 1; transform: none; filter: blur(0); }\n}\n@keyframes hb-za8-out {\n  from { opacity: 1; transform: none; filter: blur(0); }\n  to { opacity: 0; transform: translateX(calc(var(--hb-za8-d) * -34px)); filter: blur(3px); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-za8-pill, .hb-za8-tab, .hb-za8-dot, .hb-za8-nav { transition: none; }\n  .hb-za8-view[data-role=\"in\"], .hb-za8-view[data-role=\"out\"] { animation: none; }\n}\n`;\n\nexport function ViewDirectionSwitch({\n  views,\n  value,\n  defaultValue,\n  onChange,\n  controls = \"tabs\",\n  autoPlay = 0,\n  duration = 440,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...rest\n}: ViewDirectionSwitchProps) {\n  const items = views && views.length ? views : defaults;\n  const total = items.length;\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState(defaultValue ?? items[0].id);\n  const currentId = controlled ? value : inner;\n  const found = items.findIndex((v) => v.id === currentId);\n  const index = found === -1 ? 0 : found;\n  const [shown, setShown] = React.useState(index);\n  const [leaving, setLeaving] = React.useState<{ index: number; dir: 1 | -1; key: number } | null>(null);\n  const [busy, setBusy] = React.useState(false);\n  const baseId = React.useId();\n  const stageRef = React.useRef<HTMLDivElement>(null);\n  const inRef = React.useRef<HTMLDivElement>(null);\n  const outRef = React.useRef<HTMLDivElement>(null);\n  const tabRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const latest = React.useRef(onChange);\n\n  React.useEffect(() => {\n    latest.current = onChange;\n  }, [onChange]);\n\n  if (index !== shown) {\n    setLeaving((prev) => ({ index: shown, dir: index > shown ? 1 : -1, key: (prev ? prev.key : 0) + 1 }));\n    setShown(index);\n  }\n\n  React.useLayoutEffect(() => {\n    const stage = stageRef.current;\n    const out = outRef.current;\n    const into = inRef.current;\n    if (!leaving || !stage || !out || !into) return;\n    stage.getAnimations().forEach((a) => a.cancel());\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const from = out.offsetHeight;\n    const to = into.offsetHeight;\n    if (Math.abs(from - to) < 1) return;\n    stage.animate([{ height: `${from}px` }, { height: `${to}px` }], {\n      duration,\n      easing: \"cubic-bezier(0.22, 0.9, 0.24, 1)\",\n    });\n  }, [leaving, duration]);\n\n  React.useEffect(() => {\n    if (!leaving) return;\n    const t = window.setTimeout(() => setLeaving(null), duration + 40);\n    return () => window.clearTimeout(t);\n  }, [leaving, duration]);\n\n  const go = React.useCallback(\n    (next: number, focus = false) => {\n      const clamped = Math.min(total - 1, Math.max(0, next));\n      if (clamped === index) return;\n      const id = items[clamped].id;\n      if (!controlled) setInner(id);\n      latest.current?.(id);\n      if (focus) tabRefs.current[clamped]?.focus();\n    },\n    [controlled, index, items, total],\n  );\n\n  React.useEffect(() => {\n    if (!autoPlay || busy) return;\n    const t = window.setTimeout(() => go(index >= total - 1 ? 0 : index + 1), autoPlay);\n    return () => window.clearTimeout(t);\n  }, [autoPlay, busy, index, total, go]);\n\n  const dir = leaving ? leaving.dir : 1;\n  const vars = {\n    \"--hb-za8-c\": accent,\n    \"--hb-za8-n\": total,\n    \"--hb-za8-i\": index,\n    \"--hb-za8-d\": dir,\n    \"--hb-za8-t\": `${duration}ms`,\n    ...style,\n  } as React.CSSProperties;\n\n  const panelId = `${baseId}-panel`;\n\n  return (\n    <div\n      className={`hb-za8 ${className}`}\n      style={vars}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        setBusy(true);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        setBusy(false);\n      }}\n      onFocus={(e) => {\n        onFocus?.(e);\n        setBusy(true);\n      }}\n      onBlur={(e) => {\n        onBlur?.(e);\n        setBusy(false);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-view-direction-switch\" precedence=\"default\">{css}</style>\n      {controls === \"tabs\" ? (\n        <div\n          className=\"hb-za8-tabs\"\n          role=\"tablist\"\n          aria-label=\"Views\"\n          onKeyDown={(e) => {\n            if (e.key === \"ArrowRight\") {\n              e.preventDefault();\n              go((index + 1) % total, true);\n            } else if (e.key === \"ArrowLeft\") {\n              e.preventDefault();\n              go((index - 1 + total) % total, true);\n            } else if (e.key === \"Home\") {\n              e.preventDefault();\n              go(0, true);\n            } else if (e.key === \"End\") {\n              e.preventDefault();\n              go(total - 1, true);\n            }\n          }}\n        >\n          <span className=\"hb-za8-pill\" aria-hidden=\"true\" />\n          {items.map((v, i) => (\n            <button\n              key={v.id}\n              ref={(el) => {\n                tabRefs.current[i] = el;\n              }}\n              type=\"button\"\n              role=\"tab\"\n              id={`${baseId}-tab-${v.id}`}\n              className=\"hb-za8-tab\"\n              aria-selected={i === index}\n              aria-controls={panelId}\n              tabIndex={i === index ? 0 : -1}\n              onClick={() => go(i)}\n            >\n              {v.label}\n            </button>\n          ))}\n        </div>\n      ) : null}\n      <div ref={stageRef} className=\"hb-za8-stage\">\n        {leaving && items[leaving.index] ? (\n          <div ref={outRef} key={`out-${leaving.key}`} className=\"hb-za8-view\" data-role=\"out\" aria-hidden=\"true\">\n            {items[leaving.index].content}\n          </div>\n        ) : null}\n        <div\n          ref={inRef}\n          key={`in-${items[index].id}`}\n          id={panelId}\n          className=\"hb-za8-view\"\n          data-role={leaving ? \"in\" : undefined}\n          role={controls === \"tabs\" ? \"tabpanel\" : \"region\"}\n          aria-labelledby={controls === \"tabs\" ? `${baseId}-tab-${items[index].id}` : undefined}\n          aria-label={controls === \"tabs\" ? undefined : items[index].label}\n          aria-live={controls === \"tabs\" ? undefined : \"polite\"}\n        >\n          {items[index].content}\n        </div>\n      </div>\n      {controls === \"steps\" ? (\n        <div className=\"hb-za8-steps\">\n          <button type=\"button\" className=\"hb-za8-nav\" disabled={index === 0} onClick={() => go(index - 1)}>\n            Back\n          </button>\n          <div className=\"hb-za8-dots\" role=\"group\" aria-label=\"Steps\">\n            {items.map((v, i) => (\n              <button\n                key={v.id}\n                type=\"button\"\n                className=\"hb-za8-dot\"\n                aria-label={`${v.label}, step ${i + 1} of ${total}`}\n                aria-current={i === index ? \"step\" : undefined}\n                onClick={() => go(i)}\n              />\n            ))}\n          </div>\n          <button type=\"button\" className=\"hb-za8-nav\" data-primary=\"true\" disabled={index === total - 1} onClick={() => go(index + 1)}>\n            Next\n          </button>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}