import React, { createElement, useRef, useEffect } from 'react'; import { isPlainObj } from '../utils'; export * from './sources'; const isNumSize = (val: any) => /^[\d.]+$/.test(val); const ShadowSVG = (props) => { const ref = useRef(); const width = isNumSize(props.width) ? `${props.width}px` : props.width; const height = isNumSize(props.height) ? `${props.height}px` : props.height; useEffect(() => { if (ref.current) { const root = ref.current.attachShadow({ mode: 'open', }); root.innerHTML = `${props.content}`; } }, []); // @ts-ignore return
; }; const width = 150; const height = 40; const theme = 'light'; export const takeIcon = (infer: React.ReactNode) => { if (React.isValidElement(infer)) { if (infer.type === 'svg') { return React.cloneElement(infer, { height, width, fill: 'currentColor', viewBox: infer.props.viewBox || '0 0 1024 1024', focusable: 'false', 'aria-hidden': 'true', }); } else if (infer.type === 'path' || infer.type === 'g') { return ( ); } } else if (isPlainObj(infer)) { if (infer[theme]) { return takeIcon(infer[theme]); } else if (infer['shadow']) { return ; } return null; } return infer; };