2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import * as FeatherIcons from 'react-feather';
|
|
|
|
import * as icons from 'constants/icons';
|
2018-05-23 02:11:20 +02:00
|
|
|
import Tooltip from 'component/common/tooltip';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
const RED_COLOR = '#e2495e';
|
2018-05-21 22:30:00 +02:00
|
|
|
const PURPLE_COLOR = '#8165b0';
|
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-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) {
|
|
|
|
case icons.FEATURED:
|
|
|
|
return __('Featured content. Earn rewards for watching.');
|
|
|
|
case icons.LOCAL:
|
|
|
|
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;
|
|
|
|
case 'purple':
|
|
|
|
return PURPLE_COLOR;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
render() {
|
2018-05-23 05:48:22 +02:00
|
|
|
const { icon, tooltip, iconColor } = 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
|
|
|
}
|
|
|
|
|
|
|
|
let size = 14;
|
|
|
|
if (icon === icons.ARROW_LEFT || icon === icons.ARROW_RIGHT) {
|
2018-05-11 20:15:29 +02:00
|
|
|
size = 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);
|
|
|
|
}
|
|
|
|
const inner = <Icon size={size} className="icon" color={color} />;
|
|
|
|
|
|
|
|
return tooltip ? (
|
|
|
|
<Tooltip icon body={tooltipText} direction={tooltip}>
|
|
|
|
{inner}
|
|
|
|
</Tooltip>
|
|
|
|
) : (
|
|
|
|
inner
|
|
|
|
);
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default IconComponent;
|