2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2018-11-26 02:21:25 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2018-03-26 23:32:43 +02:00
|
|
|
import React from 'react';
|
|
|
|
import * as FeatherIcons from 'react-feather';
|
2018-05-23 02:11:20 +02:00
|
|
|
import Tooltip from 'component/common/tooltip';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2018-06-25 08:28:03 +02:00
|
|
|
// It would be nice to standardize this somehow
|
|
|
|
// These are copied from `scss/vars`, can they both come from the same source?
|
2018-03-26 23:32:43 +02:00
|
|
|
const RED_COLOR = '#e2495e';
|
2018-06-25 08:28:03 +02:00
|
|
|
const GREEN_COLOR = '#44b098';
|
2018-09-12 18:42:15 +02:00
|
|
|
const BLUE_COLOR = '#49b2e2';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
icon: string,
|
2018-05-23 05:48:22 +02:00
|
|
|
tooltip?: string, // tooltip direction
|
|
|
|
iconColor?: string,
|
2018-10-09 17:01:54 +02:00
|
|
|
size?: number,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class IconComponent extends React.PureComponent<Props> {
|
2018-05-23 02:11:20 +02:00
|
|
|
getTooltip = (icon: string) => {
|
|
|
|
switch (icon) {
|
2018-11-26 02:21:25 +01:00
|
|
|
case ICONS.FEATURED:
|
2018-05-23 02:11:20 +02:00
|
|
|
return __('Featured content. Earn rewards for watching.');
|
2018-11-26 02:21:25 +01:00
|
|
|
case ICONS.LOCAL:
|
2018-05-23 02:11:20 +02:00
|
|
|
return __('This file is downloaded.');
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
2018-05-23 05:48:22 +02:00
|
|
|
|
|
|
|
getIconColor = (color: string) => {
|
|
|
|
switch (color) {
|
|
|
|
case 'red':
|
|
|
|
return RED_COLOR;
|
2018-06-25 08:28:03 +02:00
|
|
|
case 'green':
|
|
|
|
return GREEN_COLOR;
|
2018-09-12 18:42:15 +02:00
|
|
|
case 'blue':
|
|
|
|
return BLUE_COLOR;
|
2018-05-23 05:48:22 +02:00
|
|
|
default:
|
2018-06-25 08:28:03 +02:00
|
|
|
return undefined;
|
2018-05-23 05:48:22 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
render() {
|
2018-10-09 17:01:54 +02:00
|
|
|
const { icon, tooltip, iconColor, size } = this.props;
|
2018-03-26 23:32:43 +02:00
|
|
|
const Icon = FeatherIcons[icon];
|
|
|
|
|
2018-05-23 02:11:20 +02:00
|
|
|
if (!Icon) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
let color;
|
2018-05-23 05:48:22 +02:00
|
|
|
if (iconColor) {
|
|
|
|
color = this.getIconColor(iconColor);
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 17:01:54 +02:00
|
|
|
let iconSize = size || 14;
|
2018-11-26 02:21:25 +01:00
|
|
|
// Arrow ICONS are quite a bit smaller than the other ICONS we use
|
|
|
|
if (icon === ICONS.ARROW_LEFT || icon === ICONS.ARROW_RIGHT) {
|
2018-10-09 17:01:54 +02:00
|
|
|
iconSize = 20;
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 02:11:20 +02:00
|
|
|
let tooltipText;
|
|
|
|
if (tooltip) {
|
|
|
|
tooltipText = this.getTooltip(icon);
|
|
|
|
}
|
2018-10-09 17:01:54 +02:00
|
|
|
const inner = <Icon size={iconSize} className="icon" color={color} />;
|
2018-05-23 02:11:20 +02:00
|
|
|
|
2018-06-21 00:15:57 +02:00
|
|
|
return tooltipText ? (
|
2018-05-23 02:11:20 +02:00
|
|
|
<Tooltip icon body={tooltipText} direction={tooltip}>
|
|
|
|
{inner}
|
|
|
|
</Tooltip>
|
|
|
|
) : (
|
|
|
|
inner
|
|
|
|
);
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default IconComponent;
|