[MM-27420] Add enlarged emojis to tooltips for custom statuses (#27478)

This commit is contained in:
Michael 2024-08-02 07:34:35 +01:00 committed by GitHub
parent 6956923b6a
commit f7ef0ffbc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 27 deletions

View File

@ -270,8 +270,9 @@
display: inline-block;
&-expiry {
color: rgba(255, 255, 255, 0.72);
font-size: 11px;
font-weight: 400;
opacity: 0.7;
}
}
}

View File

@ -1,20 +1,17 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useMemo, memo} from 'react';
import React, {memo, useEffect, useMemo, useRef, useState} from 'react';
import {useSelector} from 'react-redux';
import {CustomStatusDuration} from '@mattermost/types/users';
import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone';
import {makeGetCustomStatus, isCustomStatusEnabled, isCustomStatusExpired} from 'selectors/views/custom_status';
import {isCustomStatusEnabled, isCustomStatusExpired, makeGetCustomStatus} from 'selectors/views/custom_status';
import RenderEmoji from 'components/emoji/render_emoji';
import OverlayTrigger from 'components/overlay_trigger';
import Tooltip from 'components/tooltip';
import Constants from 'utils/constants';
import WithTooltip from 'components/with_tooltip';
import type {GlobalState} from 'types/store';
@ -33,10 +30,10 @@ interface Props {
function CustomStatusEmoji({
emojiSize = 16,
showTooltip = false,
tooltipDirection = 'top',
spanStyle = {},
emojiStyle = {
marginLeft: 4,
marginTop: -1,
},
userID = '',
onClick,
@ -48,6 +45,37 @@ function CustomStatusEmoji({
const customStatusExpired = useSelector((state: GlobalState) => isCustomStatusExpired(state, customStatus));
const customStatusEnabled = useSelector(isCustomStatusEnabled);
const [placement, setPlacement] = useState('bottom');
const emojiRef = useRef<HTMLSpanElement>(null);
useEffect(() => {
function handleMouseEnter() {
if (emojiRef.current) {
const boundingRect = emojiRef.current.getBoundingClientRect();
const windowHeight = window.innerHeight;
const threshold = windowHeight * 0.8;
if (boundingRect.bottom >= threshold) {
setPlacement('top');
} else {
setPlacement('bottom');
}
}
}
const emojiElement = emojiRef.current;
if (emojiElement) {
emojiElement.addEventListener('mouseenter', handleMouseEnter);
}
return () => {
if (emojiElement) {
emojiElement.removeEventListener('mouseenter', handleMouseEnter);
}
};
}, []);
if (!customStatusEnabled || !customStatus?.emoji || customStatusExpired) {
return null;
}
@ -66,29 +94,21 @@ function CustomStatusEmoji({
}
return (
<OverlayTrigger
delayShow={Constants.OVERLAY_TIME_DELAY}
placement={tooltipDirection}
overlay={
<Tooltip id='custom-status-tooltip'>
<WithTooltip
id='custom-status-tooltip'
title={
<>
<div className='custom-status'>
<RenderEmoji
emojiName={customStatus.emoji}
size={14}
emojiStyle={{
marginTop: -1,
}}
/>
{customStatus.text &&
{customStatus.text && (
<span
className='custom-status-text'
style={{marginLeft: 5}}
>
{customStatus.text}
</span>
}
)}
</div>
{customStatus.expires_at && customStatus.duration !== CustomStatusDuration.DONT_CLEAR &&
{customStatus.expires_at && customStatus.duration !== CustomStatusDuration.DONT_CLEAR && (
<div>
<ExpiryTime
time={customStatus.expires_at}
@ -96,14 +116,20 @@ function CustomStatusEmoji({
className='custom-status-expiry'
/>
</div>
)}
</>
}
</Tooltip>
}
emoji={customStatus.emoji}
emojiStyle='large'
placement={placement}
>
<span
ref={emojiRef}
style={spanStyle}
>
<span style={spanStyle}>
{statusEmoji}
</span>
</OverlayTrigger>
</WithTooltip>
);
}