2019-06-20 19:37:28 +07:00
|
|
|
import React, { MouseEvent } from 'react';
|
2019-02-03 17:23:33 +07:00
|
|
|
import capitalize from 'lodash/capitalize';
|
2019-06-25 05:54:32 +07:00
|
|
|
import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
import { Svg, Img, ImgWrapper } from './styles';
|
|
|
|
|
|
|
|
import brazil from './img/brazil.svg';
|
|
|
|
import china from './img/china.svg';
|
|
|
|
import india from './img/india.svg';
|
|
|
|
import nicaragua from './img/nicaragua.svg';
|
|
|
|
import pakistan from './img/pakistan.svg';
|
|
|
|
import austria from './img/austria.svg';
|
|
|
|
import spain from './img/spain.svg';
|
|
|
|
import earth from './img/earth.svg';
|
|
|
|
import verdaccio from './img/verdaccio.svg';
|
2019-03-28 05:39:06 +07:00
|
|
|
import filebinary from './img/filebinary.svg';
|
|
|
|
import law from './img/law.svg';
|
2019-02-03 17:23:33 +07:00
|
|
|
import license from './img/license.svg';
|
|
|
|
import time from './img/time.svg';
|
2019-03-28 05:39:06 +07:00
|
|
|
import version from './img/version.svg';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
export interface IconsMap {
|
|
|
|
brazil: string;
|
|
|
|
spain: string;
|
|
|
|
china: string;
|
|
|
|
nicaragua: string;
|
|
|
|
pakistan: string;
|
|
|
|
austria: string;
|
|
|
|
india: string;
|
|
|
|
earth: string;
|
|
|
|
verdaccio: string;
|
|
|
|
license: string;
|
|
|
|
time: string;
|
|
|
|
law: string;
|
|
|
|
version: string;
|
|
|
|
filebinary: string;
|
|
|
|
[key: string]: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Icons: IconsMap = {
|
2019-02-03 17:23:33 +07:00
|
|
|
brazil,
|
|
|
|
spain,
|
|
|
|
china,
|
|
|
|
nicaragua,
|
|
|
|
pakistan,
|
|
|
|
india,
|
|
|
|
austria,
|
|
|
|
earth,
|
|
|
|
verdaccio,
|
2019-03-28 05:39:06 +07:00
|
|
|
filebinary,
|
|
|
|
law,
|
2019-02-03 17:23:33 +07:00
|
|
|
license,
|
|
|
|
time,
|
2019-03-28 05:39:06 +07:00
|
|
|
version,
|
2019-02-03 17:23:33 +07:00
|
|
|
};
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
export interface Props {
|
|
|
|
name: keyof IconsMap;
|
|
|
|
className?: string;
|
|
|
|
onClick?: (event: MouseEvent<SVGElement | HTMLSpanElement>) => void;
|
2019-06-25 05:54:32 +07:00
|
|
|
size?: Breakpoint;
|
2019-06-20 19:37:28 +07:00
|
|
|
pointer?: boolean;
|
|
|
|
img?: boolean;
|
2019-06-26 06:10:15 +07:00
|
|
|
modifiers?: null | undefined;
|
2019-06-20 19:37:28 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
const Icon: React.FC<Props> = ({ className, name, size = 'sm', img = false, pointer = false, ...props }) => {
|
|
|
|
// @ts-ignore
|
2019-02-03 17:23:33 +07:00
|
|
|
const title = capitalize(name);
|
|
|
|
return img ? (
|
2019-06-26 05:29:53 +07:00
|
|
|
<ImgWrapper className={className} name={name} pointer={pointer} size={size} title={title} {...props}>
|
2019-02-03 17:23:33 +07:00
|
|
|
<Img alt={title} src={Icons[name]} />
|
|
|
|
</ImgWrapper>
|
|
|
|
) : (
|
2019-06-20 19:37:28 +07:00
|
|
|
// @ts-ignore
|
2019-02-03 17:23:33 +07:00
|
|
|
<Svg className={className} pointer={pointer} size={size} {...props}>
|
|
|
|
<title>{title}</title>
|
|
|
|
<use xlinkHref={`${Icons[name]}#${name}`} />
|
|
|
|
</Svg>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Icon;
|