import React, { Component } from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import centosIcon from 'asset/image/centos.svg';
import ubuntuIcon from 'asset/image/ubuntu.svg';
import fedoraIcon from 'asset/image/fedora.svg';
import windowsIcon from 'asset/image/windows.svg';
import debianIcon from 'asset/image/debian.svg';
import almalinuxIcon from 'asset/image/almalinux.svg';
import rockyIcon from 'asset/image/rocky.svg';
import redhatIcon from 'asset/image/redhat.svg';
import archIcon from 'asset/image/arch.svg';
import freebsdIcon from 'asset/image/freebsd.svg';
import oraclelinuxIcon from 'asset/image/oraclelinux.svg';
import othersIcon from 'asset/image/others.svg';
import { Tooltip } from 'antd';
import styles from './index.less';
export default class index extends Component {
static propTypes = {
type: PropTypes.string,
className: PropTypes.string,
title: PropTypes.string,
};
static defaultProps = {
className: '',
};
constructor(props) {
super(props);
this.icons = {
centos: centosIcon,
ubuntu: ubuntuIcon,
fedora: fedoraIcon,
windows: windowsIcon,
debian: debianIcon,
almalinux: almalinuxIcon,
rocky: rockyIcon,
rhel: redhatIcon,
oraclelinux: oraclelinuxIcon,
arch: archIcon,
freebsd: freebsdIcon,
others: othersIcon,
};
}
getImageSrc = () => {
const { type } = this.props;
return type ? this.icons[type.toLowerCase()] || othersIcon : othersIcon;
};
render() {
const src = this.getImageSrc();
const { type, className, title } = this.props;
if (title) {
return (
<Tooltip title={title}>
<img
src={src}
alt={title}
className={classnames(styles.image, className)}
/>
</Tooltip>
);
}
return (
<img
src={src}
alt={type}
className={classnames(styles.image, className)}
/>
);
}
}