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

This commit is contained in:
2026-03-10 20:35:47 +00:00
parent f86bc5cf22
commit b32626868d

View File

@@ -1,51 +1,53 @@
"use client";
import { memo } from "react";
import useSvgTextLogo from "./useSvgTextLogo";
import { cls } from "@/lib/utils";
import React, { useMemo } from "react";
interface SvgTextLogoProps {
logoText: string;
adjustHeightFactor?: number;
verticalAlign?: "top" | "center";
text: string;
className?: string;
width?: number;
height?: number;
fontSize?: number;
fontWeight?: string | number;
fill?: string;
strokeWidth?: number;
stroke?: string;
dominantBaseline?: "hanging" | "middle" | "central" | "text-bottom" | "alphabetic" | "baseline";
}
const SvgTextLogo = memo<SvgTextLogoProps>(function SvgTextLogo({
logoText,
adjustHeightFactor,
verticalAlign = "top",
className = "",
}) {
const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor);
const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
text,
className,
width = 200,
height = 100,
fontSize = 32,
fontWeight = "bold", fill = "currentColor", strokeWidth = 0,
stroke = "none", dominantBaseline = "middle"}) => {
const textWidth = useMemo(() => {
return text.length * (fontSize * 0.6);
}, [text, fontSize]);
return (
<svg
ref={svgRef}
viewBox={viewBox}
className={cls("w-full", className)}
style={{ aspectRatio: aspectRatio }}
preserveAspectRatio="none"
role="img"
aria-label={`${logoText} logo`}
viewBox={`0 0 ${Math.max(width, textWidth)} ${height}`}
className={className}
width={width}
height={height}
xmlns="http://www.w3.org/2000/svg"
>
<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"
}}
x={Math.max(width, textWidth) / 2}
y={height / 2}
textAnchor="middle"
dominantBaseline={dominantBaseline}
fontSize={fontSize}
fontWeight={fontWeight}
fill={fill}
strokeWidth={strokeWidth}
stroke={stroke}
>
{logoText}
{text}
</text>
</svg>
);
});
};
SvgTextLogo.displayName = "SvgTextLogo";
export default SvgTextLogo;
export default SvgTextLogo;