{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tap-flip","type":"registry:ui","title":"Tap Flip","description":"A small flash card that lifts off the table and springs over toward the side you tap, with a shadow that shrinks mid-turn. Enter or Space flips it too.","dependencies":["motion"],"registryDependencies":[],"files":[{"path":"registry/ui/tap-flip.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useState, type MouseEvent, type ReactNode } from \"react\";\nimport { MotionConfig, motion, useAnimate } from \"motion/react\";\n\nexport interface TapFlipProps {\n  /** Front face content (the prompt). */\n  front?: ReactNode;\n  /** Back face content (the answer). */\n  back?: ReactNode;\n  /** Small caption on the front. */\n  frontLabel?: string;\n  /** Small caption on the back. */\n  backLabel?: string;\n  /** Controlled flipped state. */\n  flipped?: boolean;\n  /** Initial state when uncontrolled. */\n  defaultFlipped?: boolean;\n  /** Called with the new state on every flip. */\n  onFlip?: (flipped: boolean) => void;\n  /** Accent color of the back face. */\n  color?: string;\n  className?: string;\n}\n\nconst turn = { type: \"spring\", stiffness: 170, damping: 15, mass: 1 } as const;\n\nexport function TapFlip({\n  front = \"What does the “C” in CSS stand for?\",\n  back = \"Cascading. Later rules win when specificity ties.\",\n  frontLabel = \"Question\",\n  backLabel = \"Answer\",\n  flipped,\n  defaultFlipped = false,\n  onFlip,\n  color = \"#818cf8\",\n  className,\n}: TapFlipProps) {\n  // Accumulated angle, so the card keeps turning the way it was pushed instead of unwinding.\n  const [angle, setAngle] = useState(defaultFlipped ? 180 : 0);\n  const [scope, animate] = useAnimate<HTMLDivElement>();\n  const showing = Math.abs(Math.round(angle / 180)) % 2 === 1;\n\n  // Controlled: follow the prop (adjust-state-during-render pattern).\n  if (flipped !== undefined && flipped !== showing) setAngle((a) => a + 180);\n\n  const flip = (dir: 1 | -1) => {\n    setAngle((a) => a + dir * 180);\n    onFlip?.(!showing);\n    // Lift off the table mid-turn and land with a little squash; the shadow shrinks as it rises.\n    animate(\"[data-lift]\", { y: [0, -18, 0], scale: [1, 1.05, 0.98, 1] }, { duration: 0.6, times: [0, 0.4, 0.8, 1], ease: \"easeOut\" });\n    animate(\"[data-shadow]\", { scaleX: [1, 0.7, 1.04, 1], opacity: [0.55, 0.2, 0.6, 0.55] }, { duration: 0.6, times: [0, 0.4, 0.8, 1] });\n  };\n\n  const onClick = (e: MouseEvent<HTMLButtonElement>) => {\n    // Flip toward the side that was pushed; keyboard (detail 0) always turns right.\n    const r = e.currentTarget.getBoundingClientRect();\n    flip(e.detail > 0 && e.clientX < r.left + r.width / 2 ? -1 : 1);\n  };\n\n  const face =\n    \"absolute inset-0 flex flex-col rounded-2xl border p-5 text-left [backface-visibility:hidden] [-webkit-backface-visibility:hidden]\";\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div ref={scope} className={`relative h-44 w-72 [perspective:900px] ${className ?? \"\"}`}>\n        <span\n          data-shadow\n          aria-hidden\n          className=\"absolute inset-x-6 -bottom-4 h-6 rounded-[50%] bg-black blur-xl\"\n          style={{ opacity: 0.55 }}\n        />\n        <div data-lift className=\"relative size-full [transform-style:preserve-3d]\">\n          <motion.button\n            type=\"button\"\n            aria-pressed={showing}\n            onClick={onClick}\n            initial={false}\n            animate={{ rotateY: angle }}\n            transition={turn}\n            whileTap={{ scale: 0.97 }}\n            className=\"group relative size-full rounded-2xl outline-none [transform-style:preserve-3d] focus-visible:ring-[3px] focus-visible:ring-ring/60 focus-visible:ring-offset-4 focus-visible:ring-offset-background\"\n          >\n            <span aria-hidden={showing} className={`${face} border-border bg-card text-foreground`}>\n              <span className=\"text-[11px] font-medium uppercase tracking-[0.18em] text-muted-foreground\">{frontLabel}</span>\n              <span className=\"my-auto text-lg font-semibold leading-snug\">{front}</span>\n              <span className=\"text-xs text-muted-foreground transition-colors group-hover:text-foreground\">Tap to flip</span>\n            </span>\n            <span\n              aria-hidden={!showing}\n              className={`${face} text-foreground`}\n              style={{\n                transform: \"rotateY(180deg)\",\n                borderColor: `color-mix(in oklab, ${color} 45%, transparent)`,\n                background: `linear-gradient(145deg, color-mix(in oklab, ${color} 22%, var(--card)), var(--card))`,\n              }}\n            >\n              <span className=\"text-[11px] font-medium uppercase tracking-[0.18em]\" style={{ color }}>\n                {backLabel}\n              </span>\n              <span className=\"my-auto text-lg font-semibold leading-snug\">{back}</span>\n              <span className=\"text-xs text-muted-foreground transition-colors group-hover:text-foreground\">Tap to flip back</span>\n            </span>\n          </motion.button>\n        </div>\n      </div>\n    </MotionConfig>\n  );\n}\n"}]}