From 93384f91f585d898fae9fd5591411128e2d4bac7 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 25 Jun 2019 18:15:03 +0100 Subject: [PATCH] Show reaction title and shortcode on hover This shows the title and shortcode for the hovered reaction at the bottom of the tooltip. If nothing is hovered, a blank space is shown for now, but will eventually become a link to a full emoji picker in future work. Part of https://github.com/vector-im/riot-web/issues/9753 --- .../views/messages/_ReactionQuickTooltip.scss | 11 +++- .../views/messages/ReactionTooltipButton.js | 1 + .../views/messages/ReactionsQuickTooltip.js | 60 ++++++++++++++++--- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/res/css/views/messages/_ReactionQuickTooltip.scss b/res/css/views/messages/_ReactionQuickTooltip.scss index 5fb7987b6f..7b1611483b 100644 --- a/res/css/views/messages/_ReactionQuickTooltip.scss +++ b/res/css/views/messages/_ReactionQuickTooltip.scss @@ -14,7 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -.mx_ReactionsQuickTooltip { +.mx_ReactionsQuickTooltip_buttons { display: grid; grid-template-columns: repeat(4, auto); } + +.mx_ReactionsQuickTooltip_label { + text-align: center; +} + +.mx_ReactionsQuickTooltip_shortcode { + padding-left: 6px; + opacity: 0.7; +} diff --git a/src/components/views/messages/ReactionTooltipButton.js b/src/components/views/messages/ReactionTooltipButton.js index a3f0256758..e09b9ade69 100644 --- a/src/components/views/messages/ReactionTooltipButton.js +++ b/src/components/views/messages/ReactionTooltipButton.js @@ -57,6 +57,7 @@ export default class ReactionTooltipButton extends React.PureComponent { }); return { + const { key } = ev.target.dataset; + const item = this.items.find(({ content }) => content === key); + this.setState({ + hoveredItem: item, + }); + } - const items = [ + onMouseOut = (ev) => { + this.setState({ + hoveredItem: null, + }); + } + + get items() { + return [ { content: "👍", title: _t("Agree"), @@ -126,8 +138,14 @@ export default class ReactionsQuickTooltip extends React.PureComponent { title: _t("Eyes"), }, ]; + } - const buttons = items.map(({ content, title }) => { + render() { + const { mxEvent } = this.props; + const { myReactions, hoveredItem } = this.state; + const ReactionTooltipButton = sdk.getComponent('messages.ReactionTooltipButton'); + + const buttons = this.items.map(({ content, title }) => { const myReactionEvent = myReactions && myReactions.find(mxEvent => { if (mxEvent.isRedacted()) { return false; @@ -144,8 +162,34 @@ export default class ReactionsQuickTooltip extends React.PureComponent { />; }); - return
- {buttons} + let label = " "; // non-breaking space to keep layout the same when empty + if (hoveredItem) { + const { content, title } = hoveredItem; + + let shortcodeLabel; + const shortcode = unicodeToShortcode(content); + if (shortcode) { + shortcodeLabel = + {shortcode} + ; + } + + label =
+ + {title} + + {shortcodeLabel} +
; + } + + return
+
+ {buttons} +
+ {label}
; } }