forked from johreh/gloomycompanion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StatIcon.jsx
50 lines (41 loc) · 1.1 KB
/
StatIcon.jsx
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
43
44
45
46
47
48
49
50
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import * as css from './style/Card.scss';
const REMAP_LUT = {
flying: { invert: true, icon: 'images/fly.svg' },
attack: { invert: true },
heal: { invert: true },
jump: { invert: true },
loot: { invert: true },
move: { invert: true },
pull: { invert: true },
push: { invert: true },
range: { invert: true },
retaliate: { invert: true },
shield: { invert: true },
target: { invert: true },
};
export default function StatIcon(props) {
const parse = /^%?([^%]+)%?$/;
const match = parse.exec(props.name);
const cnames = [props.className];
let img_src = `images/${match[1]}.svg`;
if (REMAP_LUT[match[1]]) {
const entry = REMAP_LUT[match[1]];
if (entry.icon) {
img_src = entry.icon;
}
if (entry.invert) {
cnames.push(css.invertIcon);
}
}
return <img className={classNames(cnames)} src={img_src} alt="" />;
}
StatIcon.defaultProps = {
className: [],
};
StatIcon.propTypes = {
name: PropTypes.string.isRequired,
className: PropTypes.string,
};