Files
81a4b894-3d1a-447f-a5af-16b…/src/components/shared/SvgTextLogo/SvgTextLogo.tsx

59 lines
1.4 KiB
TypeScript

import React from 'react';
interface SvgTextLogoProps {
text: string;
className?: string;
fontSize?: number;
fontWeight?: string | number;
letterSpacing?: number;
fill?: string;
strokeWidth?: number;
stroke?: string;
}
const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
text,
className = '',
fontSize = 48,
fontWeight = 'bold',
letterSpacing = 0,
fill = 'currentColor',
strokeWidth = 0,
stroke = 'none',
}) => {
const textLength = text.length;
const charWidth = fontSize * 0.6;
const width = charWidth * textLength + letterSpacing * (textLength - 1);
const height = fontSize * 1.2;
const padding = 16;
const viewBoxWidth = width + padding * 2;
const viewBoxHeight = height + padding * 2;
return (
<svg
viewBox={`0 0 ${viewBoxWidth} ${viewBoxHeight}`}
className={`overflow-visible ${className}`}
preserveAspectRatio="xMidYMid meet"
xmlns="http://www.w3.org/2000/svg"
>
<text
x={padding + width / 2}
y={padding + fontSize * 0.8}
textAnchor="middle"
dominantBaseline="middle"
fontSize={fontSize}
fontWeight={fontWeight}
letterSpacing={letterSpacing}
fill={fill}
strokeWidth={strokeWidth}
stroke={stroke}
fontFamily="inherit"
>
{text}
</text>
</svg>
);
};
export default SvgTextLogo;