You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SvgXmlIcon.web.tsx 719B

1234567891011121314151617181920212223242526
  1. import React, { useMemo } from 'react';
  2. /**
  3. * SVG rendering component.
  4. *
  5. * @returns {JSX.Element}
  6. */
  7. const SvgXmlIcon = ({ src, ...rest }: {
  8. src: string;
  9. }): JSX.Element => {
  10. const svgDocument = new DOMParser().parseFromString(src, 'image/svg+xml');
  11. const element = svgDocument.documentElement.outerHTML;
  12. const attributes = useMemo(() => Object.entries(rest).map(
  13. ([ key, value ]) => `${key}="${value}"`)
  14. .join(' '), [ rest ]);
  15. const html = element.replace('<svg', `<svg ${attributes}`);
  16. return (
  17. <div // eslint-disable-next-line react/no-danger
  18. dangerouslySetInnerHTML = {{ __html: html }}
  19. { ...rest } />
  20. );
  21. };
  22. export default SvgXmlIcon;