Spotlight New
A new spotlight component with left and right spotlight, configurable and customizable.
Open in Spotlight
Spotlight
which is not overused.
A subtle yet effective spotlight effect, because the previous version is used a bit too much these days.
Installation
Install dependencies
npm i motion clsx tailwind-merge
Add util file
lib/utils.ts
import { ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Copy the source code
components/ui/spotlight-new.tsx
"use client";
import React from "react";
import { motion } from "motion/react";
type SpotlightProps = {
gradientFirst?: string;
gradientSecond?: string;
gradientThird?: string;
translateY?: number;
width?: number;
height?: number;
smallWidth?: number;
duration?: number;
xOffset?: number;
};
export const Spotlight = ({
gradientFirst = "radial-gradient(68.54% 68.72% at 55.02% 31.46%, hsla(210, 100%, 85%, .08) 0, hsla(210, 100%, 55%, .02) 50%, hsla(210, 100%, 45%, 0) 80%)",
gradientSecond = "radial-gradient(50% 50% at 50% 50%, hsla(210, 100%, 85%, .06) 0, hsla(210, 100%, 55%, .02) 80%, transparent 100%)",
gradientThird = "radial-gradient(50% 50% at 50% 50%, hsla(210, 100%, 85%, .04) 0, hsla(210, 100%, 45%, .02) 80%, transparent 100%)",
translateY = -350,
width = 560,
height = 1380,
smallWidth = 240,
duration = 7,
xOffset = 100,
}: SpotlightProps = {}) => {
return (
<motion.div
initial={{
opacity: 0,
}}
animate={{
opacity: 1,
}}
transition={{
duration: 1.5,
}}
className="pointer-events-none absolute inset-0 h-full w-full"
>
<motion.div
animate={{
x: [0, xOffset, 0],
}}
transition={{
duration,
repeat: Infinity,
repeatType: "reverse",
ease: "easeInOut",
}}
className="absolute top-0 left-0 w-screen h-screen z-40 pointer-events-none"
>
<div
style={{
transform: `translateY(${translateY}px) rotate(-45deg)`,
background: gradientFirst,
width: `${width}px`,
height: `${height}px`,
}}
className={`absolute top-0 left-0`}
/>
<div
style={{
transform: "rotate(-45deg) translate(5%, -50%)",
background: gradientSecond,
width: `${smallWidth}px`,
height: `${height}px`,
}}
className={`absolute top-0 left-0 origin-top-left`}
/>
<div
style={{
transform: "rotate(-45deg) translate(-180%, -70%)",
background: gradientThird,
width: `${smallWidth}px`,
height: `${height}px`,
}}
className={`absolute top-0 left-0 origin-top-left`}
/>
</motion.div>
<motion.div
animate={{
x: [0, -xOffset, 0],
}}
transition={{
duration,
repeat: Infinity,
repeatType: "reverse",
ease: "easeInOut",
}}
className="absolute top-0 right-0 w-screen h-screen z-40 pointer-events-none"
>
<div
style={{
transform: `translateY(${translateY}px) rotate(45deg)`,
background: gradientFirst,
width: `${width}px`,
height: `${height}px`,
}}
className={`absolute top-0 right-0`}
/>
<div
style={{
transform: "rotate(45deg) translate(-5%, -50%)",
background: gradientSecond,
width: `${smallWidth}px`,
height: `${height}px`,
}}
className={`absolute top-0 right-0 origin-top-right`}
/>
<div
style={{
transform: "rotate(45deg) translate(180%, -70%)",
background: gradientThird,
width: `${smallWidth}px`,
height: `${height}px`,
}}
className={`absolute top-0 right-0 origin-top-right`}
/>
</motion.div>
</motion.div>
);
};
Props
Prop | Type | Default | Description |
---|---|---|---|
gradientFirst | string | "radial-gradient(68.54% 68.72% at 55.02% 31.46%, hsla(210, 100%, 85%, .08) 0, hsla(210, 100%, 55%, .02) 50%, hsla(210, 100%, 45%, 0) 80%)" | First gradient color for the spotlight effect |
gradientSecond | string | "radial-gradient(50% 50% at 50% 50%, hsla(210, 100%, 85%, .06) 0, hsla(210, 100%, 55%, .02) 80%, transparent 100%)" | Second gradient color for the spotlight effect |
gradientThird | string | "radial-gradient(50% 50% at 50% 50%, hsla(210, 100%, 85%, .04) 0, hsla(210, 100%, 45%, .02) 80%, transparent 100%)" | Third gradient color for the spotlight effect |
translateY | number | -350 | Vertical translation offset in pixels |
width | number | 560 | Width of the main spotlight element in pixels |
height | number | 1380 | Height of the spotlight elements in pixels |
smallWidth | number | 240 | Width of the smaller spotlight elements in pixels |
duration | number | 7 | Animation duration in seconds |
xOffset | number | 100 | Horizontal animation offset in pixels |
Get beautiful, hand-crafted templates and components with Aceternity UI Pro
Professional, beautiful and elegant templates for your business. Get the best component packs and templates with Aceternity UI Pro.
I'd highly recommend working with Manu on a site redesign. We came to Manu with a basic website shell. Manu quickly took our rough concept and transformed it into a polished, user-friendly website....
Ray Thai
Head of Product at Fireworks