diff --git a/src/components/shared/SvgTextLogo/SvgTextLogo.tsx b/src/components/shared/SvgTextLogo/SvgTextLogo.tsx index f214190..fea4c08 100644 --- a/src/components/shared/SvgTextLogo/SvgTextLogo.tsx +++ b/src/components/shared/SvgTextLogo/SvgTextLogo.tsx @@ -1,51 +1,78 @@ "use client"; -import { memo } from "react"; -import useSvgTextLogo from "./useSvgTextLogo"; -import { cls } from "@/lib/utils"; +import React, { useEffect, useRef } from "react"; +import gsap from "gsap"; +import { ScrollTrigger } from "gsap/ScrollTrigger"; + +gsap.registerPlugin(ScrollTrigger); interface SvgTextLogoProps { - logoText: string; - adjustHeightFactor?: number; - verticalAlign?: "top" | "center"; + text?: string; className?: string; + containerClassName?: string; + textClassName?: string; + id?: string; } -const SvgTextLogo = memo(function SvgTextLogo({ - logoText, - adjustHeightFactor, - verticalAlign = "top", - className = "", -}) { - const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor); +const SvgTextLogo = React.forwardRef( + ( + { + text = "Webild", className = "", containerClassName = "", textClassName = "", id = "svg-text-logo" + }, + ref + ) => { + const containerRef = useRef(null); + const svgRef = useRef(null); + const textRef = useRef(null); - return ( - - - {logoText} - - - ); -}); + // Combine refs + React.useImperativeHandle(ref, () => svgRef.current as SVGSVGElement); + + useEffect(() => { + if (!containerRef.current || !svgRef.current || !textRef.current) return; + + const container = containerRef.current; + const svg = svgRef.current; + const textElement = textRef.current; + + // Get text width + const bbox = textElement.getBBox(); + const textWidth = bbox.width; + const textHeight = bbox.height; + + // Set SVG dimensions based on text + svg.setAttribute("width", String(textWidth + 40)); + svg.setAttribute("height", String(textHeight + 20)); + svg.setAttribute("viewBox", `0 0 ${textWidth + 40} ${textHeight + 20}`); + + // Position text in the center + textElement.setAttribute("x", String(20)); + textElement.setAttribute("y", String(textHeight + 10)); + }, [text]); + + return ( +
+ + + {text} + + +
+ ); + } +); SvgTextLogo.displayName = "SvgTextLogo"; -export default SvgTextLogo; +export default SvgTextLogo; \ No newline at end of file