Files
707daeae-3a82-48d9-acd4-0ef…/src/components/shared/SvgTextLogo/SvgTextLogo.tsx

46 lines
1.0 KiB
TypeScript

import React, { useMemo } from "react";
interface SvgTextLogoProps {
text: string;
className?: string;
fontSize?: number;
fontWeight?: string | number;
fill?: string;
dominantBaseline?: "middle";
}
const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
text,
className = "", fontSize = 48,
fontWeight = 700,
fill = "currentColor", dominantBaseline = "middle"}) => {
const textWidth = useMemo(() => {
const charWidth = fontSize * 0.6;
return text.length * charWidth;
}, [text, fontSize]);
const viewBoxWidth = textWidth + 40;
return (
<svg
viewBox={`0 0 ${viewBoxWidth} ${fontSize + 40}`}
className={className}
xmlns="http://www.w3.org/2000/svg"
preserveAspectRatio="xMidYMid meet"
>
<text
x={viewBoxWidth / 2}
y={fontSize / 2 + 20}
fontSize={fontSize}
fontWeight={fontWeight}
fill={fill}
dominantBaseline={dominantBaseline}
textAnchor="middle"
>
{text}
</text>
</svg>
);
};
export default SvgTextLogo;