import { useEffect, useRef } from "react"; interface SvgIconProps extends React.SVGProps { content: string; // the SVG content as a string } export function SvgIcon({ content, ...props }: SvgIconProps) { const containerRef = useRef(null); useEffect(() => { if (!containerRef.current) return; // Parse the SVG string const parser = new DOMParser(); const doc = parser.parseFromString(content, 'image/svg+xml'); const svgEl = doc.querySelector('svg'); if (!svgEl) { console.warn('SvgIcon: No element found in provided string'); containerRef.current.innerHTML = ''; return; } // Apply all passed props to the SVG element props && Object.entries(props).forEach(([key, value]) => { if (value == null) return; const attrName = key === 'className' ? 'class' : key; svgEl.setAttribute(attrName, String(value)); }); // Clear and append the new SVG containerRef.current.innerHTML = ''; containerRef.current.appendChild(svgEl); }, [content, props]); return ; } export function createSvgIcon(content: string): React.ComponentType> { const IconComponent: React.FC> = (props) => { return ; }; return IconComponent; }