]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/common/Icon.js
add language switcher
[alttp.git] / resources / js / components / common / Icon.js
1 import { library } from '@fortawesome/fontawesome-svg-core';
2 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3 import { fab } from '@fortawesome/free-brands-svg-icons';
4 import { fas } from '@fortawesome/free-solid-svg-icons';
5 import React from 'react';
6 import PropTypes from 'prop-types';
7 import { withTranslation } from 'react-i18next';
8
9 import i18n from '../../i18n';
10
11 library.add(fab);
12 library.add(fas);
13
14 const Icon = ({
15         alt,
16         className,
17         name,
18         size,
19         title,
20 }) =>
21         <FontAwesomeIcon
22                 icon={name}
23                 alt={alt}
24                 className={name === Icon.LOADING ? `${className} fa-spin` : className}
25                 size={size}
26                 title={title}
27         />
28 ;
29
30 Icon.propTypes = {
31         name: PropTypes.oneOfType([
32                 PropTypes.string,
33                 PropTypes.arrayOf(PropTypes.string),
34         ]).isRequired,
35         alt: PropTypes.string,
36         className: PropTypes.string,
37         size: PropTypes.string,
38         title: PropTypes.string,
39 };
40
41 Icon.defaultProps = {
42         alt: null,
43         className: '',
44         size: null,
45         title: null,
46 };
47
48 const makePreset = (presetDisplayName, presetName) => {
49         const preset = ({ alt, className, name, size, title}) => <Icon
50                 alt={alt || i18n.t(`icon.${presetDisplayName}`)}
51                 className={className}
52                 name={name || presetName}
53                 size={size}
54                 title={title !== '' ? title || alt || i18n.t(`icon.${presetDisplayName}`) : null}
55         />;
56         preset.displayName = presetDisplayName;
57         return withTranslation()(preset);
58 };
59
60 Icon.DISCORD = makePreset('DiscordIcon', ['fab', 'discord']);
61 Icon.EDIT = makePreset('EditIcon', 'edit');
62 Icon.FINISHED = makePreset('FinishedIcon', 'square-check');
63 Icon.FIRST_PLACE = makePreset('FirstPlaceIcon', 'trophy');
64 Icon.FORFEIT = makePreset('ForfeitIcon', 'square-xmark');
65 Icon.LANGUAGE = makePreset('LanguageIcon', 'language');
66 Icon.LOGOUT = makePreset('LogoutIcon', 'sign-out-alt');
67 Icon.PENDING = makePreset('PendingIcon', 'clock');
68 Icon.PROTOCOL = makePreset('ProtocolIcon', 'file-alt');
69 Icon.SECOND_PLACE = makePreset('SecondPlaceIcon', 'medal');
70 Icon.THIRD_PLACE = makePreset('ThirdPlaceIcon', 'award');
71
72 export default Icon;