55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
|
|
interface SvgTextLogoProps {
|
|
text: string;
|
|
className?: string;
|
|
fontSize?: number;
|
|
fontWeight?: number | string;
|
|
letterSpacing?: number;
|
|
fill?: string;
|
|
textAnchor?: 'start' | 'middle' | 'end';
|
|
dominantBaseline?: SVGAttributes<SVGTextElement>['dominantBaseline'];
|
|
}
|
|
|
|
const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
|
|
text,
|
|
className = '',
|
|
fontSize = 24,
|
|
fontWeight = 700,
|
|
letterSpacing = 0,
|
|
fill = 'currentColor',
|
|
textAnchor = 'start',
|
|
dominantBaseline = 'auto'
|
|
}) => {
|
|
// Calculate approximate text width for viewBox
|
|
const charWidth = fontSize * 0.6;
|
|
const textWidth = text.length * charWidth + letterSpacing * text.length;
|
|
const viewBoxWidth = textWidth + fontSize;
|
|
const viewBoxHeight = fontSize * 1.5;
|
|
|
|
return (
|
|
<svg
|
|
viewBox={`0 0 ${viewBoxWidth} ${viewBoxHeight}`}
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
className={`inline-block align-middle ${className}`}
|
|
preserveAspectRatio="xMidYMid meet"
|
|
>
|
|
<text
|
|
x={textAnchor === 'start' ? fontSize / 2 : viewBoxWidth / 2}
|
|
y={viewBoxHeight / 2}
|
|
fontSize={fontSize}
|
|
fontWeight={fontWeight}
|
|
letterSpacing={letterSpacing}
|
|
fill={fill}
|
|
textAnchor={textAnchor}
|
|
dominantBaseline="middle"
|
|
fontFamily="inherit"
|
|
>
|
|
{text}
|
|
</text>
|
|
</svg>
|
|
);
|
|
};
|
|
|
|
export default SvgTextLogo;
|