@@ -15,11 +15,12 @@ export interface SvgImageProps {
15
15
style ?: object [ ] ;
16
16
height ?: number ;
17
17
width ?: number ;
18
+ id ?: string ;
18
19
}
19
20
20
21
function SvgImage ( props : SvgImageProps ) {
21
22
const { data, style = [ ] , tintColor, width, height, ...others } = props ;
22
- const [ id ] = useState ( `svg-${ new Date ( ) . getTime ( ) . toString ( ) } ` ) ;
23
+ const [ className ] = useState ( `svg-${ new Date ( ) . getTime ( ) . toString ( ) } ` ) ;
23
24
const [ svgStyleCss , setSvgStyleCss ] = useState < string | undefined > ( undefined ) ;
24
25
25
26
useEffect ( ( ) => {
@@ -29,11 +30,11 @@ function SvgImage(props: SvgImageProps) {
29
30
postcss ( )
30
31
. process ( { width, height, ...styleObj } , { parser : cssjs } )
31
32
. then ( ( style : { css : any } ) => {
32
- const svgPathCss = ( styleObj ?. tintColor ) ? `# ${ id } svg path {fill: ${ styleObj ?. tintColor } }` : '' ;
33
- setSvgStyleCss ( `# ${ id } svg { ${ style . css } } # ${ id } {${ style . css } } ${ svgPathCss } }` ) ;
33
+ const svgPathCss = styleObj ?. tintColor ? `. ${ className } > svg path {fill: ${ styleObj ?. tintColor } }` : '' ;
34
+ setSvgStyleCss ( `. ${ className } > svg {${ style . css } } ${ svgPathCss } }` ) ;
34
35
} ) ;
35
36
}
36
- } , [ style , id , width , height ] ) ;
37
+ } , [ style , className , width , height ] ) ;
37
38
38
39
if ( isSvgUri ( data ) ) {
39
40
return < img { ...others } src = { data . uri } style = { StyleSheet . flatten ( style ) } /> ;
@@ -53,9 +54,9 @@ function SvgImage(props: SvgImageProps) {
53
54
} else if ( data && svgStyleCss ) {
54
55
const svgStyleTag = `<style> ${ svgStyleCss } </style>` ;
55
56
return (
56
- < div
57
- id = { id }
57
+ < div
58
58
{ ...others }
59
+ className = { className }
59
60
// eslint-disable-next-line react/no-danger
60
61
dangerouslySetInnerHTML = { { __html : svgStyleTag + data } }
61
62
/>
0 commit comments