58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import React from 'react';
|
|
|
|
interface SvgTextLogoProps {
|
|
text: string;
|
|
className?: string;
|
|
fontSize?: number;
|
|
fontWeight?: number | string;
|
|
fontFamily?: string;
|
|
fill?: string;
|
|
dominantBaseline?: 'auto' | 'middle' | 'central' | 'text-bottom' | 'alphabetic' | 'ideographic' | 'hanging';
|
|
}
|
|
|
|
const SvgTextLogo = React.forwardRef<SVGSVGElement, SvgTextLogoProps>(
|
|
(
|
|
{
|
|
text,
|
|
className = '',
|
|
fontSize = 48,
|
|
fontWeight = 'bold',
|
|
fontFamily = 'inherit',
|
|
fill = 'currentColor',
|
|
dominantBaseline = 'middle',
|
|
},
|
|
ref
|
|
) => {
|
|
const textLength = text.length;
|
|
const charWidth = fontSize * 0.6;
|
|
const totalWidth = textLength * charWidth + 20;
|
|
|
|
return (
|
|
<svg
|
|
ref={ref}
|
|
viewBox={`0 0 ${totalWidth} ${fontSize + 20}`}
|
|
width={totalWidth}
|
|
height={fontSize + 20}
|
|
className={className}
|
|
preserveAspectRatio="xMidYMid meet"
|
|
>
|
|
<text
|
|
x={totalWidth / 2}
|
|
y={fontSize / 2 + 10}
|
|
textAnchor="middle"
|
|
fontSize={fontSize}
|
|
fontWeight={fontWeight}
|
|
fontFamily={fontFamily}
|
|
fill={fill}
|
|
dominantBaseline={dominantBaseline}
|
|
>
|
|
{text}
|
|
</text>
|
|
</svg>
|
|
);
|
|
}
|
|
);
|
|
|
|
SvgTextLogo.displayName = 'SvgTextLogo';
|
|
|
|
export default SvgTextLogo; |