signal-desktop/ts/components/CallingButton.tsx

153 lines
5.2 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useMemo } from 'react';
2020-10-08 01:25:33 +00:00
import classNames from 'classnames';
import { v4 as uuid } from 'uuid';
import type { TooltipPlacement } from './Tooltip';
import { Tooltip } from './Tooltip';
import { Theme } from '../util/theme';
import type { LocalizerType } from '../types/Util';
2020-10-08 01:25:33 +00:00
export enum CallingButtonType {
AUDIO_DISABLED = 'AUDIO_DISABLED',
2020-10-08 01:25:33 +00:00
AUDIO_OFF = 'AUDIO_OFF',
AUDIO_ON = 'AUDIO_ON',
PRESENTING_DISABLED = 'PRESENTING_DISABLED',
PRESENTING_OFF = 'PRESENTING_OFF',
PRESENTING_ON = 'PRESENTING_ON',
RAISE_HAND_OFF = 'RAISE_HAND_OFF',
RAISE_HAND_ON = 'RAISE_HAND_ON',
REACT_OFF = 'REACT_OFF',
REACT_ON = 'REACT_ON',
RING_DISABLED = 'RING_DISABLED',
RING_OFF = 'RING_OFF',
RING_ON = 'RING_ON',
VIDEO_DISABLED = 'VIDEO_DISABLED',
2020-10-08 01:25:33 +00:00
VIDEO_OFF = 'VIDEO_OFF',
VIDEO_ON = 'VIDEO_ON',
2023-11-16 19:55:35 +00:00
MORE_OPTIONS = 'MORE_OPTIONS',
2020-10-08 01:25:33 +00:00
}
export type PropsType = {
buttonType: CallingButtonType;
i18n: LocalizerType;
isVisible?: boolean;
2020-10-08 01:25:33 +00:00
onClick: () => void;
2021-09-18 00:20:29 +00:00
onMouseEnter?: () => void;
onMouseLeave?: () => void;
2020-11-19 18:11:35 +00:00
tooltipDirection?: TooltipPlacement;
2020-10-08 01:25:33 +00:00
};
2022-11-18 00:45:19 +00:00
export function CallingButton({
2020-10-08 01:25:33 +00:00
buttonType,
i18n,
isVisible = true,
2020-10-08 01:25:33 +00:00
onClick,
2021-09-18 00:20:29 +00:00
onMouseEnter,
onMouseLeave,
2020-11-19 18:11:35 +00:00
tooltipDirection,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
const uniqueButtonId = useMemo(() => uuid(), []);
2020-10-08 01:25:33 +00:00
let classNameSuffix = '';
let tooltipContent = '';
let disabled = false;
if (buttonType === CallingButtonType.AUDIO_DISABLED) {
2020-10-08 01:25:33 +00:00
classNameSuffix = 'audio--disabled';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--audio-disabled');
disabled = true;
} else if (buttonType === CallingButtonType.AUDIO_OFF) {
classNameSuffix = 'audio--off';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--audio-on');
2020-10-08 01:25:33 +00:00
} else if (buttonType === CallingButtonType.AUDIO_ON) {
classNameSuffix = 'audio--on';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--audio-off');
} else if (buttonType === CallingButtonType.VIDEO_DISABLED) {
2020-10-08 01:25:33 +00:00
classNameSuffix = 'video--disabled';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--video-disabled');
disabled = true;
} else if (buttonType === CallingButtonType.VIDEO_OFF) {
classNameSuffix = 'video--off';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--video-on');
2020-10-08 01:25:33 +00:00
} else if (buttonType === CallingButtonType.VIDEO_ON) {
classNameSuffix = 'video--on';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--video-off');
} else if (buttonType === CallingButtonType.RING_DISABLED) {
classNameSuffix = 'ring--disabled';
disabled = true;
tooltipContent = i18n(
2023-03-30 00:03:25 +00:00
'icu:calling__button--ring__disabled-because-group-is-too-large'
);
} else if (buttonType === CallingButtonType.REACT_OFF) {
classNameSuffix = 'react--off';
tooltipContent = i18n('icu:calling__button--react');
} else if (buttonType === CallingButtonType.REACT_ON) {
classNameSuffix = 'react--on';
} else if (buttonType === CallingButtonType.RAISE_HAND_OFF) {
classNameSuffix = 'raise-hand--off';
tooltipContent = i18n('icu:CallControls__MenuItemRaiseHand');
} else if (buttonType === CallingButtonType.RAISE_HAND_ON) {
classNameSuffix = 'raise-hand--on';
tooltipContent = i18n('icu:CallControls__MenuItemRaiseHand--lower');
} else if (buttonType === CallingButtonType.RING_OFF) {
classNameSuffix = 'ring--off';
2023-10-25 13:40:22 +00:00
tooltipContent = i18n('icu:CallingButton--ring-on');
} else if (buttonType === CallingButtonType.RING_ON) {
classNameSuffix = 'ring--on';
2023-10-25 13:40:22 +00:00
tooltipContent = i18n('icu:CallingButton__ring-off');
} else if (buttonType === CallingButtonType.PRESENTING_DISABLED) {
classNameSuffix = 'presenting--disabled';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--presenting-disabled');
disabled = true;
} else if (buttonType === CallingButtonType.PRESENTING_ON) {
classNameSuffix = 'presenting--on';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--presenting-off');
} else if (buttonType === CallingButtonType.PRESENTING_OFF) {
classNameSuffix = 'presenting--off';
2023-03-30 00:03:25 +00:00
tooltipContent = i18n('icu:calling__button--presenting-on');
2023-11-16 19:55:35 +00:00
} else if (buttonType === CallingButtonType.MORE_OPTIONS) {
classNameSuffix = 'more-options';
tooltipContent = i18n('icu:CallingButton--more-options');
2020-10-08 01:25:33 +00:00
}
const buttonContent = (
<button
aria-label={tooltipContent}
className={classNames(
'CallingButton__icon',
`CallingButton__icon--${classNameSuffix}`
)}
disabled={disabled}
id={uniqueButtonId}
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
type="button"
>
<div />
</button>
);
2020-10-08 01:25:33 +00:00
return (
2023-10-25 13:40:22 +00:00
<div className="CallingButton">
{tooltipContent === '' ? (
<div className="CallingButton__button-container">{buttonContent}</div>
) : (
<Tooltip
className="CallingButton__tooltip"
wrapperClassName={classNames(
'CallingButton__button-container',
!isVisible && 'CallingButton__button-container--hidden'
2023-10-25 13:40:22 +00:00
)}
content={tooltipContent}
direction={tooltipDirection}
theme={Theme.Dark}
>
{buttonContent}
</Tooltip>
)}
2023-10-25 13:40:22 +00:00
</div>
2020-10-08 01:25:33 +00:00
);
2022-11-18 00:45:19 +00:00
}