Componentes
[ui] · motion

SparklesText

Texto con destellos animados que se regeneran en loop. Perfecto para titulares llamativos.

motion
@/components/ui/sparkles-text
Brilla con SFESS
1"use client";
2import { useEffect, useState } from "react";
3import { motion } from "motion/react"
4 
5import { cn } from "@/lib/utils"
6 
7const Sparkle = ({ id, x, y, color, delay, scale }) => {
8 return (
9 <motion.svg
10 key={id}
11 className="pointer-events-none absolute z-20"
12 initial={{ opacity: 0, left: x, top: y }}
13 animate={{
14 opacity: [0, 1, 0],
15 scale: [0, scale, 0],
16 rotate: [75, 120, 150],
17 }}
18 transition={{ duration: 0.8, repeat: Infinity, delay }}
19 width="21"
20 height="21"
21 viewBox="0 0 21 21">
22 <path
23 d="M9.82531 0.843845C10.0553 0.215178 10.9446 0.215178 11.1746 0.843845L11.8618 2.72026C12.4006 4.19229 12.3916 6.39157 13.5 7.5C14.6084 8.60843 16.8077 8.59935 18.2797 9.13822L20.1561 9.82534C20.7858 10.0553 20.7858 10.9447 20.1561 11.1747L18.2797 11.8618C16.8077 12.4007 14.6084 12.3916 13.5 13.5C12.3916 14.6084 12.4006 16.8077 11.8618 18.2798L11.1746 20.1562C10.9446 20.7858 10.0553 20.7858 9.82531 20.1562L9.13819 18.2798C8.59932 16.8077 8.60843 14.6084 7.5 13.5C6.39157 12.3916 4.19225 12.4007 2.72023 11.8618L0.843814 11.1747C0.215148 10.9447 0.215148 10.0553 0.843814 9.82534L2.72023 9.13822C4.19225 8.59935 6.39157 8.60843 7.5 7.5C8.60843 6.39157 8.59932 4.19229 9.13819 2.72026L9.82531 0.843845Z"
24 fill={color} />
25 </motion.svg>
26 );
27}
28 
29export const SparklesText = ({
30 children,
31 colors = { first: "#9E7AFF", second: "#FE8BBB" },
32 className,
33 sparklesCount = 10,
34 ...props
35}) => {
36 const [sparkles, setSparkles] = useState([])
37 
38 useEffect(() => {
39 const generateStar = () => {
40 const starX = `${Math.random() * 100}%`
41 const starY = `${Math.random() * 100}%`
42 const color = Math.random() > 0.5 ? colors.first : colors.second
43 const delay = Math.random() * 2
44 const scale = Math.random() * 1 + 0.3
45 const lifespan = Math.random() * 10 + 5
46 const id = `${starX}-${starY}-${Date.now()}`
47 return { id, x: starX, y: starY, color, delay, scale, lifespan }
48 }
49 
50 const initializeStars = () => {
51 const newSparkles = Array.from({ length: sparklesCount }, generateStar)
52 setSparkles(newSparkles)
53 }
54 
55 const updateStars = () => {
56 setSparkles((currentSparkles) =>
57 currentSparkles.map((star) => {
58 if (star.lifespan <= 0) {
59 return generateStar();
60 } else {
61 return { ...star, lifespan: star.lifespan - 0.1 }
62 }
63 }))
64 }
65 
66 initializeStars()
67 const interval = setInterval(updateStars, 100)
68 
69 return () => clearInterval(interval);
70 }, [colors.first, colors.second, sparklesCount])
71 
72 return (
73 <div
74 className={cn("text-6xl font-bold", className)}
75 {...props}
76 style={
77 {
78 "--sparkles-first-color": `${colors.first}`,
79 "--sparkles-second-color": `${colors.second}`
80 }
81 }>
82 <span className="relative inline-block">
83 {sparkles.map((sparkle) => (
84 <Sparkle key={sparkle.id} {...sparkle} />
85 ))}
86 <strong>{children}</strong>
87 </span>
88 </div>
89 );
90}
91 

Uso

Props

PropTipoDefaultDescripción
childrenReactNode—Texto a animar.
colors{first, second}…Colores de los destellos.
sparklesCountnumber10Cantidad de destellos.

Acciones del componente

Search for a command to run...

Potenciá tu negocio con SFESS

Software a medida, IA integrada y ciberseguridad avanzada para empresas.

0años de ingeniería
0proyectos entregados
0% uptime
Servicios destacados
  • Consultoría SEO Avanzado & Analítica

    Auditoría técnica profunda para posicionar tu negocio en los primeros resultados de Google.

    SEO TécnicoGA4
  • Páginas Web Corporativas Complejas

    Plataformas empresariales masivas con múltiples secciones y animaciones fluidas.

    Framer MotionMulti-page
  • Integración de Inteligencia Artificial en Negocios

    Automatizamos la atención, las reservas y las ventas de tu negocio con agentes de IA.

    AI AgentsChatbots
Nuestro ecosistema
WORKENTA_OSSFESS_SOLUTIONSPRANALUZ_YOGAREMY_AI
Ver todos los servicios