Update src/components/shared/SvgTextLogo/SvgTextLogo.tsx

This commit is contained in:
2026-03-13 02:30:30 +00:00
parent 5bdf8ccbc9
commit 77d4d5aff9

View File

@@ -1,51 +1,61 @@
"use client";
import { memo } from "react";
import useSvgTextLogo from "./useSvgTextLogo";
import { cls } from "@/lib/utils";
import React from 'react';
interface SvgTextLogoProps {
logoText: string;
adjustHeightFactor?: number;
verticalAlign?: "top" | "center";
text: string;
className?: string;
animationType?: 'none' | 'wave' | 'float';
}
const SvgTextLogo = memo<SvgTextLogoProps>(function SvgTextLogo({
logoText,
adjustHeightFactor,
verticalAlign = "top",
className = "",
}) {
const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor);
export const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
text,
className = '',
animationType = 'none',
}) => {
const characters = text.split('');
const characterWidth = 20;
const totalWidth = characters.length * characterWidth;
const fontSize = 32;
return (
<svg
ref={svgRef}
viewBox={viewBox}
className={cls("w-full", className)}
style={{ aspectRatio: aspectRatio }}
preserveAspectRatio="none"
role="img"
aria-label={`${logoText} logo`}
width={totalWidth + 40}
height={fontSize + 20}
viewBox={`0 0 ${totalWidth + 40} ${fontSize + 20}`}
className={className}
aria-label={text}
>
<text
ref={textRef}
x="0"
y={verticalAlign === "center" ? "50%" : "0"}
className="font-bold fill-current"
style={{
fontSize: "20px",
letterSpacing: "-0.02em",
dominantBaseline: verticalAlign === "center" ? "middle" : "text-before-edge"
}}
>
{logoText}
</text>
{characters.map((char, index) => {
let yOffset = 0;
let animationDelay = 0;
if (animationType === 'wave') {
yOffset = Math.sin((index / characters.length) * Math.PI) * 5;
animationDelay = index * 50;
} else if (animationType === 'float') {
animationDelay = index * 100;
}
return (
<text
key={index}
x={20 + index * characterWidth}
y={fontSize}
fontSize={fontSize}
fontWeight="bold"
dominantBaseline="auto"
textAnchor="middle"
fill="currentColor"
style={{
transform: `translateY(${yOffset}px)`,
opacity: animationType !== 'none' ? 1 : 1,
}}
>
{char}
</text>
);
})}
</svg>
);
});
};
SvgTextLogo.displayName = "SvgTextLogo";
export default SvgTextLogo;
export default SvgTextLogo;