Spotlight New
A new spotlight component with left and right spotlight, configurable and customizable.
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
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 |
Build websites faster and 10x better than your competitors with Aceternity UI Pro
With the best in class components and templates, stand out from the crowd and get more attention to your website. Trusted by founders and entrepreneurs from all over the world.
This service exceeded our expectations, since not only was the
development technically flawless, but Manu and his team also acted as
strategic partners by encouraging us to add ...
Georg Weingartner
CMO at Renderwork