1- import React from 'react' ;
1+ import React , { useRef , useEffect } from 'react' ;
22import PropTypes from 'prop-types' ;
33
4- const getIframeStyle = ( src , fitToSize ) => {
5- let style = { border : 'none' , height : '100%' , width : '100%' } ;
6-
7- if ( ! fitToSize ) return style ;
8-
9- const parser = new DOMParser ( ) ;
10- const doc = parser . parseFromString ( src , 'image/svg+xml' ) ;
11- const svg = doc . querySelector ( 'svg' ) ;
12-
13- if ( ! svg ) return style ;
14-
15- const width = svg . getAttribute ( 'width' ) || ( svg . viewBox ?. baseVal ?. width ?? null ) ;
16- const height = svg . getAttribute ( 'height' ) || ( svg . viewBox ?. baseVal ?. height ?? null ) ;
17-
18- if ( ! width || ! height ) return style ;
19-
20- style = { ...style , width : `${ width } px` , height : `${ height } px` } ;
21- return style ;
22- } ;
23-
24- const InlineSVG = ( { src, fitToSize = false , ...otherProps } ) => {
25- const iframeStyle = getIframeStyle ( src , fitToSize ) ;
4+ const InlineSVG = ( { src, ...otherProps } ) => {
265 return (
276 < div
287 // eslint-disable-next-line react/no-danger
@@ -34,11 +13,6 @@ const InlineSVG = ({ src, fitToSize = false, ...otherProps }) => {
3413
3514InlineSVG . propTypes = {
3615 src : PropTypes . string . isRequired ,
37- fitToSize : PropTypes . bool ,
38- } ;
39-
40- InlineSVG . defaultProps = {
41- fitToSize : false ,
4216} ;
4317
4418export default InlineSVG ;
0 commit comments