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

This commit is contained in:
2026-03-10 18:56:36 +00:00
parent c42bbcf402
commit d202632c00

View File

@@ -1,51 +1,57 @@
"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;
width?: number;
height?: number;
fontSize?: number;
fontWeight?: number | string;
letterSpacing?: number;
textAnchor?: 'start' | 'middle' | 'end';
dominantBaseline?: SVGTextElementAttributes<SVGTextElement>['dominantBaseline'];
}
const SvgTextLogo = memo<SvgTextLogoProps>(function SvgTextLogo({
logoText,
adjustHeightFactor,
verticalAlign = "top",
className = "",
}) {
const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor);
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"
}}
const SvgTextLogo = React.forwardRef<SVGSVGElement, SvgTextLogoProps>(
(
{
text,
className = '',
width = 400,
height = 200,
fontSize = 48,
fontWeight = 700,
letterSpacing = 0,
textAnchor = 'middle',
dominantBaseline = 'middle',
},
ref
) => {
return (
<svg
ref={ref}
width={width}
height={height}
viewBox={`0 0 ${width} ${height}`}
className={className}
>
{logoText}
</text>
</svg>
);
});
<text
x={width / 2}
y={height / 2}
fontSize={fontSize}
fontWeight={fontWeight}
letterSpacing={letterSpacing}
textAnchor={textAnchor}
dominantBaseline="central"
fill="currentColor"
>
{text}
</text>
</svg>
);
}
);
SvgTextLogo.displayName = "SvgTextLogo";
SvgTextLogo.displayName = 'SvgTextLogo';
export default SvgTextLogo;