Files
Iris/src/js/components/Icon.js

87 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-04-11 08:05:53 +12:00
import React, { memo } from 'react';
2018-05-15 21:30:57 +12:00
import FontAwesome from 'react-fontawesome';
import { sourceIcon } from '../util/helpers';
const Icon = memo(({
name,
type,
className,
onClick,
2021-03-23 21:21:00 +13:00
}) => {
if (!name || name === '') return null;
2019-09-05 15:36:11 +12:00
2020-06-09 21:09:29 +12:00
const fullClassName = `icon icon--${type || 'material'} ${className || ''}`;
2019-09-05 15:36:11 +12:00
switch (type) {
2019-09-05 15:36:11 +12:00
case 'svg':
return (
<span className={fullClassName}>
<img
src={`/iris/assets/icons/${name}.svg`}
onClick={onClick}
alt={`${name} icon`}
/>
</span>
);
2019-09-05 15:36:11 +12:00
case 'gif':
return (
<span className={fullClassName}>
<img
className={fullClassName}
src={`/iris/assets/icons/${name}.gif`}
onClick={onClick}
alt={`${name} icon`}
/>
</span>
);
2019-09-05 15:36:11 +12:00
case 'fontawesome':
return (
<FontAwesome
className={fullClassName}
type="fontawesome"
name={name}
onClick={onClick}
/>
);
2019-09-05 15:36:11 +12:00
case 'css':
if (name === 'playing') {
return (
<i className={`${fullClassName} icon--playing`}>
<span />
<span />
<span />
</i>
);
2019-09-05 15:36:11 +12:00
}
break;
2019-09-05 15:36:11 +12:00
default:
return <i className={fullClassName} onClick={onClick}>{name}</i>;
2019-09-05 15:36:11 +12:00
}
});
const SourceIcon = ({
uri,
...rest
}) => {
const source = sourceIcon(uri);
switch (source) {
case 'genius':
case 'tidal':
return <Icon name={source} type="svg" className="source" {...rest} />;
default:
return <Icon name={source} type="fontawesome" className="source" {...rest} />;
}
};
export default Icon;
export {
Icon,
SourceIcon,
};