61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import React, { useEffect, useRef } from 'react';
|
|
|
|
interface SvgTextLogoProps {
|
|
text?: string;
|
|
className?: string;
|
|
textClassName?: string;
|
|
fontSize?: number;
|
|
fontWeight?: number | string;
|
|
letterSpacing?: number;
|
|
dominantBaseline?: 'auto' | 'text-before-edge' | 'hanging' | 'middle' | 'central' | 'alphabetic' | 'ideographic' | 'mathematical' | 'inherit';
|
|
}
|
|
|
|
export const SvgTextLogo: React.FC<SvgTextLogoProps> = ({
|
|
text = 'Logo',
|
|
className = '',
|
|
textClassName = '',
|
|
fontSize = 32,
|
|
fontWeight = 700,
|
|
letterSpacing = 0,
|
|
dominantBaseline = 'central',
|
|
}) => {
|
|
const svgRef = useRef<SVGSVGElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (svgRef.current) {
|
|
const textElement = svgRef.current.querySelector('text');
|
|
if (textElement) {
|
|
const bbox = textElement.getBBox();
|
|
svgRef.current.setAttribute('viewBox', `${bbox.x - 10} ${bbox.y - 10} ${bbox.width + 20} ${bbox.height + 20}`);
|
|
svgRef.current.setAttribute('width', String(bbox.width + 20));
|
|
svgRef.current.setAttribute('height', String(bbox.height + 20));
|
|
}
|
|
}
|
|
}, [text]);
|
|
|
|
return (
|
|
<svg
|
|
ref={svgRef}
|
|
className={className}
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 200 60"
|
|
width="200"
|
|
height="60"
|
|
>
|
|
<text
|
|
x="100"
|
|
y="30"
|
|
textAnchor="middle"
|
|
dominantBaseline={dominantBaseline}
|
|
fontSize={fontSize}
|
|
fontWeight={fontWeight}
|
|
letterSpacing={letterSpacing}
|
|
className={textClassName}
|
|
>
|
|
{text}
|
|
</text>
|
|
</svg>
|
|
);
|
|
};
|
|
|
|
export default SvgTextLogo; |