2022-05-04 17:09:48 +01:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2022-2024 New Vector Ltd.
|
2026-01-12 15:35:21 +01:00
|
|
|
Copyright 2026 Element Creations Ltd.
|
2022-05-04 17:09:48 +01:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 10:22:13 +02:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2022-05-04 17:09:48 +01:00
|
|
|
*/
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type ComponentPropsWithoutRef, type FC } from "react";
|
2021-12-07 11:59:57 -08:00
|
|
|
import classNames from "classnames";
|
2022-10-10 09:19:10 -04:00
|
|
|
import { useTranslation } from "react-i18next";
|
2026-04-14 17:05:56 +02:00
|
|
|
import {
|
|
|
|
|
Button as CpdButton,
|
|
|
|
|
IconButton,
|
|
|
|
|
Tooltip,
|
|
|
|
|
} from "@vector-im/compound-web";
|
2024-07-25 13:15:45 -04:00
|
|
|
import {
|
|
|
|
|
MicOnSolidIcon,
|
|
|
|
|
MicOffSolidIcon,
|
|
|
|
|
VideoCallSolidIcon,
|
|
|
|
|
VideoCallOffSolidIcon,
|
|
|
|
|
EndCallIcon,
|
|
|
|
|
ShareScreenSolidIcon,
|
2026-04-08 16:05:46 +02:00
|
|
|
OverflowHorizontalIcon,
|
|
|
|
|
OverflowVerticalIcon,
|
2026-04-09 15:49:09 +02:00
|
|
|
VolumeOnSolidIcon,
|
2024-07-25 13:15:45 -04:00
|
|
|
} from "@vector-im/compound-design-tokens/assets/web/icons";
|
2022-06-11 23:21:20 +02:00
|
|
|
|
2021-12-07 11:59:57 -08:00
|
|
|
import styles from "./Button.module.css";
|
2026-04-14 13:25:33 +02:00
|
|
|
import callFooterStyles from "../components/CallFooter.module.css";
|
2026-04-08 16:05:46 +02:00
|
|
|
import { platform } from "../Platform";
|
2021-12-07 11:59:57 -08:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
interface MicButtonProps extends ComponentPropsWithoutRef<"button"> {
|
2026-03-18 11:29:55 +01:00
|
|
|
enabled: boolean;
|
2026-03-09 14:40:13 +01:00
|
|
|
size?: "sm" | "lg";
|
2022-06-11 23:21:20 +02:00
|
|
|
}
|
2023-12-19 11:00:33 -05:00
|
|
|
|
2026-03-18 11:29:55 +01:00
|
|
|
export const MicButton: FC<MicButtonProps> = ({ enabled, ...props }) => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2026-03-18 11:29:55 +01:00
|
|
|
const Icon = enabled ? MicOnSolidIcon : MicOffSolidIcon;
|
|
|
|
|
const label = enabled
|
|
|
|
|
? t("mute_microphone_button_label")
|
|
|
|
|
: t("unmute_microphone_button_label");
|
2022-10-10 09:19:10 -04:00
|
|
|
|
2021-12-07 11:59:57 -08:00
|
|
|
return (
|
2023-09-08 15:39:49 -04:00
|
|
|
<Tooltip label={label}>
|
2024-08-28 08:44:39 -04:00
|
|
|
<CpdButton
|
|
|
|
|
iconOnly
|
|
|
|
|
Icon={Icon}
|
2026-03-18 11:29:55 +01:00
|
|
|
kind={enabled ? "primary" : "secondary"}
|
2026-03-18 15:09:02 +01:00
|
|
|
role="switch"
|
|
|
|
|
aria-checked={enabled}
|
2024-08-28 08:44:39 -04:00
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-08-30 21:58:29 -04:00
|
|
|
</Tooltip>
|
2021-12-07 11:59:57 -08:00
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|
2021-12-07 11:59:57 -08:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
interface VideoButtonProps extends ComponentPropsWithoutRef<"button"> {
|
2026-03-18 11:29:55 +01:00
|
|
|
enabled: boolean;
|
2026-03-09 14:40:13 +01:00
|
|
|
size?: "sm" | "lg";
|
2024-08-28 08:44:39 -04:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 11:29:55 +01:00
|
|
|
export const VideoButton: FC<VideoButtonProps> = ({ enabled, ...props }) => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2026-03-18 11:29:55 +01:00
|
|
|
const Icon = enabled ? VideoCallSolidIcon : VideoCallOffSolidIcon;
|
|
|
|
|
const label = enabled
|
|
|
|
|
? t("stop_video_button_label")
|
|
|
|
|
: t("start_video_button_label");
|
2022-10-10 09:19:10 -04:00
|
|
|
|
2021-12-07 11:59:57 -08:00
|
|
|
return (
|
2023-09-08 15:39:49 -04:00
|
|
|
<Tooltip label={label}>
|
2024-08-28 08:44:39 -04:00
|
|
|
<CpdButton
|
|
|
|
|
iconOnly
|
|
|
|
|
Icon={Icon}
|
2026-03-18 11:29:55 +01:00
|
|
|
kind={enabled ? "primary" : "secondary"}
|
2026-03-18 15:09:02 +01:00
|
|
|
role="switch"
|
|
|
|
|
aria-checked={enabled}
|
2024-08-28 08:44:39 -04:00
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-08-30 21:58:29 -04:00
|
|
|
</Tooltip>
|
2021-12-07 11:59:57 -08:00
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|
2021-12-07 11:59:57 -08:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
interface ShareScreenButtonProps extends ComponentPropsWithoutRef<"button"> {
|
2022-07-02 21:20:53 +02:00
|
|
|
enabled: boolean;
|
2026-03-04 16:47:15 +01:00
|
|
|
size: "sm" | "lg";
|
2024-08-28 08:44:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ShareScreenButton: FC<ShareScreenButtonProps> = ({
|
|
|
|
|
enabled,
|
|
|
|
|
...props
|
|
|
|
|
}) => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2023-11-20 13:38:01 +00:00
|
|
|
const label = enabled
|
|
|
|
|
? t("stop_screenshare_button_label")
|
|
|
|
|
: t("screenshare_button_label");
|
2022-10-10 09:19:10 -04:00
|
|
|
|
2021-12-07 11:59:57 -08:00
|
|
|
return (
|
2023-09-08 15:39:49 -04:00
|
|
|
<Tooltip label={label}>
|
2024-08-28 08:44:39 -04:00
|
|
|
<CpdButton
|
|
|
|
|
iconOnly
|
|
|
|
|
Icon={ShareScreenSolidIcon}
|
|
|
|
|
kind={enabled ? "primary" : "secondary"}
|
2026-03-18 15:09:02 +01:00
|
|
|
role="switch"
|
|
|
|
|
aria-checked={enabled}
|
2024-08-28 08:44:39 -04:00
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-08-30 21:58:29 -04:00
|
|
|
</Tooltip>
|
2021-12-07 11:59:57 -08:00
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|
2021-12-07 11:59:57 -08:00
|
|
|
|
2026-03-04 16:47:15 +01:00
|
|
|
interface EndCallButtonProps extends ComponentPropsWithoutRef<"button"> {
|
2026-03-09 14:40:13 +01:00
|
|
|
size?: "sm" | "lg";
|
2026-03-04 16:47:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const EndCallButton: FC<EndCallButtonProps> = ({
|
2024-08-28 08:44:39 -04:00
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}) => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2021-12-07 11:59:57 -08:00
|
|
|
return (
|
2023-11-20 13:00:43 +00:00
|
|
|
<Tooltip label={t("hangup_button_label")}>
|
2024-08-28 08:44:39 -04:00
|
|
|
<CpdButton
|
|
|
|
|
className={classNames(className, styles.endCall)}
|
|
|
|
|
iconOnly
|
|
|
|
|
Icon={EndCallIcon}
|
|
|
|
|
destructive
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-08-30 21:58:29 -04:00
|
|
|
</Tooltip>
|
2021-12-07 11:59:57 -08:00
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|
2022-04-27 16:47:23 -07:00
|
|
|
|
2026-04-09 15:49:09 +02:00
|
|
|
interface LoudspeakerButtonProps extends ComponentPropsWithoutRef<"button"> {
|
|
|
|
|
size?: "sm" | "lg";
|
|
|
|
|
/** The button will be rendered:
|
|
|
|
|
* true: currently in loudspeaker mode, pressing will switch to earpiece (rendered as enabled)
|
|
|
|
|
* false: currently in earpiece mode, pressing will switch to loudspeaker (rendered as disabled)
|
|
|
|
|
*/
|
|
|
|
|
isEarpieceTarget: boolean;
|
|
|
|
|
}
|
|
|
|
|
export const LoudspeakerButton: FC<LoudspeakerButtonProps> = (props) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const label = props.isEarpieceTarget
|
|
|
|
|
? t("settings.devices.handset")
|
|
|
|
|
: t("settings.devices.loudspeaker");
|
|
|
|
|
// if the target is the earpice, we are currently in loudspeaker mode.
|
|
|
|
|
const enabled = props.isEarpieceTarget;
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip label={label}>
|
|
|
|
|
<CpdButton
|
|
|
|
|
iconOnly
|
|
|
|
|
Icon={VolumeOnSolidIcon}
|
|
|
|
|
{...props}
|
|
|
|
|
kind={enabled ? "primary" : "secondary"}
|
|
|
|
|
role="switch"
|
|
|
|
|
aria-checked={enabled}
|
|
|
|
|
/>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-14 18:09:50 +02:00
|
|
|
function classNamesForScrrenWidth(
|
|
|
|
|
className?: string,
|
|
|
|
|
forScreenWidth?: "wide" | "narrow",
|
|
|
|
|
): string {
|
|
|
|
|
return classNames(className, {
|
|
|
|
|
[callFooterStyles.settingsOnlyShowWide]: forScreenWidth === "wide",
|
|
|
|
|
[callFooterStyles.settingsOnlyShowNarrow]: forScreenWidth === "narrow",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 17:44:31 +02:00
|
|
|
interface SettingsIconButtonProps extends ComponentPropsWithoutRef<"button"> {
|
2026-04-14 18:09:50 +02:00
|
|
|
/** If this buttons should be setup to be used in the app bar */
|
|
|
|
|
showForScreenWidth?: "wide" | "narrow";
|
2026-04-14 17:44:31 +02:00
|
|
|
kind?: "secondary" | "primary";
|
|
|
|
|
}
|
2026-04-14 18:09:50 +02:00
|
|
|
export const SettingsIconButton: FC<SettingsIconButtonProps> = ({
|
|
|
|
|
showForScreenWidth,
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}) => {
|
2026-04-14 17:44:31 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const Icon =
|
|
|
|
|
platform === "android" ? OverflowVerticalIcon : OverflowHorizontalIcon;
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip label={t("common.settings")}>
|
2026-04-14 18:09:50 +02:00
|
|
|
<IconButton
|
|
|
|
|
className={classNamesForScrrenWidth(className, showForScreenWidth)}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
2026-04-14 17:44:31 +02:00
|
|
|
<Icon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-09 13:42:28 +01:00
|
|
|
interface SettingsButtonProps extends ComponentPropsWithoutRef<"button"> {
|
2026-03-09 14:40:13 +01:00
|
|
|
size?: "sm" | "lg";
|
2026-04-10 18:59:17 +02:00
|
|
|
/** If this buttons should be setup to be used in the app bar */
|
|
|
|
|
showForScreenWidth?: "wide" | "narrow";
|
2026-03-09 13:42:28 +01:00
|
|
|
}
|
2026-04-10 18:59:17 +02:00
|
|
|
export const SettingsButton: FC<SettingsButtonProps> = ({
|
|
|
|
|
showForScreenWidth,
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}) => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2022-04-27 16:47:23 -07:00
|
|
|
return (
|
2023-11-20 11:05:18 +00:00
|
|
|
<Tooltip label={t("common.settings")}>
|
2024-08-28 08:44:39 -04:00
|
|
|
<CpdButton
|
2026-04-14 18:09:50 +02:00
|
|
|
className={classNamesForScrrenWidth(className, showForScreenWidth)}
|
2024-08-28 08:44:39 -04:00
|
|
|
iconOnly
|
2026-04-08 16:05:46 +02:00
|
|
|
Icon={
|
|
|
|
|
platform === "android" ? OverflowVerticalIcon : OverflowHorizontalIcon
|
|
|
|
|
}
|
2026-04-14 18:09:50 +02:00
|
|
|
kind={"secondary"}
|
2024-08-28 08:44:39 -04:00
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-08-30 21:58:29 -04:00
|
|
|
</Tooltip>
|
2022-04-27 16:47:23 -07:00
|
|
|
);
|
2023-09-22 18:05:13 -04:00
|
|
|
};
|