1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { useTranslation } from 'react-i18next';
5 import Icon from './Icon';
91 const isOnItemMap = name => ITEM_MAP.includes(name);
93 const getItemMapStyle = name => {
94 const index = ITEM_MAP.indexOf(name);
96 const y = Math.floor(index / 8);
97 return { backgroundPosition: `-${x * 100}% -${y * 100}%` };
100 const getIconURL = name => {
115 return `/dungeon/${name.substr(8)}.png`;
116 case 'crystal-switch':
117 case 'crystal-switch-blue':
118 case 'crystal-switch-red':
119 return `/icon/${name}.png`;
125 const ZeldaIcon = ({ name, title }) => {
126 const { t } = useTranslation();
128 const invert = name.startsWith('not-');
129 const strippedName = invert ? name.substr(4) : name;
130 const src = getIconURL(strippedName);
131 const alt = t(`icon.zelda.${name}`);
132 const realTitle = title !== '' ? title || alt : null;
134 return <span className="zelda-icon">
135 {isOnItemMap(strippedName) ?
137 className="item-map-icon"
138 style={getItemMapStyle(strippedName)}
150 <span className="strike">
151 <Icon.SLASH title="" />
157 ZeldaIcon.propTypes = {
158 name: PropTypes.string.isRequired,
159 title: PropTypes.string,
162 export default ZeldaIcon;