lbry-desktop/ui/component/common/icon.jsx

86 lines
2.1 KiB
React
Raw Permalink Normal View History

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';
2019-04-01 01:04:01 +02:00
import classnames from 'classnames';
import { icons } from './icon-custom';
2018-03-26 23:32:43 +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';
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,
tooltip?: boolean,
2020-01-20 17:47:03 +01:00
customTooltipText?: string,
iconColor?: string,
2018-10-09 17:01:54 +02:00
size?: number,
2019-04-01 01:04:01 +02:00
className?: string,
2019-09-26 18:07:11 +02:00
sectionIcon?: boolean,
2018-03-26 23:32:43 +02:00
};
class IconComponent extends React.PureComponent<Props> {
getTooltip = (icon: string) => {
switch (icon) {
case ICONS.REWARDS:
return __('Featured content. Earn rewards for watching.');
2019-05-13 08:05:38 +02:00
case ICONS.DOWNLOAD:
2019-08-14 20:09:45 +02:00
return __('This file is in your library.');
2019-06-28 09:33:07 +02:00
case ICONS.SUBSCRIBE:
return __('You are subscribed to this channel.');
case ICONS.SETTINGS:
return __('Your settings.');
default:
return null;
}
};
getIconColor = (color: string) => {
switch (color) {
case 'red':
return RED_COLOR;
case 'green':
return GREEN_COLOR;
2018-09-12 18:42:15 +02:00
case 'blue':
return BLUE_COLOR;
default:
return color;
}
};
2018-03-26 23:32:43 +02:00
render() {
2020-09-30 20:46:17 +02:00
const { icon, tooltip, customTooltipText, iconColor, size, className, sectionIcon = false, ...rest } = this.props;
const Icon = icons[this.props.icon];
2019-03-27 05:40:02 +01:00
if (!Icon) {
return null;
}
2018-03-26 23:32:43 +02:00
let color;
if (iconColor) {
color = this.getIconColor(iconColor);
2018-03-26 23:32:43 +02:00
}
let tooltipText;
if (tooltip) {
2020-01-20 17:47:03 +01:00
tooltipText = customTooltipText || this.getTooltip(icon);
}
2019-09-26 18:07:11 +02:00
const component = (
<Icon
title={tooltipText}
size={size || (sectionIcon ? 20 : 16)}
wip wip wip - everything but publish, autoplay, and styling collection publishing add channel to collection publish cleanup wip bump clear mass add after success move collection item management controls redirect replace to published collection id bump playlist selector on create bump use new collection add ui element bump wip gitignore add content json wip bump context add to playlist basic collections page style pass wip wip: edits, buttons, styles... change fileAuthor to claimAuthor update, pending bugfixes, delete modal progress, collection header, other bugfixes bump cleaning show page bugfix builtin collection headers no playlists, no grid title wip style tweaks use normal looking claim previews for collection tiles add collection changes style library previews collection menulist for delete/view on library delete modal works for unpublished rearrange collection publish tabs clean up collection publishing and items show on odysee begin collectoin edit header and css renaming better thumbnails bump fix collection publish redirect view collection in menu does something copy and thumbs list previews, pending, context menus, list page enter to add collection, lists page empty state playable lists only, delete feature, bump put fileListDownloaded back better collection titles improve collection claim details fix horiz more icon fix up channel page style, copy, bump refactor preview overlay properties, fix reposts showing as floppydisk add watch later toast, small overlay properties on wunderbar results, fix collection actions buttons bump cleanup cleaning, refactoring bump preview thumb styling, cleanup support discover page lists search sync, bump bump, fix sync more enforce builtin order for now new lists page empty state try to indicate unpublished edits in lists bump fix autoplay and linting consts, fix autoplay bugs fixes cleanup fix, bump lists experimental ui, fixes refactor listIndex out hack in collection fallback thumb bump
2021-02-06 08:03:51 +01:00
className={classnames(`icon icon--${icon}`, className, { 'color-override': iconColor })}
color={color}
aria-hidden
2020-09-30 20:46:17 +02:00
{...rest}
/>
2019-09-26 18:07:11 +02:00
);
return sectionIcon ? <span className={`icon__wrapper icon__wrapper--${icon}`}>{component}</span> : component;
2018-03-26 23:32:43 +02:00
}
}
export default IconComponent;