{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "icon-swap-toggle",
  "title": "Icon Swap Toggle",
  "description": "A toggle button that swaps between two icons with a rotate, 3D flip, pop or slide: ready-made pairs for play/pause, mute, like, save, show/hide, menu/close, light/dark and copy/copied, or any two icons of your own.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/icon-swap-toggle/icon-swap-toggle.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion, type TargetAndTransition } from \"motion/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 SwapPreset = \"play\" | \"sound\" | \"heart\" | \"bookmark\" | \"eye\" | \"menu\" | \"theme\" | \"copy\";\nexport type SwapEffect = \"rotate\" | \"flip\" | \"scale\" | \"slide\";\n\nexport interface IconSwapToggleProps {\n  preset?: SwapPreset;\n  /** Your own pair; overrides the preset. */\n  iconOff?: React.ReactNode;\n  iconOn?: React.ReactNode;\n  effect?: SwapEffect;\n  on?: boolean;\n  defaultOn?: boolean;\n  onChange?: (on: boolean) => void;\n  /** Accessible names for each state, e.g. [\"Play\", \"Pause\"]. */\n  labels?: [string, string];\n  variant?: \"ghost\" | \"outline\" | \"solid\";\n  size?: number;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", border: \"rgba(255,255,255,0.14)\", hover: \"rgba(255,255,255,0.08)\", solid: \"#F5F4F1\", solidText: \"#0A0A0A\", accent: \"#FF7A6B\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", border: \"rgba(10,10,10,0.14)\", hover: \"rgba(10,10,10,0.05)\", solid: \"#0A0A0A\", solidText: \"#FFFFFF\", accent: \"#E5484D\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst s = (d: string | string[], fill?: boolean) => (\n  <svg width=\"100%\" height=\"100%\" viewBox=\"0 0 24 24\" fill={fill ? \"currentColor\" : \"none\"} stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    {(Array.isArray(d) ? d : [d]).map((x) => (\n      <path key={x} d={x} />\n    ))}\n  </svg>\n);\n\nconst PRESETS: Record<SwapPreset, { off: React.ReactNode; on: React.ReactNode; labels: [string, string]; tint?: boolean }> = {\n  play: { off: s(\"M7 4.8v14.4a1 1 0 0 0 1.5.9l11-7.2a1 1 0 0 0 0-1.7l-11-7.2A1 1 0 0 0 7 4.8Z\", true), on: s([\"M8 5v14\", \"M16 5v14\"]), labels: [\"Play\", \"Pause\"] },\n  sound: { off: s([\"M11 5 6.5 9H4a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h2.5l4.5 4Z\", \"M15 9.5a3.5 3.5 0 0 1 0 5\", \"M18 7a7 7 0 0 1 0 10\"]), on: s([\"M11 5 6.5 9H4a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h2.5l4.5 4Z\", \"m16 9.5 5 5\", \"m21 9.5-5 5\"]), labels: [\"Mute\", \"Unmute\"] },\n  heart: { off: s(\"M12 20s-7.5-4.6-7.5-10.2A4.2 4.2 0 0 1 12 7.2a4.2 4.2 0 0 1 7.5 2.6C19.5 15.4 12 20 12 20Z\"), on: s(\"M12 20s-7.5-4.6-7.5-10.2A4.2 4.2 0 0 1 12 7.2a4.2 4.2 0 0 1 7.5 2.6C19.5 15.4 12 20 12 20Z\", true), labels: [\"Like\", \"Unlike\"], tint: true },\n  bookmark: { off: s(\"M6.5 3.5h11a1 1 0 0 1 1 1v16l-6.5-4-6.5 4v-16a1 1 0 0 1 1-1Z\"), on: s(\"M6.5 3.5h11a1 1 0 0 1 1 1v16l-6.5-4-6.5 4v-16a1 1 0 0 1 1-1Z\", true), labels: [\"Save\", \"Remove from saved\"] },\n  eye: { off: s([\"M2.5 12s3.5-6.5 9.5-6.5 9.5 6.5 9.5 6.5-3.5 6.5-9.5 6.5S2.5 12 2.5 12Z\", \"M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z\"]), on: s([\"M10 5.7a9.6 9.6 0 0 1 2-.2c6 0 9.5 6.5 9.5 6.5a17 17 0 0 1-2.3 3.1M6.6 6.6C4 8.4 2.5 12 2.5 12s3.5 6.5 9.5 6.5a9 9 0 0 0 5.4-1.8\", \"m3 3 18 18\"]), labels: [\"Show\", \"Hide\"] },\n  menu: { off: s([\"M4 7h16\", \"M4 12h16\", \"M4 17h16\"]), on: s([\"m6 6 12 12\", \"M18 6 6 18\"]), labels: [\"Open menu\", \"Close menu\"] },\n  theme: { off: s([\"M12 16a4 4 0 1 0 0-8 4 4 0 0 0 0 8Z\", \"M12 2.5v2M12 19.5v2M4.6 4.6l1.4 1.4M18 18l1.4 1.4M2.5 12h2M19.5 12h2M4.6 19.4 6 18M18 6l1.4-1.4\"]), on: s(\"M20.5 14.2A8.5 8.5 0 1 1 9.8 3.5a6.8 6.8 0 0 0 10.7 10.7Z\"), labels: [\"Dark theme\", \"Light theme\"] },\n  copy: { off: s([\"M16 8V5.5A2.5 2.5 0 0 0 13.5 3h-8A2.5 2.5 0 0 0 3 5.5v8A2.5 2.5 0 0 0 5.5 16H8\", \"M11 8h7a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3h-7a3 3 0 0 1-3-3v-7a3 3 0 0 1 3-3Z\"]), on: s(\"m5 12.5 4.5 4.5L19 7.5\"), labels: [\"Copy\", \"Copied\"] },\n};\n\nconst EFFECTS: Record<SwapEffect, { in: TargetAndTransition; out: TargetAndTransition }> = {\n  rotate: { in: { rotate: -90, scale: 0.5, opacity: 0 }, out: { rotate: 90, scale: 0.5, opacity: 0 } },\n  flip: { in: { rotateY: -90, opacity: 0 }, out: { rotateY: 90, opacity: 0 } },\n  scale: { in: { scale: 0, opacity: 0 }, out: { scale: 0, opacity: 0 } },\n  slide: { in: { y: \"110%\", opacity: 0 }, out: { y: \"-110%\", opacity: 0 } },\n};\n\nexport function IconSwapToggle({ preset = \"play\", iconOff, iconOn, effect = \"rotate\", on, defaultOn = false, onChange, labels, variant = \"outline\", size = 44, theme = \"dark\", className }: IconSwapToggleProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState(defaultOn);\n  const isOn = on ?? internal;\n  const pre = PRESETS[preset];\n  const names = labels ?? pre.labels;\n  const icon = isOn ? (iconOn ?? pre.on) : (iconOff ?? pre.off);\n  const fx = EFFECTS[effect];\n  const solid = variant === \"solid\";\n\n  return (\n    <motion.button\n      type=\"button\"\n      aria-pressed={isOn}\n      aria-label={isOn ? names[1] : names[0]}\n      onClick={() => {\n        if (on === undefined) setInternal(!isOn);\n        onChange?.(!isOn);\n      }}\n      className={cn(\"relative flex cursor-pointer items-center justify-center overflow-hidden rounded-full outline-none focus-visible:ring-2\", className)}\n      style={{ width: size, height: size, perspective: 400, background: solid ? p.solid : \"transparent\", color: solid ? p.solidText : pre.tint && isOn ? p.accent : p.text, border: variant === \"outline\" ? `1px solid ${p.border}` : \"none\", transition: \"color 0.2s ease\", [\"--tw-ring-color\" as string]: p.focus }}\n      whileHover={reduce ? undefined : { backgroundColor: solid ? p.solid : p.hover }}\n      whileTap={{ scale: 0.9 }}\n    >\n      <AnimatePresence mode=\"popLayout\" initial={false}>\n        <motion.span\n          key={isOn ? \"on\" : \"off\"}\n          className=\"flex\"\n          style={{ width: size * 0.45, height: size * 0.45 }}\n          initial={reduce ? { opacity: 0 } : fx.in}\n          animate={{ rotate: 0, rotateY: 0, scale: 1, y: 0, opacity: 1 }}\n          exit={reduce ? { opacity: 0 } : fx.out}\n          transition={{ type: \"spring\", stiffness: 500, damping: 30, opacity: { duration: 0.14 } }}\n        >\n          {icon}\n        </motion.span>\n      </AnimatePresence>\n    </motion.button>\n  );\n}\n\nexport default IconSwapToggle;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}