{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "corner-ribbon",
  "title": "Corner Ribbon",
  "description": "A diagonal ribbon for the corner of any card, in any of the four corners, with a band of light that passes along it now and then.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/corner-ribbon/corner-ribbon.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type RibbonCorner =\n  \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n\nexport interface CornerRibbonProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> {\n  label?: string;\n  corner?: RibbonCorner;\n  /** Fill of the ribbon. */\n  color?: string;\n  /** Colour of the text. */\n  ink?: string;\n  /** Width of the square corner it sits in, in px. */\n  size?: number;\n  /** A band of light passes along it now and then. */\n  shine?: boolean;\n}\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\nconst SPOT: Record<RibbonCorner, React.CSSProperties> = {\n  \"top-left\": { top: 0, left: 0 },\n  \"top-right\": { top: 0, right: 0 },\n  \"bottom-left\": { bottom: 0, left: 0 },\n  \"bottom-right\": { bottom: 0, right: 0 },\n};\n\nconst TURN: Record<RibbonCorner, number> = {\n  \"top-left\": -45,\n  \"top-right\": 45,\n  \"bottom-left\": 45,\n  \"bottom-right\": -45,\n};\n\n/** Place it inside any element with position: relative. */\nexport function CornerRibbon({\n  label = \"Popular\",\n  corner = \"top-right\",\n  color = \"#5E6AD2\",\n  ink = \"#FFFFFF\",\n  size = 112,\n  shine = true,\n  className,\n  style,\n  ...props\n}: CornerRibbonProps) {\n  const reduce = useReducedMotion();\n  const shineRef = React.useRef<HTMLSpanElement>(null);\n\n  React.useEffect(() => {\n    if (reduce || !shine) return;\n    const run = shineRef.current?.animate(\n      [\n        { transform: \"translateX(-160%)\", offset: 0 },\n        { transform: \"translateX(260%)\", offset: 0.4 },\n        { transform: \"translateX(260%)\", offset: 1 },\n      ],\n      { duration: 3000, iterations: Infinity, easing: \"ease-in-out\" },\n    );\n    return () => run?.cancel();\n  }, [reduce, shine]);\n\n  // The band crosses the corner on the diagonal, at a third of the corner's size from the point.\n  const reach = size * 0.34;\n  const across = corner.endsWith(\"left\") ? -1 : 1;\n  const down = corner.startsWith(\"top\") ? -1 : 1;\n  return (\n    <div\n      className={`pointer-events-none absolute overflow-hidden ${className ?? \"\"}`}\n      style={{ width: size, height: size, ...SPOT[corner], ...style }}\n      {...props}\n    >\n      <div\n        className=\"absolute top-1/2 left-1/2 overflow-hidden text-center text-[11px] font-semibold tracking-[0.02em] whitespace-nowrap\"\n        style={{\n          width: size * 1.8,\n          lineHeight: \"26px\",\n          height: 26,\n          background: color,\n          color: ink,\n          fontFamily:\n            '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif',\n          boxShadow: \"0 2px 8px rgba(0,0,0,0.25)\",\n          transform: `translate(-50%, -50%) translate(${across * reach * 0.62}px, ${down * reach * 0.62}px) rotate(${TURN[corner]}deg)`,\n        }}\n      >\n        {label}\n        <span\n          ref={shineRef}\n          aria-hidden=\"true\"\n          className=\"absolute inset-y-0 left-0 w-1/3\"\n          style={{\n            background:\n              \"linear-gradient(90deg, transparent, rgba(255,255,255,0.45), transparent)\",\n            transform: \"translateX(-160%)\",\n          }}\n        />\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}