{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"gradient-heading","type":"registry:ui","title":"Gradient heading","description":"Display heading with a slow brand gradient on highlighted words, or one soft brand pass through the whole line.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/gradient-heading/gradient-heading.tsx","type":"registry:ui","target":"components/facade/gradient-heading.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface GradientHeadingProps {\n  /** Heading copy. */\n  children?: string;\n  /** Element to render. Defaults to \"h1\". */\n  as?: \"h1\" | \"h2\" | \"h3\";\n  /**\n   * Words (or phrases) that get the brand gradient. When omitted a soft\n   * brand pass moves slowly through the otherwise monochrome heading.\n   */\n  highlight?: string[];\n  /** Seconds for one full sweep. Defaults to 9. */\n  duration?: number;\n  className?: string;\n  /** Class applied to highlighted segments. */\n  highlightClassName?: string;\n}\n\n/** Highlighted words: ultramarine with a slightly deeper band drifting through. */\nconst accent =\n  \"linear-gradient(100deg, var(--brand) 0%, color-mix(in oklch, var(--brand) 72%, var(--foreground)) 50%, var(--brand) 100%)\";\n\n/** Whole heading: monochrome with one soft ultramarine pass. */\nconst monochromeToAccent =\n  \"linear-gradient(100deg, var(--foreground) 0%, var(--foreground) 38%, var(--brand) 62%, var(--foreground) 100%)\";\n\nfunction escapeRegExp(s: string) {\n  return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction Sweep({\n  gradient,\n  duration,\n  reduce,\n  className,\n  children,\n}: {\n  gradient: string;\n  duration: number;\n  reduce: boolean;\n  className?: string;\n  children: React.ReactNode;\n}) {\n  return (\n    <motion.span\n      className={cn(\"bg-clip-text text-transparent [-webkit-background-clip:text] [box-decoration-break:clone]\", className)}\n      style={{ backgroundImage: gradient, backgroundSize: \"200% 100%\", backgroundPosition: \"0% 50%\" }}\n      animate={reduce ? undefined : { backgroundPosition: [\"0% 50%\", \"100% 50%\"] }}\n      transition={{ duration, ease: \"easeInOut\", repeat: Infinity, repeatType: \"mirror\" }}\n    >\n      {children}\n    </motion.span>\n  );\n}\n\nexport function GradientHeading({\n  children = \"Websites that make the phone ring.\",\n  as = \"h1\",\n  highlight,\n  duration = 9,\n  className,\n  highlightClassName,\n}: GradientHeadingProps) {\n  const reduce = useReducedMotion() ?? false;\n  const Tag = as;\n\n  const parts = React.useMemo(() => {\n    if (!highlight || highlight.length === 0) return null;\n    const re = new RegExp(`(${highlight.map(escapeRegExp).join(\"|\")})`, \"g\");\n    return children.split(re).filter((p) => p.length > 0);\n  }, [children, highlight]);\n\n  return (\n    <Tag\n      className={cn(\n        \"font-display text-[40px] font-semibold leading-[1.02] tracking-[-0.035em] text-balance text-foreground sm:text-[56px] md:text-[64px]\",\n        className,\n      )}\n    >\n      {parts ? (\n        parts.map((part, i) =>\n          highlight?.includes(part) ? (\n            <Sweep key={i} gradient={accent} duration={duration} reduce={reduce} className={highlightClassName}>\n              {part}\n            </Sweep>\n          ) : (\n            <React.Fragment key={i}>{part}</React.Fragment>\n          ),\n        )\n      ) : (\n        <Sweep gradient={monochromeToAccent} duration={duration} reduce={reduce}>\n          {children}\n        </Sweep>\n      )}\n    </Tag>\n  );\n}\n\nexport default GradientHeading;\n"}],"categories":["text"],"meta":{"tier":"free","demo":"import { ArrowRight } from \"lucide-react\";\nimport { GradientHeading } from \"./gradient-heading\";\n\nexport default function Demo() {\n  return (\n    <div className=\"mx-auto w-full max-w-3xl py-6 text-center\">\n      <p className=\"text-[13px] font-medium uppercase tracking-[0.08em] text-muted-foreground\">\n        Now serving Miami and Fort Lauderdale\n      </p>\n      <GradientHeading highlight={[\"calls you back\"]} className=\"mx-auto mt-5 max-w-2xl\">\n        The roofing crew that actually calls you back.\n      </GradientHeading>\n      <p className=\"mx-auto mt-6 max-w-[480px] text-[17px] leading-relaxed text-muted-foreground sm:text-[19px]\">\n        Same day quotes, fixed pricing and a 10 year workmanship warranty on every job.\n      </p>\n      <a\n        href=\"#\"\n        className=\"group mt-8 inline-flex h-12 items-center gap-2 rounded-full bg-brand px-6 text-[15px] font-medium text-brand-foreground transition-colors hover:bg-brand/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n      >\n        Get a same day quote\n        <ArrowRight className=\"size-4 transition-transform duration-300 group-hover:translate-x-0.5\" aria-hidden />\n      </a>\n    </div>\n  );\n}\n"}}