{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "laptop-closes-on-scroll",
  "type": "registry:ui",
  "title": "Laptop Closes on Scroll",
  "description": "A Laptop Closes on Scroll component for displaying a laptop that closes on scroll.",
  "files": [
    {
      "path": "src/registry/ui/laptop-closes-on-scroll.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport { useRef, useSyncExternalStore } from \"react\";\nimport { motion, useScroll, useTransform } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst COLORS = {\n  space: { lid: \"bg-neutral-800\", base: \"bg-neutral-700\" },\n  silver: { lid: \"bg-neutral-300\", base: \"bg-neutral-400\" },\n} as const;\n\nexport type LaptopColor = keyof typeof COLORS;\n\nconst REDUCED_MOTION = \"(prefers-reduced-motion: reduce)\";\nconst subscribeToReducedMotion = (onChange: () => void) => {\n  const query = window.matchMedia(REDUCED_MOTION);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\n\n/**\n * The server can't know the visitor's motion preference, so the first client render must\n * match its HTML (animated). The real preference is applied right after hydration.\n */\nfunction usePrefersReducedMotion() {\n  return useSyncExternalStore(\n    subscribeToReducedMotion,\n    () => window.matchMedia(REDUCED_MOTION).matches,\n    () => false\n  );\n}\n\nexport type AnimatedMacBookProps = React.ComponentProps<\"div\"> & {\n  /** Screen content, e.g. an image or a live UI. Fills a 16:10 screen. */\n  children?: React.ReactNode;\n  /** Length of the scroll track, any CSS length. */\n  scrollHeight?: string;\n  /** How far the lid closes, clamped to 0–90 degrees (90 = fully closed). */\n  maxRotation?: number;\n  /** Body color preset. */\n  color?: LaptopColor;\n  /** Classes for the screen area that wraps `children`. */\n  screenClassName?: string;\n};\n\n/**\n * A laptop mockup pinned to the viewport whose lid closes as you scroll\n * through its track. With reduced motion the lid stays open.\n */\nexport function AnimatedMacBook({\n  children,\n  scrollHeight = \"200vh\",\n  maxRotation = 90,\n  color = \"space\",\n  className,\n  screenClassName,\n  style,\n  ...props\n}: AnimatedMacBookProps) {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const reduceMotion = usePrefersReducedMotion();\n\n  const { scrollYProgress } = useScroll({\n    target: containerRef,\n    offset: [\"start start\", \"end end\"],\n  });\n\n  const closingAngle = Math.min(90, Math.max(0, maxRotation));\n  const rotateX = useTransform(scrollYProgress, [0.1, 0.9], [0, -closingAngle]);\n  const dim = useTransform(rotateX, [-90, -75, 0], [1, 0.35, 0]);\n  const screenOpacity = useTransform(rotateX, [-90, -88, 0], [0, 1, 1]);\n  const lidEdgeOpacity = useTransform(rotateX, [-90, -84, 0], [1, 0, 0]);\n  const deviceY = useTransform(rotateX, [-90, 0], [\"-45%\", \"0%\"]);\n\n  const animated = !reduceMotion;\n\n  return (\n    <div\n      ref={containerRef}\n      data-slot=\"laptop-closes-on-scroll\"\n      className={cn(\"relative w-full\", className)}\n      style={{ height: scrollHeight, ...style }}\n      {...props}\n    >\n      <div className=\"sticky top-0 flex h-svh items-center justify-center overflow-x-clip px-4\">\n        <motion.div\n          className=\"w-full max-w-4xl\"\n          style={animated ? { y: deviceY } : undefined}\n        >\n          {/* The perspective origin must share the lid's bottom-edge hinge.\n              A centred origin projects the closing screen below the base. */}\n          <div className=\"relative mx-auto aspect-[16/10] w-[88%] perspective-[2000px] [perspective-origin:50%_100%]\">\n            <motion.div\n              className={cn(\n                \"absolute inset-0 origin-bottom rounded-xl p-[1%] [backface-visibility:hidden]\",\n                COLORS[color].lid\n              )}\n              style={animated ? { rotateX } : undefined}\n            >\n              <motion.div\n                className=\"relative size-full rounded-lg bg-neutral-950 p-[2%] [backface-visibility:hidden]\"\n                style={animated ? { opacity: screenOpacity } : undefined}\n              >\n                <span\n                  aria-hidden\n                  className=\"absolute top-[0.8%] left-1/2 size-1.5 -translate-x-1/2 rounded-full bg-neutral-700\"\n                />\n                <div\n                  data-slot=\"laptop-screen\"\n                  className={cn(\n                    \"relative size-full overflow-hidden rounded-sm bg-muted [&>img]:size-full [&>img]:object-cover\",\n                    screenClassName\n                  )}\n                >\n                  {children}\n                  {animated && (\n                    <motion.div\n                      aria-hidden\n                      className=\"pointer-events-none absolute inset-0 bg-black\"\n                      style={{ opacity: dim }}\n                    />\n                  )}\n                </div>\n              </motion.div>\n            </motion.div>\n            {animated && (\n              <motion.div\n                aria-hidden\n                data-slot=\"laptop-lid-edge\"\n                className={cn(\n                  \"pointer-events-none absolute inset-x-0 bottom-0 h-1.5 rounded-t-md\",\n                  COLORS[color].lid\n                )}\n                style={{ opacity: lidEdgeOpacity }}\n              />\n            )}\n          </div>\n\n          <div\n            aria-hidden\n            data-slot=\"laptop-base\"\n            className={cn(\"relative z-10 h-3 rounded-b-xl ring-1 ring-black/10 sm:h-4\", COLORS[color].base)}\n          >\n            <div className=\"absolute top-0 left-1/2 h-1/3 w-[14%] -translate-x-1/2 rounded-b-md bg-black/20\" />\n          </div>\n        </motion.div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ],
  "dependencies": [
    "motion"
  ]
}
