import React from 'react'; import { useThemeProps } from '../../../hooks'; import { useToken } from '../../../hooks'; import styled from 'styled-components/native'; import { border, color, flexbox, layout, space, typography, position, } from 'styled-system'; import { customBorder, customBackground, customOutline, customLayout, customExtra, customShadow, customTypography, customPosition, } from '../../../utils/customProps'; import { Svg, Path, G, Circle, Ellipse, Text, TSpan, TextPath, Polygon, Polyline, Line, Rect, Use, Image, Symbol, Defs, LinearGradient, RadialGradient, Stop, ClipPath, Pattern, Mask, } from 'react-native-svg'; import type { IIconProps } from './types'; const VALID_SVG_COMPONENTS: any = { G, Path, Circle, Ellipse, Text, TSpan, TextPath, Polygon, Polyline, Line, Rect, Use, Image, Symbol, Defs, LinearGradient, RadialGradient, Stop, ClipPath, Pattern, Mask, }; const SVG = styled(Svg)( color, space, layout, flexbox, border, typography, position, customPosition, customBorder, customBackground, customOutline, customShadow, customExtra, customLayout, customTypography ); const SVGIcon = ( { viewBox, color: colorProp, stroke, strokeWidth, children, focusable, size, style, }: IIconProps, ref: any ) => { const newProps = useThemeProps('Icon', { size }); let strokeColor = useToken('colors', stroke || ''); colorProp = useToken('colors', colorProp || ''); return ( {React.Children.count(children) > 0 ? ( {React.Children.map(children, ({ props: childProps, type }: any) => type && type.name && Object.keys(VALID_SVG_COMPONENTS).includes(type.name) ? ( ) : null )} ) : ( getDefaultIcon(ref) )} ); }; const ChildPath = ({ type, fill, stroke: pathStroke, ...remainingProps }: any) => { const Component = VALID_SVG_COMPONENTS[type]; const pathStrokeColor = useToken('colors', pathStroke || ''); const fillColor = useToken('colors', fill || ''); if (!Component) { return null; } return ( ); }; const getDefaultIcon = (ref: any) => { return ( ); }; export default React.memo(React.forwardRef(SVGIcon));