feat: add text and color props to GlitchText component and make children optional.

This commit is contained in:
n.tolstov 2025-11-30 23:20:41 +03:00
parent 059e6eedf9
commit 101cf97cc2

View File

@ -4,20 +4,26 @@ import React from "react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
interface GlitchTextProps { interface GlitchTextProps {
children: string; children?: string;
text?: string;
as?: "h1" | "h2" | "h3" | "h4" | "span" | "p"; as?: "h1" | "h2" | "h3" | "h4" | "span" | "p";
className?: string; className?: string;
glitchClassName?: string; glitchClassName?: string;
intensity?: "low" | "medium" | "high"; intensity?: "low" | "medium" | "high";
color?: string;
} }
export function GlitchText({ export function GlitchText({
children, children,
text,
as: Component = "span", as: Component = "span",
className, className,
glitchClassName, glitchClassName,
intensity = "medium", intensity = "medium",
color,
}: GlitchTextProps) { }: GlitchTextProps) {
const content = text || children || "";
const intensityStyles = { const intensityStyles = {
low: "hover:animate-glitch-text", low: "hover:animate-glitch-text",
medium: "animate-glitch-text", medium: "animate-glitch-text",
@ -31,9 +37,10 @@ export function GlitchText({
intensityStyles[intensity], intensityStyles[intensity],
className className
)} )}
data-text={children} style={color ? { color } : undefined}
data-text={content}
> >
{children} {content}
{/* Glitch layers */} {/* Glitch layers */}
<span <span
className={cn( className={cn(
@ -49,7 +56,7 @@ export function GlitchText({
}} }}
aria-hidden aria-hidden
> >
{children} {content}
</span> </span>
<span <span
className={cn( className={cn(
@ -65,7 +72,7 @@ export function GlitchText({
}} }}
aria-hidden aria-hidden
> >
{children} {content}
</span> </span>
</Component> </Component>
); );