BetterDiscordApp-rauenzi/renderer/src/ui/emote.js

82 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-06-25 22:36:34 +02:00
import {Settings, React, WebpackModules, Events, Strings} from "modules";
2019-05-28 23:27:25 +02:00
2020-02-28 01:00:12 +01:00
const TooltipWrapper = WebpackModules.getByDisplayName("Tooltip");
2019-06-19 05:09:49 +02:00
export default class BDEmote extends React.Component {
2019-05-28 20:19:48 +02:00
constructor(props) {
super(props);
this.state = {
shouldAnimate: !this.animateOnHover,
2019-06-24 21:47:24 +02:00
isFavorite: this.props.isFavorite
2019-05-28 20:19:48 +02:00
};
this.onMouseEnter = this.onMouseEnter.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
this.onClick = this.onClick.bind(this);
2019-06-25 22:36:34 +02:00
this.toggleFavorite = this.toggleFavorite.bind(this);
2019-05-28 20:19:48 +02:00
}
get animateOnHover() {
2019-06-08 08:35:43 +02:00
return Settings.get("emotes", "general", "animateOnHover");
2019-05-28 20:19:48 +02:00
}
get label() {
return this.props.modifier ? `${this.props.name}:${this.props.modifier}` : this.props.name;
}
get modifierClass() {
return this.props.modifier ? ` emote${this.props.modifier}` : "";
}
onMouseEnter() {
if (!this.state.shouldAnimate && this.animateOnHover) this.setState({shouldAnimate: true});
}
onMouseLeave() {
if (this.state.shouldAnimate && this.animateOnHover) this.setState({shouldAnimate: false});
}
onClick(e) {
if (this.props.onClick) this.props.onClick(e);
}
2019-06-25 22:36:34 +02:00
toggleFavorite(e) {
e.preventDefault();
e.stopPropagation();
if (this.state.isFavorite) Events.emit("emotes-favorite-removed", this.label);
else Events.emit("emotes-favorite-added", this.label, this.props.url);
this.setState({isFavorite: !this.state.isFavorite});
}
2019-05-28 20:19:48 +02:00
render() {
return React.createElement(TooltipWrapper, {
color: "primary",
2019-05-28 20:19:48 +02:00
position: "top",
text: this.label,
delay: 750
},
2020-02-28 01:00:12 +01:00
(childProps) => {
return React.createElement("div", Object.assign({
2019-05-28 20:19:48 +02:00
className: "emotewrapper" + (this.props.jumboable ? " jumboable" : ""),
onMouseEnter: this.onMouseEnter,
onMouseLeave: this.onMouseLeave,
onClick: this.onClick
2020-02-28 01:00:12 +01:00
}, childProps),
2019-06-19 05:09:49 +02:00
React.createElement("img", {
2019-05-28 20:19:48 +02:00
draggable: false,
className: "emote" + this.modifierClass + (this.props.jumboable ? " jumboable" : "") + (!this.state.shouldAnimate ? " stop-animation" : ""),
dataModifier: this.props.modifier,
alt: this.label,
src: this.props.url
}),
2019-06-19 05:09:49 +02:00
React.createElement("input", {
2019-05-28 20:19:48 +02:00
className: "fav" + (this.state.isFavorite ? " active" : ""),
2019-06-25 22:36:34 +02:00
title: Strings.Emotes.favoriteAction,
2019-05-28 20:19:48 +02:00
type: "button",
2019-06-25 22:36:34 +02:00
onClick: this.toggleFavorite
2019-05-28 20:19:48 +02:00
})
2020-02-28 01:00:12 +01:00
);
});
2019-05-28 20:19:48 +02:00
}
}