Files
bb2c80db-27de-47e7-8bd3-5c9…/src/components/shared/SvgTextLogo/SvgTextLogo.tsx

57 lines
1.4 KiB
TypeScript

import React from 'react';
interface SvgTextLogoProps {
text: string;
className?: string;
dominantBaseline?: 'auto' | 'text-after-edge' | 'alphabetic' | 'ideographic' | 'middle' | 'central' | 'mathematical' | 'hanging';
fontSize?: number;
fontWeight?: string | number;
fill?: string;
}
const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
text,
className = '',
dominantBaseline = 'middle',
fontSize = 48,
fontWeight = 'bold',
fill = 'currentColor',
}) => {
const textRef = React.useRef<SVGTextElement>(null);
const svgRef = React.useRef<SVGSVGElement>(null);
React.useEffect(() => {
if (textRef.current && svgRef.current) {
const bbox = textRef.current.getBBox();
svgRef.current.setAttribute('viewBox', `${bbox.x} ${bbox.y} ${bbox.width} ${bbox.height}`);
}
}, [text]);
return (
<svg
ref={svgRef}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 500 100"
className={`w-full h-full ${className}`}
preserveAspectRatio="xMidYMid meet"
>
<text
ref={textRef}
x="50%"
y="50%"
dominantBaseline={dominantBaseline}
fontSize={fontSize}
fontWeight={fontWeight}
fill={fill}
textAnchor="middle"
style={{
fontFamily: 'inherit',
}}
>
{text}
</text>
</svg>
);
};
export default SvgTextLogo;