aboutsummaryrefslogtreecommitdiff
path: root/modern/src/login/LogoImage.js
blob: d3f4b1ce90008306c41b7f55b8abb59277643664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React, { useRef } from 'react';
import { makeStyles } from '@mui/styles';
import image from '../resources/images/logo.svg';

const useStyles = makeStyles(() => ({
  image: {
    alignSelf: 'center',
    maxWidth: '240px',
    maxHeight: '120px',
    width: 'auto',
    height: 'auto',
    visibility: 'hidden',
  },
}));

const LogoImage = ({ color }) => {
  const classes = useStyles();

  const element = useRef(null);

  return (
    <object
      type="image/svg+xml"
      data={image}
      aria-label="logo"
      className={classes.image}
      ref={element}
      onLoad={() => {
        const imageDocument = element.current.contentDocument;
        imageDocument.querySelectorAll('svg').forEach((element) => {
          const style = imageDocument.createElement('style');
          style.appendChild(imageDocument.createTextNode(`g { color: ${color}; }`));
          element.insertAdjacentElement('afterbegin', style);
          element.innerHTML += '';
        });
        element.current.style.visibility = 'visible';
      }}
    />
  );
};

export default LogoImage;