{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fold-drawer",
  "title": "Fold Drawer",
  "description": "Toggleable 3D hinged drawer/accordion with smooth auto-height collapse, perspective rotateX, and dynamic crease shading.",
  "files": [
    {
      "path": "registry/fold-ui/fold-drawer/fold-drawer.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface FoldDrawerProps extends React.HTMLAttributes<HTMLDivElement> {\n  /** Controlled open state. Omit to manage state via `defaultOpen`. */\n  open?: boolean;\n  /** Initial open state when uncontrolled. */\n  defaultOpen?: boolean;\n  /** Called when open state changes. */\n  onOpenChange?: (open: boolean) => void;\n  /**\n   * Axis along which the drawer collapses.\n   * - `vertical` (default): collapses height (`grid-template-rows`) with `rotateX`.\n   * - `horizontal`: collapses width (`grid-template-columns`) with `rotateY` (vertical crease).\n   */\n  orientation?: \"vertical\" | \"horizontal\";\n  /** Fold angle in degrees when closed. Negative folds inward away from viewer. */\n  angle?: number;\n  /** CSS perspective depth in pixels. */\n  perspective?: number;\n  /** Transition duration in milliseconds. */\n  duration?: number;\n  /** Hinge edge from which the panel folds. Defaults to `\"top\"` (vertical) or `\"left\"` (horizontal). */\n  origin?: \"top\" | \"bottom\" | \"left\" | \"right\";\n  /** Peak opacity (0-1) of the crease shadow when folded. */\n  creaseOpacity?: number;\n  /** CSS color for the crease shadow gradient. Defaults to `rgb(0 0 0)`. */\n  creaseColor?: string;\n  /** Class applied to the inner hinged flap surface. */\n  flapClassName?: string;\n  /** Class applied to the content wrapper inside the flap. */\n  contentClassName?: string;\n  children?: React.ReactNode;\n}\n\nconst EASE_OUT = \"cubic-bezier(0.22, 1, 0.36, 1)\";\nconst EASE_DRAWER = \"cubic-bezier(0.32, 0.72, 0, 1)\";\n\n/**\n * Toggleable 3D hinged drawer/accordion.\n * Uses CSS `grid-template-rows` (vertical) or `grid-template-columns` (horizontal)\n * for auto-size collapse paired with a 3D `rotateX`/`rotateY` hinge and dynamic crease shading.\n */\nexport const FoldDrawer = React.forwardRef<HTMLDivElement, FoldDrawerProps>(\n  function FoldDrawer(\n    {\n      open: controlledOpen,\n      defaultOpen = false,\n      onOpenChange,\n      orientation = \"vertical\",\n      angle,\n      perspective = 1200,\n      duration = 340,\n      origin,\n      creaseOpacity = 0.28,\n      creaseColor = \"0 0 0\",\n      className,\n      flapClassName,\n      contentClassName,\n      style,\n      children,\n      ...props\n    },\n    ref\n  ) {\n    const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);\n    const isControlled = controlledOpen !== undefined;\n    const isOpen = isControlled ? controlledOpen : uncontrolledOpen;\n\n    React.useEffect(() => {\n      if (!isControlled) {\n        onOpenChange?.(uncontrolledOpen);\n      }\n    }, [isControlled, onOpenChange, uncontrolledOpen]);\n\n    const isHorizontal = orientation === \"horizontal\";\n    const resolvedOrigin = origin ?? (isHorizontal ? \"left\" : \"top\");\n    const resolvedAngle = angle ?? (isHorizontal ? 86 : -86);\n    const easing = isOpen ? EASE_OUT : EASE_DRAWER;\n\n    const gradientDir = isHorizontal\n      ? resolvedOrigin === \"right\"\n        ? \"to left\"\n        : \"to right\"\n      : resolvedOrigin === \"bottom\"\n        ? \"to top\"\n        : \"to bottom\";\n\n    const transformOrigin = isHorizontal\n      ? resolvedOrigin === \"right\"\n        ? \"right center\"\n        : \"left center\"\n      : resolvedOrigin === \"bottom\"\n        ? \"bottom center\"\n        : \"top center\";\n\n    const transformValue = isHorizontal\n      ? isOpen\n        ? \"rotateY(0deg)\"\n        : `rotateY(${resolvedAngle}deg)`\n      : isOpen\n        ? \"rotateX(0deg)\"\n        : `rotateX(${resolvedAngle}deg)`;\n\n    return (\n      <div\n        ref={ref}\n        data-slot=\"fold-drawer\"\n        data-orientation={orientation}\n        data-state={isOpen ? \"open\" : \"closed\"}\n        aria-hidden={!isOpen}\n        className={cn(\n          \"grid overflow-hidden\",\n          isHorizontal ? \"grid-rows-[minmax(0,1fr)]\" : \"grid-cols-[minmax(0,1fr)]\",\n          isOpen ? \"pointer-events-auto\" : \"pointer-events-none\",\n          className\n        )}\n        style={{\n          ...(isHorizontal\n            ? {\n                gridTemplateColumns: isOpen ? \"1fr\" : \"0fr\",\n                transitionProperty: \"grid-template-columns, visibility\",\n              }\n            : {\n                gridTemplateRows: isOpen ? \"1fr\" : \"0fr\",\n                transitionProperty: \"grid-template-rows, visibility\",\n              }),\n          visibility: isOpen ? \"visible\" : \"hidden\",\n          transitionDuration: `${duration}ms, 0ms`,\n          transitionTimingFunction: `${easing}, linear`,\n          transitionDelay: isOpen ? \"0ms, 0ms\" : `0ms, ${duration}ms`,\n          ...style,\n        }}\n        {...props}\n      >\n        <div\n          className={cn(\n            \"min-h-0 min-w-0\",\n            isHorizontal ? \"h-full\" : \"w-full\",\n            !isHorizontal && resolvedOrigin === \"bottom\" && \"flex flex-col justify-end\",\n            isHorizontal && resolvedOrigin === \"right\" && \"flex justify-end\"\n          )}\n          style={{ perspective: `${perspective}px` }}\n        >\n          <div\n            data-slot=\"fold-drawer-flap\"\n            className={cn(\n              \"relative [backface-visibility:hidden] [transform-style:preserve-3d] will-change-transform motion-reduce:!transform-none\",\n              isHorizontal ? \"h-full\" : \"min-w-0 w-full\",\n              flapClassName\n            )}\n            style={{\n              transformOrigin,\n              transform: transformValue,\n              transition: `transform ${duration}ms ${easing}`,\n            }}\n          >\n            <div\n              data-slot=\"fold-drawer-content\"\n              className={cn(\n                \"relative\",\n                isHorizontal ? \"h-full\" : \"min-w-0\",\n                contentClassName\n              )}\n            >\n              {children}\n            </div>\n\n            {creaseOpacity > 0 && (\n              <div\n                aria-hidden=\"true\"\n                data-slot=\"fold-drawer-crease\"\n                className=\"pointer-events-none absolute inset-0 z-10 motion-reduce:hidden\"\n                style={{\n                  background: `linear-gradient(${gradientDir}, rgb(${creaseColor} / ${creaseOpacity}) 0%, rgb(${creaseColor} / ${(creaseOpacity * 0.3).toFixed(3)}) 55%, transparent 100%)`,\n                  opacity: isOpen ? 0 : 1,\n                  transition: `opacity ${duration}ms ${easing}`,\n                }}\n              />\n            )}\n          </div>\n        </div>\n      </div>\n    );\n  }\n);\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}