import PropTypes from 'prop-types';
import React from 'react';
-import { withTranslation } from 'react-i18next';
+import { useTranslation } from 'react-i18next';
-import i18n from '../../i18n';
+import Icon from './Icon';
const getIconURL = name => {
switch (name) {
case 'ether':
case 'fairy':
case 'fighter-shield':
+ case 'fighter-sword':
case 'fire-rod':
case 'fire-shield':
case 'flippers':
case 'small-key':
case 'somaria':
return `/item/${name}.png`;
+ case 'dungeon-ct':
+ case 'dungeon-dp':
+ case 'dungeon-ep':
+ case 'dungeon-gt':
+ case 'dungeon-hc':
+ case 'dungeon-ip':
+ case 'dungeon-mm':
+ case 'dungeon-pd':
+ case 'dungeon-sp':
+ case 'dungeon-sw':
+ case 'dungeon-th':
+ case 'dungeon-tr':
+ case 'dungeon-tt':
+ return `/dungeon/${name.substr(8)}.png`;
+ case 'crystal-switch':
+ case 'crystal-switch-blue':
+ case 'crystal-switch-red':
+ return `/icon/${name}.png`;
default:
return '';
}
};
-const ZeldaIcon = ({ name }) =>
-<span className="zelda-icon">
- <img
- alt={i18n.t(`icon.zelda.${name}`)}
- src={getIconURL(name)}
- title={i18n.t(`icon.zelda.${name}`)}
- />
-</span>;
+const ZeldaIcon = ({ name, title }) => {
+ const { t } = useTranslation();
+
+ const invert = name.startsWith('not-');
+ const strippedName = invert ? name.substr(4) : name;
+ const src = getIconURL(strippedName);
+ const alt = t(`icon.zelda.${name}`);
+ const realTitle = title !== '' ? title || alt : null;
+
+ return <span className="zelda-icon">
+ {src ?
+ <img
+ alt={alt}
+ src={src}
+ title={realTitle}
+ />
+ : null}
+ {invert ?
+ <span className="strike">
+ <Icon.SLASH title="" />
+ </span>
+ : null}
+ </span>;
+};
ZeldaIcon.propTypes = {
name: PropTypes.string,
+ title: PropTypes.string,
};
-export default withTranslation()(ZeldaIcon);
+export default ZeldaIcon;