{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flip-box",
  "title": "Flip Box",
  "description": "A photo card that turns over in 3D to show its details, flipping away from whichever edge the pointer came in from, with a priced feature list and call to action on the back, tap and keyboard support and a reduced-motion fallback.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/flip-box/flip-box.tsx",
      "content": "\"use client\";\n/* eslint-disable @next/next/no-img-element -- Registry components work in any React app. */\n\nimport * as React from \"react\";\nimport { ArrowUpRight, RotateCcw } from \"lucide-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 FlipBoxTheme = \"dark\" | \"light\";\nexport type FlipBoxTrigger = \"hover\" | \"click\";\n/** \"auto\" flips around whichever axis matches the edge the pointer came in from. */\nexport type FlipBoxAxis = \"auto\" | \"x\" | \"y\";\n\nexport interface FlipBoxProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"title\" | \"children\"> {\n  image?: string;\n  imageAlt?: string;\n  eyebrow?: string;\n  title?: string;\n  caption?: string;\n  backTitle?: string;\n  backDescription?: string;\n  features?: string[];\n  price?: string;\n  priceNote?: string;\n  ctaLabel?: string;\n  ctaHref?: string;\n  onCtaClick?: React.MouseEventHandler<HTMLAnchorElement>;\n  /** Replace the whole front or back face with your own content. */\n  front?: React.ReactNode;\n  back?: React.ReactNode;\n  trigger?: FlipBoxTrigger;\n  axis?: FlipBoxAxis;\n  /** Flip duration in ms. */\n  duration?: number;\n  /** Width / height of the card. */\n  aspectRatio?: number;\n  radius?: number;\n  theme?: FlipBoxTheme;\n  /** Controlled flip state. */\n  flipped?: boolean;\n  defaultFlipped?: boolean;\n  onFlippedChange?: (flipped: boolean) => void;\n}\n\ntype Turn = { axis: \"x\" | \"y\"; sign: 1 | -1 };\n\nfunction palette(theme: FlipBoxTheme, radius: number): React.CSSProperties & Record<`--${string}`, string> {\n  const light = theme === \"light\";\n  return {\n    \"--fb-surface\": light ? \"#ffffff\" : \"#121212\",\n    \"--fb-line\": light ? \"#e6e6e3\" : \"#262626\",\n    \"--fb-ink\": light ? \"#141414\" : \"#f4f4f2\",\n    \"--fb-muted\": light ? \"#6e6e6e\" : \"#8f8f8f\",\n    \"--fb-radius\": `${radius}px`,\n    color: \"var(--fb-ink)\",\n    fontFamily: \"inherit\",\n  };\n}\n\nconst focus = \"outline-none focus-visible:ring-2 focus-visible:ring-[var(--fb-ink)] focus-visible:ring-offset-2 focus-visible:ring-offset-transparent\";\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\n/** Which edge the pointer crossed, turned into a flip that \"pushes\" the card away from it. */\nfunction turnFrom(event: React.PointerEvent, el: HTMLElement, axis: FlipBoxAxis): Turn {\n  const rect = el.getBoundingClientRect();\n  const fromLeft = (event.clientX - rect.left) / rect.width;\n  const fromTop = (event.clientY - rect.top) / rect.height;\n  const edges = { left: fromLeft, right: 1 - fromLeft, top: fromTop, bottom: 1 - fromTop };\n  const horizontal = Math.min(edges.left, edges.right);\n  const vertical = Math.min(edges.top, edges.bottom);\n  const useY = axis === \"y\" || (axis === \"auto\" && horizontal <= vertical);\n  if (useY) return { axis: \"y\", sign: edges.left <= edges.right ? 1 : -1 };\n  return { axis: \"x\", sign: edges.top <= edges.bottom ? -1 : 1 };\n}\n\nexport function FlipBox({\n  image = \"/demo/38.webp\",\n  imageAlt = \"\",\n  eyebrow = \"01 — Portraits\",\n  title = \"Studio portraits\",\n  caption = \"Natural light, a quiet room, an hour.\",\n  backTitle = \"The portrait session\",\n  backDescription = \"A relaxed hour in our daylight studio, shot slowly so nobody has to perform for the camera.\",\n  features = [\"60-minute session\", \"15 retouched images\", \"Delivered in 5 days\"],\n  price = \"€320\",\n  priceNote = \"per session\",\n  ctaLabel = \"Book a session\",\n  ctaHref = \"#\",\n  onCtaClick,\n  front,\n  back,\n  trigger = \"hover\",\n  axis = \"auto\",\n  duration = 700,\n  aspectRatio = 3 / 4,\n  radius = 18,\n  theme = \"dark\",\n  flipped: flippedProp,\n  defaultFlipped = false,\n  onFlippedChange,\n  className,\n  style,\n  ...props\n}: FlipBoxProps) {\n  const reduce = useReducedMotion();\n  const [internal, setInternal] = React.useState(defaultFlipped);\n  const flipped = flippedProp ?? internal;\n  const [turn, setTurn] = React.useState<Turn>({ axis: axis === \"x\" ? \"x\" : \"y\", sign: 1 });\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const frontToggle = React.useRef<HTMLButtonElement>(null);\n  const backToggle = React.useRef<HTMLButtonElement>(null);\n  const backId = React.useId();\n  const focusTimer = React.useRef(0);\n  React.useEffect(() => () => window.clearTimeout(focusTimer.current), []);\n\n  const ms = reduce ? 0 : duration;\n\n  const setFlipped = (next: boolean) => {\n    if (next === flipped) return;\n    if (flippedProp === undefined) setInternal(next);\n    onFlippedChange?.(next);\n  };\n\n  // The axis is only re-picked while the card shows its front, so a flip always unwinds the way it came.\n  const aim = (event: React.PointerEvent) => {\n    if (!flipped && rootRef.current) setTurn(turnFrom(event, rootRef.current, axis));\n  };\n\n  const toggleFromKeyboardOrTap = (next: boolean, event: React.MouseEvent) => {\n    if (!flipped) setTurn((current) => ({ axis: axis === \"x\" ? \"x\" : axis === \"y\" ? \"y\" : current.axis, sign: current.sign }));\n    setFlipped(next);\n    // Keyboard users land on the face they just turned to; the other face becomes hidden and unfocusable.\n    // It can only take focus once its face turns visible, halfway through the flip.\n    if (event.detail === 0) {\n      window.clearTimeout(focusTimer.current);\n      focusTimer.current = window.setTimeout(() => (next ? backToggle : frontToggle).current?.focus({ preventScroll: true }), ms / 2 + 30);\n    }\n  };\n\n  const angle = flipped ? 180 * turn.sign : 0;\n  const rotate = turn.axis === \"y\" ? `rotateY(${angle}deg)` : `rotateX(${angle}deg)`;\n  const backRotate = turn.axis === \"y\" ? \"rotateY(180deg)\" : \"rotateX(180deg)\";\n  // Swap face visibility at the halfway point as well as using backface-visibility, for engines that ignore it.\n  // The flip curve is symmetric, so halfway in time is exactly when the card stands edge-on at 90deg.\n  const faceTransition = `visibility 0s linear ${ms / 2}ms`;\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"group/flip relative w-full select-none [perspective:1400px]\", className)}\n      style={{ ...palette(theme, radius), aspectRatio, ...style }}\n      onPointerEnter={(event) => {\n        if (trigger !== \"hover\" || event.pointerType !== \"mouse\") return;\n        aim(event);\n        setFlipped(true);\n      }}\n      onPointerLeave={(event) => {\n        if (trigger !== \"hover\" || event.pointerType !== \"mouse\") return;\n        setFlipped(false);\n      }}\n      onPointerDown={aim}\n      {...props}\n    >\n      <div\n        className=\"relative h-full w-full [transform-style:preserve-3d]\"\n        style={{ transform: rotate, transition: `transform ${ms}ms cubic-bezier(.65,0,.35,1)` }}\n      >\n        {/* Front */}\n        <div\n          className=\"absolute inset-0 [backface-visibility:hidden] [-webkit-backface-visibility:hidden]\"\n          style={{ visibility: flipped ? \"hidden\" : \"visible\", transition: faceTransition }}\n          aria-hidden={flipped}\n        >\n          <div className=\"relative h-full w-full overflow-hidden rounded-[var(--fb-radius)] bg-[var(--fb-surface)]\">\n            {front ?? (\n              <>\n                <img src={image} alt={imageAlt} draggable={false} className=\"absolute inset-0 h-full w-full object-cover transition-transform duration-700 ease-out group-hover/flip:scale-[1.03] motion-reduce:transform-none\" />\n                <div aria-hidden=\"true\" className=\"absolute inset-0 bg-gradient-to-t from-black/75 via-black/10 to-black/20\" />\n                <div className=\"absolute inset-x-0 top-0 flex items-center justify-between p-5 text-white\">\n                  <span className=\"rounded-full border border-white/25 bg-black/20 px-2.5 py-1 font-mono text-[10px] tracking-wide backdrop-blur-md\">{eyebrow}</span>\n                </div>\n                <div className=\"absolute inset-x-0 bottom-0 flex items-end justify-between gap-4 p-5 text-white\">\n                  <div className=\"min-w-0\">\n                    <h3 className=\"text-[22px] leading-tight font-medium tracking-[-0.01em]\">{title}</h3>\n                    {caption && <p className=\"mt-1.5 text-[13px] leading-snug text-white/70\">{caption}</p>}\n                  </div>\n                  <span aria-hidden=\"true\" className=\"flex size-9 shrink-0 items-center justify-center rounded-full border border-white/25 bg-white/10 backdrop-blur-md transition-transform duration-500 group-hover/flip:rotate-180\">\n                    <RotateCcw size={14} />\n                  </span>\n                </div>\n              </>\n            )}\n            <button\n              ref={frontToggle}\n              type=\"button\"\n              tabIndex={flipped ? -1 : 0}\n              aria-expanded={flipped}\n              aria-controls={backId}\n              aria-label={`Show details: ${title}`}\n              onClick={(event) => toggleFromKeyboardOrTap(true, event)}\n              className={cn(\"absolute inset-0 cursor-pointer rounded-[var(--fb-radius)]\", focus, \"focus-visible:ring-inset focus-visible:ring-white\")}\n            />\n          </div>\n        </div>\n\n        {/* Back */}\n        <div\n          id={backId}\n          className=\"absolute inset-0 [backface-visibility:hidden] [-webkit-backface-visibility:hidden]\"\n          style={{ transform: backRotate, visibility: flipped ? \"visible\" : \"hidden\", transition: faceTransition }}\n          aria-hidden={!flipped}\n        >\n          <div className=\"relative flex h-full w-full flex-col overflow-hidden rounded-[var(--fb-radius)] border border-[var(--fb-line)] bg-[var(--fb-surface)] p-5 @container\">\n            <button\n              ref={backToggle}\n              type=\"button\"\n              tabIndex={flipped ? 0 : -1}\n              aria-label=\"Flip back\"\n              onClick={(event) => toggleFromKeyboardOrTap(false, event)}\n              className={cn(\n                \"absolute top-4 right-4 z-10 flex h-7 cursor-pointer items-center gap-1 rounded-full border border-[var(--fb-line)] bg-[var(--fb-surface)] px-2.5 font-mono text-[9.5px] text-[var(--fb-muted)] opacity-0 transition-opacity hover:text-[var(--fb-ink)] focus-visible:opacity-100\",\n                trigger === \"click\" ? \"opacity-100\" : \"[@media(pointer:coarse)]:opacity-100\",\n                focus,\n              )}\n            >\n              <RotateCcw size={10} aria-hidden=\"true\" /> Flip\n            </button>\n            {back ?? (\n              <>\n                <div className=\"flex items-center gap-3 pr-16\">\n                  <img src={image} alt=\"\" draggable={false} className=\"size-10 shrink-0 rounded-full object-cover grayscale\" />\n                  <span className=\"min-w-0 truncate font-mono text-[10px] tracking-wide text-[var(--fb-muted)]\">{eyebrow}</span>\n                </div>\n                <h3 className=\"mt-4 text-[20px] leading-tight font-medium tracking-[-0.01em]\">{backTitle}</h3>\n                {backDescription && <p className=\"mt-2 line-clamp-2 text-[13px] leading-relaxed text-[var(--fb-muted)] @min-[320px]:line-clamp-none\">{backDescription}</p>}\n                {features.length > 0 && (\n                  <ul className=\"mt-4 border-t border-[var(--fb-line)]\">\n                    {features.map((feature) => (\n                      <li key={feature} className=\"flex items-center gap-2.5 border-b border-[var(--fb-line)] py-2 text-[13px]\">\n                        <span aria-hidden=\"true\" className=\"size-1 rounded-full bg-[var(--fb-ink)]\" />\n                        {feature}\n                      </li>\n                    ))}\n                  </ul>\n                )}\n                <div className=\"mt-auto flex items-end justify-between gap-3 pt-4\">\n                  {price && (\n                    <p className=\"leading-none\">\n                      <span className=\"text-[24px] font-medium tracking-tight\">{price}</span>\n                      {priceNote && <span className=\"mt-1.5 block text-[11px] text-[var(--fb-muted)]\">{priceNote}</span>}\n                    </p>\n                  )}\n                  {ctaLabel && (\n                    <a\n                      href={ctaHref}\n                      tabIndex={flipped ? 0 : -1}\n                      onClick={onCtaClick}\n                      className={cn(\"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-[var(--fb-ink)] pr-3 pl-4 text-[13px] font-medium text-[var(--fb-surface)] transition-opacity hover:opacity-90\", focus)}\n                    >\n                      {ctaLabel}\n                      <ArrowUpRight size={14} aria-hidden=\"true\" />\n                    </a>\n                  )}\n                </div>\n              </>\n            )}\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}