[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; display: inline-block;
&-expiry { &-expiry {
color: rgba(255, 255, 255, 0.72);
font-size: 11px;
font-weight: 400; font-weight: 400;
opacity: 0.7;
} }
} }
} }

View File

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