[MM-60166] Migrate tooltips of "components/channel_header/channel_header_title_favorite.tsx" to WithTooltip (#27980)
Этот коммит содержится в:
@@ -2,17 +2,14 @@
|
|||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, {memo, useRef, useCallback} from 'react';
|
import React, {memo, useCallback} from 'react';
|
||||||
import {FormattedMessage, useIntl} from 'react-intl';
|
import {FormattedMessage, useIntl} from 'react-intl';
|
||||||
import {useSelector, useDispatch} from 'react-redux';
|
import {useSelector, useDispatch} from 'react-redux';
|
||||||
|
|
||||||
import {favoriteChannel, unfavoriteChannel} from 'mattermost-redux/actions/channels';
|
import {favoriteChannel, unfavoriteChannel} from 'mattermost-redux/actions/channels';
|
||||||
import {getCurrentChannel, isCurrentChannelFavorite} from 'mattermost-redux/selectors/entities/channels';
|
import {getCurrentChannel, isCurrentChannelFavorite} from 'mattermost-redux/selectors/entities/channels';
|
||||||
|
|
||||||
import OverlayTrigger from 'components/overlay_trigger';
|
import WithTooltip from 'components/with_tooltip';
|
||||||
import Tooltip from 'components/tooltip';
|
|
||||||
|
|
||||||
import {Constants} from 'utils/constants';
|
|
||||||
|
|
||||||
const ChannelHeaderTitleFavorite = () => {
|
const ChannelHeaderTitleFavorite = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
@@ -20,7 +17,6 @@ const ChannelHeaderTitleFavorite = () => {
|
|||||||
const isFavorite = useSelector(isCurrentChannelFavorite);
|
const isFavorite = useSelector(isCurrentChannelFavorite);
|
||||||
const channel = useSelector(getCurrentChannel);
|
const channel = useSelector(getCurrentChannel);
|
||||||
const channelIsArchived = (channel?.delete_at ?? 0) > 0;
|
const channelIsArchived = (channel?.delete_at ?? 0) > 0;
|
||||||
const toggleFavoriteRef = useRef<HTMLButtonElement>(null);
|
|
||||||
|
|
||||||
const toggleFavoriteCallback = useCallback((e: React.MouseEvent<HTMLButtonElement>) => {
|
const toggleFavoriteCallback = useCallback((e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -34,11 +30,6 @@ const ChannelHeaderTitleFavorite = () => {
|
|||||||
}
|
}
|
||||||
}, [isFavorite, channel?.id]);
|
}, [isFavorite, channel?.id]);
|
||||||
|
|
||||||
const removeTooltipLink = useCallback(() => {
|
|
||||||
// Bootstrap adds the attr dynamically, removing it to prevent a11y readout
|
|
||||||
toggleFavoriteRef.current?.removeAttribute('aria-describedby');
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!channel || channelIsArchived) {
|
if (!channel || channelIsArchived) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -49,8 +40,8 @@ const ChannelHeaderTitleFavorite = () => {
|
|||||||
}
|
}
|
||||||
ariaLabel = ariaLabel.toLowerCase();
|
ariaLabel = ariaLabel.toLowerCase();
|
||||||
|
|
||||||
const toggleFavoriteTooltip = (
|
const title = (
|
||||||
<Tooltip id='favoriteTooltip' >
|
<>
|
||||||
{!isFavorite &&
|
{!isFavorite &&
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='channelHeader.addToFavorites'
|
id='channelHeader.addToFavorites'
|
||||||
@@ -61,27 +52,25 @@ const ChannelHeaderTitleFavorite = () => {
|
|||||||
id='channelHeader.removeFromFavorites'
|
id='channelHeader.removeFromFavorites'
|
||||||
defaultMessage='Remove from Favorites'
|
defaultMessage='Remove from Favorites'
|
||||||
/>}
|
/>}
|
||||||
</Tooltip>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OverlayTrigger
|
<WithTooltip
|
||||||
key={`isFavorite-${isFavorite}`}
|
key={`isFavorite-${isFavorite}`}
|
||||||
delayShow={Constants.OVERLAY_TIME_DELAY}
|
id='favoriteTooltip'
|
||||||
|
title={title}
|
||||||
placement='bottom'
|
placement='bottom'
|
||||||
overlay={toggleFavoriteTooltip}
|
|
||||||
onEntering={removeTooltipLink}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
id='toggleFavorite'
|
id='toggleFavorite'
|
||||||
ref={toggleFavoriteRef}
|
|
||||||
onClick={toggleFavoriteCallback}
|
onClick={toggleFavoriteCallback}
|
||||||
className={classNames('channel-header__favorites btn btn-icon btn-xs', {active: isFavorite, inactive: !isFavorite})}
|
className={classNames('channel-header__favorites btn btn-icon btn-xs', {active: isFavorite, inactive: !isFavorite})}
|
||||||
aria-label={ariaLabel}
|
aria-label={ariaLabel}
|
||||||
>
|
>
|
||||||
<i className={classNames('icon', {'icon-star': isFavorite, 'icon-star-outline': !isFavorite})}/>
|
<i className={classNames('icon', {'icon-star': isFavorite, 'icon-star-outline': !isFavorite})}/>
|
||||||
</button>
|
</button>
|
||||||
</OverlayTrigger>
|
</WithTooltip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user