From 34dfd2bb6ec0c56a7aa66b8f4f63419d91cd7da5 Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 11 Mar 2026 14:25:28 +0000 Subject: [PATCH] Update src/components/shared/SvgTextLogo/SvgTextLogo.tsx --- .../shared/SvgTextLogo/SvgTextLogo.tsx | 80 ++++++++++--------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/src/components/shared/SvgTextLogo/SvgTextLogo.tsx b/src/components/shared/SvgTextLogo/SvgTextLogo.tsx index f214190..efc9c90 100644 --- a/src/components/shared/SvgTextLogo/SvgTextLogo.tsx +++ b/src/components/shared/SvgTextLogo/SvgTextLogo.tsx @@ -1,51 +1,59 @@ -"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; + fontSize?: number; + fontFamily?: string; + fontWeight?: string | number; + fill?: string; className?: string; } -const SvgTextLogo = memo(function SvgTextLogo({ - logoText, - adjustHeightFactor, - verticalAlign = "top", - className = "", -}) { - const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor); +const SvgTextLogo: React.FC = ({ + text, + fontSize = 24, + fontFamily = "Arial", fontWeight = "bold", fill = "currentColor", className = ""}) => { + const textMetrics = useMemo(() => { + const canvas = typeof document !== "undefined" ? document.createElement("canvas") : null; + if (!canvas) return { width: text.length * fontSize * 0.5, height: fontSize }; + + const ctx = canvas.getContext("2d"); + if (!ctx) return { width: text.length * fontSize * 0.5, height: fontSize }; + + ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`; + const metrics = ctx.measureText(text); + + return { + width: metrics.width, + height: fontSize, + }; + }, [text, fontSize, fontFamily, fontWeight]); + + const padding = 8; + const svgWidth = textMetrics.width + padding * 2; + const svgHeight = textMetrics.height + padding * 2; return ( - {logoText} + {text} ); -}); +}; -SvgTextLogo.displayName = "SvgTextLogo"; - -export default SvgTextLogo; +export default SvgTextLogo; \ No newline at end of file