Files
5da789de-f2ea-4b67-bdf4-435…/src/components/shared/SvgTextLogo/SvgTextLogo.tsx

66 lines
1.7 KiB
TypeScript

import React from 'react';
interface SvgTextLogoProps {
text: string;
className?: string;
fontSize?: number;
fontFamily?: string;
fontWeight?: number | string;
fill?: string;
stroke?: string;
strokeWidth?: number;
letterSpacing?: number;
dominantBaseline?: 'auto' | 'middle' | 'before-edge' | 'text-before-edge' | 'central' | 'after-edge' | 'text-after-edge' | 'ideographic' | 'alphabetic' | 'hanging' | 'mathematical' | 'inherit' | 'use-script' | 'no-change' | 'reset-size';
}
const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
text,
className = '',
fontSize = 48,
fontFamily = 'Arial, sans-serif',
fontWeight = 700,
fill = 'currentColor',
stroke = 'none',
strokeWidth = 0,
letterSpacing = 0,
dominantBaseline = 'middle',
}) => {
const textLength = text.length;
const charWidth = fontSize * 0.5;
const totalWidth = textLength * charWidth + letterSpacing * (textLength - 1);
const padding = 20;
const width = totalWidth + padding * 2;
const height = fontSize + padding * 2;
const xStart = padding + charWidth / 2;
const yStart = height / 2;
return (
<svg
width={width}
height={height}
viewBox={`0 0 ${width} ${height}`}
xmlns="http://www.w3.org/2000/svg"
className={className}
preserveAspectRatio="xMidYMid meet"
>
<text
x={xStart}
y={yStart}
fontSize={fontSize}
fontFamily={fontFamily}
fontWeight={fontWeight}
fill={fill}
stroke={stroke}
strokeWidth={strokeWidth}
letterSpacing={letterSpacing}
dominantBaseline={dominantBaseline}
textAnchor="start"
>
{text}
</text>
</svg>
);
};
export default SvgTextLogo;