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

138 lines
3.3 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
Copyright 2022-2024 New Vector Ltd
2022-05-04 17:09:48 +01:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { ComponentPropsWithoutRef, 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,
SettingsSolidIcon,
} 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";
interface MicButtonProps extends ComponentPropsWithoutRef<"button"> {
muted: boolean;
2022-06-11 23:21:20 +02:00
}
export const MicButton: FC<MicButtonProps> = ({ muted, ...props }) => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2023-09-08 15:39:49 -04:00
const Icon = muted ? MicOffSolidIcon : MicOnSolidIcon;
2023-11-20 13:38:01 +00:00
const label = muted
? t("unmute_microphone_button_label")
: t("mute_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={muted ? "primary" : "secondary"}
{...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"> {
2022-07-02 21:20:53 +02:00
muted: boolean;
}
export const VideoButton: FC<VideoButtonProps> = ({ muted, ...props }) => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2023-10-30 10:43:59 -04:00
const Icon = muted ? VideoCallOffSolidIcon : VideoCallSolidIcon;
2023-11-20 13:38:01 +00:00
const label = muted
? t("start_video_button_label")
: t("stop_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={muted ? "primary" : "secondary"}
{...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;
}
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"}
{...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
export const EndCallButton: FC<ComponentPropsWithoutRef<"button">> = ({
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
export const SettingsButton: FC<ComponentPropsWithoutRef<"button">> = (
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
iconOnly
Icon={SettingsSolidIcon}
kind="secondary"
{...props}
/>
</Tooltip>
2022-04-27 16:47:23 -07:00
);
2023-09-22 18:05:13 -04:00
};