Hyperlink

PreviousNext

Hyperlink component with animated underline, smooth hover & customizable style.

Docs
scrollxuicomponent

Preview

Loading preview…
components/ui/hyperlink.tsx
"use client";
import React from "react";
import { cn } from "@/lib/utils";

interface HyperlinkProps {
  href: string;
  children: React.ReactNode;
  className?: string;
  underlineClassName?: string;
}

const Hyperlink: React.FC<HyperlinkProps> = ({
  href,
  children,
  className,
  underlineClassName,
}) => {
  const [isHovered, setIsHovered] = React.useState(false);

  return (
    <a
      href={href}
      onMouseEnter={() => setIsHovered(true)}
      onMouseLeave={() => setIsHovered(false)}
      className={cn(
        "relative inline-block text-sm font-medium tracking-wide text-foreground",
        className
      )}
    >
      <span className="relative z-10">{children}</span>
      <span className="absolute left-0 w-full h-[1.5px] bg-muted-foreground/30 -bottom-2" />
      <span
        className={cn(
          "absolute left-0 w-full h-[1.5px] bg-foreground transform scale-x-0 transition-transform duration-500 ease-out -bottom-2",
          isHovered ? "scale-x-100 origin-left" : "scale-x-0 origin-right",
          underlineClassName
        )}
      />
    </a>
  );
};

export { Hyperlink };

Installation

npx shadcn@latest add @scrollxui/hyperlink

Usage

import { Hyperlink } from "@/components/hyperlink"
<Hyperlink />