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

This commit is contained in:
2026-03-12 05:26:21 +00:00
parent aa9668517f
commit a64c24bb93

View File

@@ -1,50 +1,51 @@
"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;
textClassName?: string;
ariaLabel?: string;
}
const SvgTextLogo = memo<SvgTextLogoProps>(function SvgTextLogo({
logoText,
adjustHeightFactor,
verticalAlign = "top",
className = "",
}) {
const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor);
const SvgTextLogo = React.forwardRef<SVGSVGElement, SvgTextLogoProps>(
(
{ text = "Webild", className = "", textClassName = "", ariaLabel },
ref
) => {
const textLength = text.length;
const charWidth = 50;
const viewBoxWidth = textLength * charWidth + 20;
return (
<svg
ref={svgRef}
viewBox={viewBox}
className={cls("w-full", className)}
style={{ aspectRatio: aspectRatio }}
preserveAspectRatio="none"
role="img"
aria-label={`${logoText} logo`}
>
<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"
}}
return (
<svg
ref={ref}
viewBox={`0 0 ${viewBoxWidth} 100`}
className={`w-full h-full ${className}`}
xmlns="http://www.w3.org/2000/svg"
aria-label={ariaLabel || text}
role="img"
>
{logoText}
</text>
</svg>
);
});
<defs>
<style>{`
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;900&display=swap');
`}</style>
</defs>
<text
x="50%"
y="50%"
dominantBaseline="middle"
textAnchor="middle"
className={`fill-current font-bold text-4xl ${textClassName}`}
fontFamily="Inter, sans-serif"
fontSize="48"
fontWeight="900"
>
{text}
</text>
</svg>
);
}
);
SvgTextLogo.displayName = "SvgTextLogo";