We are working on new components <3
HextaUIHextaUI

Gradient Tracing

An animated line component with a moving gradient and optional logos at the endpoints.

Preview

A
B

Code

GradientTracing.tsx
"use client";
 
import React from "react";
import { motion } from "motion/react";
import Image from "next/image";
 
interface GradientTracingProps {
  width: number;
  height: number;
  baseColor?: string;
  gradientColors?: [string, string, string];
  animationDuration?: number;
  strokeWidth?: number;
}
 
export const GradientTracing: React.FC<GradientTracingProps> = ({
  width,
  height,
  baseColor = "black",
  gradientColors = ["#2EB9DF", "#2EB9DF", "#9E00FF"],
  animationDuration = 2,
  strokeWidth = 2,
}) => {
  const gradientId = `pulse-${Math.random().toString(36).substr(2, 9)}`;
 
  return (
    <div className="relative" style={{ width, height }}>
      <svg
        width={width}
        height={height}
        viewBox={`0 0 ${width} ${height}`}
        fill="none"
      >
        <line
          x1={0}
          y1={height / 2}
          x2={width}
          y2={height / 2}
          stroke={baseColor}
          strokeOpacity="0.2"
        />
        <line
          x1={0}
          y1={height / 2}
          x2={width}
          y2={height / 2}
          stroke={`url(#${gradientId})`}
          strokeLinecap="round"
          strokeWidth={strokeWidth}
        />
        <defs>
          <motion.linearGradient
            animate={{
              x1: [0, width * 2],
              x2: [0, width],
            }}
            transition={{
              duration: animationDuration,
              repeat: Infinity,
              ease: "linear",
            }}
            id={gradientId}
            gradientUnits="userSpaceOnUse"
          >
            <stop stopColor={gradientColors[0]} stopOpacity="0" />
            <stop stopColor={gradientColors[1]} />
            <stop offset="1" stopColor={gradientColors[2]} stopOpacity="0" />
          </motion.linearGradient>
        </defs>
      </svg>
    </div>
  );
};

Usage

index.tsx
import { GradientTracing } from "@/components/library/animation/GradientTracing";
 
<div className="flex items-center justify-center p-4">
  <GradientTracing
    width={300}
    height={50}
    gradientColors={["#2EB9DF", "#2EB9DF", "#9E00FF"]}
    animationDuration={2}
  />
</div>;

Examples

Curved path

Sine wave

Heart shape

Spiral

Double helix

Infinity symbol

Bouncing ball

Lightning bolt

Zigzag path

Loop path

Props

PropTypeDefault
width
number
-
height
number
-
path
string
-
baseColor
string
-
gradientColors
[string, string, string]
-
animationDuration
number
-
strokeWidth
number
-
Edit on GitHub

Last updated on

On this page