{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hanging-price-tags",
  "title": "Hanging Price Tags",
  "description": "Plans as paper price tags hanging from a rail: they swing like real pendulums when the pointer brushes past, the chosen tag drops lower on its string, and its details appear underneath.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/hanging-price-tags/hanging-price-tags.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type HangingTagsTheme = \"dark\" | \"light\";\n\nexport interface PriceTag {\n  name: string;\n  price: number;\n  /** Small text beside the price, e.g. \"/ mo\". */\n  period?: string;\n  /** Fill of this tag while it is picked. */\n  color?: string;\n  /** Text on this tag while it is picked. */\n  ink?: string;\n  features: string[];\n  cta?: string;\n}\n\nexport interface HangingPriceTagsProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"title\" | \"onSelect\"\n> {\n  theme?: HangingTagsTheme;\n  title?: string;\n  subtitle?: string;\n  tags?: PriceTag[];\n  /** Index of the tag picked first. */\n  defaultIndex?: number;\n  currency?: string;\n  /** How much the tags swing when the pointer brushes them. */\n  swing?: number;\n  /** Colour of the picked tag's string and pin. */\n  accent?: string;\n  onSelect?: (tag: PriceTag) => void;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#08090A\",\n    border: \"rgba(255,255,255,0.08)\",\n    highlight:\n      \"inset 0 0 0 1px rgba(255,255,255,0.03), inset 0 1px 0 rgba(255,255,255,0.04)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    rail: \"#23252A\",\n    pin: \"#62666D\",\n    string: \"rgba(255,255,255,0.14)\",\n    tag: \"#0F1011\",\n    picked: \"#E5E5E6\",\n    pickedInk: \"#08090A\",\n    pickedSub: \"rgba(8,9,10,0.62)\",\n    panel: \"#0F1011\",\n    check: \"#D0D6E0\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n    shadow: \"0 4px 24px rgba(0,0,0,0.2)\",\n    accent: \"#5E6AD2\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    highlight: \"inset 0 1px 0 rgba(255,255,255,0.8)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    rail: \"#E5E5E6\",\n    pin: \"#8A8F98\",\n    string: \"rgba(8,9,10,0.16)\",\n    tag: \"#F7F8F8\",\n    picked: \"#08090A\",\n    pickedInk: \"#F7F8F8\",\n    pickedSub: \"rgba(247,248,248,0.62)\",\n    panel: \"#F7F8F8\",\n    check: \"#3C3F44\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n    shadow: \"0 3px 12px rgba(8,9,10,0.06)\",\n    accent: \"#5E6AD2\",\n  },\n};\n\nconst DEFAULT_TAGS: PriceTag[] = [\n  {\n    name: \"Basic\",\n    price: 9,\n    period: \"/ mo\",\n    features: [\"1 shop\", \"50 products\", \"Email receipts\"],\n  },\n  {\n    name: \"Plus\",\n    price: 29,\n    period: \"/ mo\",\n    features: [\n      \"3 shops\",\n      \"Unlimited products\",\n      \"Discount codes\",\n      \"Abandoned cart emails\",\n    ],\n  },\n  {\n    name: \"Pro\",\n    price: 79,\n    period: \"/ mo\",\n    features: [\n      \"10 shops\",\n      \"Staff accounts\",\n      \"Advanced reports\",\n      \"Priority support\",\n    ],\n  },\n  {\n    name: \"Max\",\n    price: 199,\n    period: \"/ mo\",\n    features: [\n      \"Unlimited shops\",\n      \"API access\",\n      \"Custom checkout\",\n      \"Dedicated manager\",\n    ],\n  },\n];\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nconst STIFFNESS = 46;\nconst DAMPING = 1.9;\n\nexport function HangingPriceTags({\n  theme = \"dark\",\n  title = \"Pick a tag\",\n  subtitle = \"Brush past them, they swing\",\n  tags = DEFAULT_TAGS,\n  defaultIndex = 1,\n  currency = \"$\",\n  swing = 1,\n  accent,\n  onSelect,\n  className,\n  style,\n  ...props\n}: HangingPriceTagsProps) {\n  const pal = PALETTES[theme];\n  const lead = accent ?? pal.accent;\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const swingRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const physics = React.useRef(tags.map(() => ({ a: 0, v: 0 })));\n  const raf = React.useRef(0);\n  const last = React.useRef({ x: 0, t: 0 });\n  const loop = React.useRef<() => void>(() => {});\n  const [index, setIndex] = React.useState(defaultIndex);\n  const active = tags[index] ? index : 0;\n\n  // Each tag is a damped pendulum. Angles go straight to the elements, so nothing re-renders while they swing.\n  React.useEffect(() => {\n    let prev = 0;\n    const frame = (now: number) => {\n      const dt = Math.min(0.033, prev ? (now - prev) / 1000 : 1 / 60);\n      prev = now;\n      let moving = false;\n      physics.current.forEach((p, i) => {\n        p.v += (-STIFFNESS * p.a - DAMPING * p.v) * dt;\n        p.a += p.v * dt;\n        if (Math.abs(p.a) < 0.02 && Math.abs(p.v) < 0.05) {\n          p.a = 0;\n          p.v = 0;\n        } else moving = true;\n        const el = swingRefs.current[i];\n        if (el) el.style.transform = `rotate(${p.a.toFixed(2)}deg)`;\n      });\n      if (moving) raf.current = requestAnimationFrame(frame);\n      else {\n        raf.current = 0;\n        prev = 0;\n      }\n    };\n    loop.current = () => {\n      if (!raf.current) raf.current = requestAnimationFrame(frame);\n    };\n    return () => {\n      cancelAnimationFrame(raf.current);\n      raf.current = 0;\n    };\n  }, []);\n\n  const push = React.useCallback(\n    (i: number, amount: number) => {\n      if (reduce) return;\n      const p = physics.current[i];\n      if (!p) return;\n      p.v = Math.max(-150, Math.min(150, p.v + amount * swing));\n      loop.current();\n    },\n    [reduce, swing],\n  );\n\n  // A little sway when the tags first come into view.\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const timers: number[] = [];\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry.isIntersecting) return;\n        io.disconnect();\n        tags.forEach((_, i) =>\n          timers.push(\n            window.setTimeout(() => push(i, i % 2 ? -46 : 46), i * 90),\n          ),\n        );\n      },\n      { threshold: 0.3 },\n    );\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      timers.forEach(clearTimeout);\n    };\n  }, [tags, push]);\n\n  const onMove = (e: React.PointerEvent, i: number) => {\n    const now = e.timeStamp;\n    const dt = Math.max(8, now - last.current.t);\n    const speed = ((e.clientX - last.current.x) / dt) * 16;\n    last.current = { x: e.clientX, t: now };\n    if (e.pointerType === \"mouse\")\n      push(i, Math.max(-14, Math.min(14, speed * 1.6)));\n  };\n  const pick = (i: number) => {\n    setIndex(i);\n    push(i, i % 2 ? 60 : -60);\n  };\n  const onKey = (e: React.KeyboardEvent) => {\n    const dir = e.key === \"ArrowRight\" ? 1 : e.key === \"ArrowLeft\" ? -1 : 0;\n    if (!dir) return;\n    e.preventDefault();\n    const next = (index + dir + tags.length) % tags.length;\n    pick(next);\n    rootRef.current\n      ?.querySelectorAll<HTMLElement>(\"[role=radio]\")\n      [next]?.focus();\n  };\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\n        \"w-full overflow-hidden rounded-2xl px-4 pt-6 pb-5 sm:px-8 sm:pt-8 sm:pb-8\",\n        className,\n      )}\n      style={{\n        background: pal.bg,\n        boxShadow: `inset 0 0 0 1px ${pal.border}`,\n        color: pal.text,\n        fontFamily:\n          '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif',\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-wrap items-baseline justify-between gap-2\">\n        <h3 className=\"m-0 text-[24px] leading-[1.33] font-[510] tracking-[-0.012em]\">\n          {title}\n        </h3>\n        <p\n          className=\"m-0 text-[13px] tracking-[-0.011em]\"\n          style={{ color: pal.sub }}\n        >\n          {subtitle}\n        </p>\n      </div>\n\n      <div className=\"relative mt-6\">\n        <div\n          aria-hidden=\"true\"\n          className=\"h-px\"\n          style={{ background: pal.rail }}\n        />\n        <div\n          role=\"radiogroup\"\n          aria-label=\"Plans\"\n          onKeyDown={onKey}\n          className=\"flex justify-around gap-1.5 sm:gap-3\"\n        >\n          {tags.map((t, i) => {\n            const on = i === index;\n            return (\n              <div\n                key={t.name}\n                className=\"min-w-0 flex-1\"\n                style={{ maxWidth: 170 }}\n              >\n                <div\n                  ref={(el) => {\n                    swingRefs.current[i] = el;\n                  }}\n                  className=\"flex origin-top flex-col items-center will-change-transform\"\n                >\n                  <span\n                    aria-hidden=\"true\"\n                    className=\"-mt-[3px] size-[5px] rounded-full transition-colors duration-300\"\n                    style={{ background: on ? lead : pal.pin }}\n                  />\n                  {/* The string's slot keeps its full height and the tag moves by transform, so picking one never resizes the card. */}\n                  <span\n                    aria-hidden=\"true\"\n                    className=\"relative z-10 -mb-3.5 block h-[60px] w-px\"\n                  >\n                    <span\n                      className=\"absolute inset-x-0 top-0 block transition-colors duration-300 motion-safe:transition-[height,background-color]\"\n                      style={{\n                        height: on ? 60 : 38,\n                        background: on ? lead : pal.string,\n                      }}\n                    />\n                  </span>\n                  <span\n                    className=\"block w-full motion-safe:transition-transform motion-safe:duration-300\"\n                    style={{ transform: on ? \"none\" : \"translateY(-22px)\" }}\n                  >\n                    <button\n                      type=\"button\"\n                      role=\"radio\"\n                      aria-checked={on}\n                      aria-label={`${t.name}, ${currency}${t.price} ${t.period ?? \"\"}`}\n                      tabIndex={on ? 0 : -1}\n                      onPointerMove={(e) => onMove(e, i)}\n                      onClick={() => pick(i)}\n                      className=\"relative block w-full cursor-pointer rounded-xl px-2 pt-7 pb-4 text-center outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-offset-2\"\n                      style={\n                        {\n                          \"--tw-ring-color\": lead,\n                          \"--tw-ring-offset-color\": pal.bg,\n                          background: on ? (t.color ?? pal.picked) : pal.tag,\n                          color: on ? (t.ink ?? pal.pickedInk) : pal.text,\n                          boxShadow: `inset 0 0 0 1px ${on ? \"transparent\" : pal.border}, ${on ? \"0 0 0 0 transparent\" : pal.highlight}, ${pal.shadow}`,\n                        } as React.CSSProperties\n                      }\n                    >\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"absolute top-2.5 left-1/2 size-2 -translate-x-1/2 rounded-full\"\n                        style={{\n                          background: pal.bg,\n                          boxShadow: `inset 0 0 0 1px ${on ? \"transparent\" : pal.border}`,\n                        }}\n                      />\n                      <span\n                        className=\"block text-[13px] font-[510] tracking-[-0.011em] transition-colors duration-200\"\n                        style={{ color: on ? pal.pickedSub : pal.sub }}\n                      >\n                        {t.name}\n                      </span>\n                      <span className=\"mt-1 block text-[26px] leading-none font-[510] tracking-[-0.022em] tabular-nums sm:text-[32px]\">\n                        {currency}\n                        {t.price}\n                      </span>\n                      {t.period && (\n                        <span\n                          className=\"mt-1 block text-[12px] tracking-[-0.011em] transition-colors duration-200\"\n                          style={{ color: on ? pal.pickedSub : pal.faint }}\n                        >\n                          {t.period}\n                        </span>\n                      )}\n                    </button>\n                  </span>\n                </div>\n              </div>\n            );\n          })}\n        </div>\n      </div>\n\n      {/* Every plan's panel sits in the same grid cell, so the card stays as tall as the longest one. */}\n      <div className=\"mt-5 grid grid-cols-[minmax(0,1fr)]\">\n        {tags.map((t, i) => (\n          <div\n            key={t.name}\n            className={cn(\n              \"col-start-1 row-start-1 flex flex-col gap-4 rounded-xl p-4 sm:flex-row sm:items-center sm:justify-between sm:p-5\",\n              i !== active && \"invisible\",\n            )}\n            style={{\n              background: pal.panel,\n              boxShadow: `inset 0 0 0 1px ${pal.border}, ${pal.highlight}`,\n            }}\n          >\n            <ul className=\"m-0 grid list-none grid-cols-1 gap-x-7 gap-y-2 p-0 text-[13px] tracking-[-0.011em] sm:grid-cols-2\">\n              {t.features.map((f) => (\n                <li\n                  key={f}\n                  className=\"flex items-center gap-2\"\n                  style={{ color: pal.soft }}\n                >\n                  <svg\n                    width=\"14\"\n                    height=\"14\"\n                    viewBox=\"0 0 14 14\"\n                    aria-hidden=\"true\"\n                    className=\"shrink-0\"\n                  >\n                    <circle cx=\"7\" cy=\"7\" r=\"7\" fill={pal.check} />\n                    <path\n                      d=\"m4.2 7.2 1.9 1.9 3.7-4\"\n                      fill=\"none\"\n                      stroke={pal.panel}\n                      strokeWidth=\"1.5\"\n                      strokeLinecap=\"round\"\n                      strokeLinejoin=\"round\"\n                    />\n                  </svg>\n                  {f}\n                </li>\n              ))}\n            </ul>\n            <button\n              type=\"button\"\n              onClick={() => onSelect?.(t)}\n              className=\"h-10 shrink-0 cursor-pointer rounded-full px-5 text-[13px] font-[510] tracking-[-0.011em] transition-opacity hover:opacity-90\"\n              style={{ background: pal.btn, color: pal.btnText }}\n            >\n              {t.cta ?? `Choose ${t.name}`}\n            </button>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}