Light Rays
magicui/light-raysFreeComponent
A component with animated light rays which shine down from above.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/light-rays.jsonSource
1"use client"23import { useEffect, useState, type CSSProperties } from "react"4import { motion } from "motion/react"56import { cn } from "@/lib/utils"78interface LightRaysProps extends React.HTMLAttributes<HTMLDivElement> {9 ref?: React.Ref<HTMLDivElement>10 count?: number11 color?: string12 blur?: number13 speed?: number14 length?: string15}1617type LightRay = {18 id: string19 left: number20 rotate: number21 width: number22 swing: number23 delay: number24 duration: number25 intensity: number26}2728const createRays = (count: number, cycle: number): LightRay[] => {29 if (count <= 0) return []3031 return Array.from({ length: count }, (_, index) => {32 const left = 8 + Math.random() * 8433 const rotate = -28 + Math.random() * 5634 const width = 160 + Math.random() * 16035 const swing = 0.8 + Math.random() * 1.836 const delay = Math.random() * cycle37 const duration = cycle * (0.75 + Math.random() * 0.5)38 const intensity = 0.6 + Math.random() * 0.53940 return {41 id: `${index}-${Math.round(left * 10)}`,42 left,43 rotate,44 width,45 swing,46 delay,47 duration,48 intensity,49 }50 })51}5253const Ray = ({54 left,55 rotate,56 width,57 swing,58 delay,59 duration,60 intensity,61}: LightRay) => {62 return (63 <motion.div64 className="pointer-events-none absolute -top-[12%] left-[var(--ray-left)] h-[var(--light-rays-length)] w-[var(--ray-width)] origin-top -translate-x-1/2 rounded-full bg-linear-to-b from-[color-mix(in_srgb,var(--light-rays-color)_70%,transparent)] to-transparent opacity-0 mix-blend-screen blur-[var(--light-rays-blur)]"65 style={66 {67 "--ray-left": `${left}%`,68 "--ray-width": `${width}px`,69 } as CSSProperties70 }71 initial={{ rotate: rotate }}72 animate={{73 opacity: [0, intensity, 0],74 rotate: [rotate - swing, rotate + swing, rotate - swing],75 }}76 transition={{77 duration: duration,78 repeat: Infinity,79 ease: "easeInOut",80 delay: delay,81 repeatDelay: duration * 0.1,82 }}83 />84 )85}8687export function LightRays({88 className,89 style,90 count = 7,91 color = "rgba(160, 210, 255, 0.2)",92 blur = 36,93 speed = 14,94 length = "70vh",95 ref,96 ...props97}: LightRaysProps) {98 const [rays, setRays] = useState<LightRay[]>([])99 const cycleDuration = Math.max(speed, 0.1)100101 useEffect(() => {102 setRays(createRays(count, cycleDuration))103 }, [count, cycleDuration])104105 return (106 <div107 ref={ref}108// … truncated
What it pulls in
npm packages
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
