Files
element-call/src/button/Button.tsx
T

195 lines
5.1 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01: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
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
2022-05-04 17:09:48 +01: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";
import { Button as CpdButton, Tooltip } from "@vector-im/compound-web";
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,
} 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
interface MicButtonProps extends ComponentPropsWithoutRef<"button"> {
enabled: boolean;
2026-03-09 14:40:13 +01:00
size?: "sm" | "lg";
2022-06-11 23:21:20 +02:00
}
export const MicButton: FC<MicButtonProps> = ({ enabled, ...props }) => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
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}>
<CpdButton
iconOnly
Icon={Icon}
kind={enabled ? "primary" : "secondary"}
role="switch"
aria-checked={enabled}
{...props}
/>
</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
interface VideoButtonProps extends ComponentPropsWithoutRef<"button"> {
enabled: boolean;
2026-03-09 14:40:13 +01:00
size?: "sm" | "lg";
}
export const VideoButton: FC<VideoButtonProps> = ({ enabled, ...props }) => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
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}>
<CpdButton
iconOnly
Icon={Icon}
kind={enabled ? "primary" : "secondary"}
role="switch"
aria-checked={enabled}
{...props}
/>
</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
interface ShareScreenButtonProps extends ComponentPropsWithoutRef<"button"> {
2022-07-02 21:20:53 +02:00
enabled: boolean;
size: "sm" | "lg";
}
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}>
<CpdButton
iconOnly
Icon={ShareScreenSolidIcon}
kind={enabled ? "primary" : "secondary"}
role="switch"
aria-checked={enabled}
{...props}
/>
</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
interface EndCallButtonProps extends ComponentPropsWithoutRef<"button"> {
2026-03-09 14:40:13 +01:00
size?: "sm" | "lg";
}
export const EndCallButton: FC<EndCallButtonProps> = ({
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")}>
<CpdButton
className={classNames(className, styles.endCall)}
iconOnly
Icon={EndCallIcon}
destructive
{...props}
/>
</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-03-09 13:42:28 +01:00
interface SettingsButtonProps extends ComponentPropsWithoutRef<"button"> {
2026-03-09 14:40:13 +01:00
size?: "sm" | "lg";
/** If the button should be styled so it fits into the footer center buttons group */
forButtonsBar?: boolean;
/** If this buttons should be setup to be used in the app bar */
showForScreenWidth?: "wide" | "narrow";
2026-03-09 13:42:28 +01:00
}
export const SettingsButton: FC<SettingsButtonProps> = ({
showForScreenWidth,
forButtonsBar,
className,
...props
}) => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2022-04-27 16:47:23 -07:00
return (
<Tooltip label={t("common.settings")}>
<CpdButton
className={classNames(className, {
2026-04-14 13:25:33 +02:00
[callFooterStyles.settingsOnlyShowWide]:
showForScreenWidth === "wide",
2026-04-14 13:25:33 +02:00
[callFooterStyles.settingsOnlyShowNarrow]:
showForScreenWidth === "narrow",
})}
iconOnly
2026-04-08 16:05:46 +02:00
Icon={
platform === "android" ? OverflowVerticalIcon : OverflowHorizontalIcon
}
kind={forButtonsBar ? "secondary" : "tertiary"}
{...props}
/>
</Tooltip>
2022-04-27 16:47:23 -07:00
);
2023-09-22 18:05:13 -04:00
};