2019-02-01 13:39:25 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-01-23 14:38:17 +00:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2019 New Vector Ltd
|
2019-02-01 13:39:25 +01:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-02-01 13:39:25 +01:00
|
|
|
*/
|
|
|
|
|
|
2025-02-05 13:25:06 +00:00
|
|
|
import React, { type ComponentProps, type CSSProperties } from "react";
|
2019-02-01 13:39:25 +01:00
|
|
|
import classNames from "classnames";
|
2023-12-21 15:21:41 +00:00
|
|
|
import { Tooltip } from "@vector-im/compound-web";
|
2020-01-23 13:00:17 +00:00
|
|
|
|
2025-02-05 13:25:06 +00:00
|
|
|
import { _t, _td, type TranslationKey } from "../../../languageHandler";
|
2020-01-24 10:13:03 +00:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2021-09-20 13:23:02 +02:00
|
|
|
import { E2EStatus } from "../../../utils/ShieldUtils";
|
2019-02-01 13:39:25 +01:00
|
|
|
|
2025-01-13 22:17:52 +05:30
|
|
|
export const crossSigningUserTitles: { [key in E2EStatus]?: TranslationKey } = {
|
|
|
|
|
[E2EStatus.Warning]: _td("encryption|cross_signing_user_warning"),
|
|
|
|
|
[E2EStatus.Normal]: _td("encryption|cross_signing_user_normal"),
|
|
|
|
|
[E2EStatus.Verified]: _td("encryption|cross_signing_user_verified"),
|
2020-01-23 13:00:17 +00:00
|
|
|
};
|
2025-01-13 22:17:52 +05:30
|
|
|
const crossSigningRoomTitles: { [key in E2EStatus]?: TranslationKey } = {
|
|
|
|
|
[E2EStatus.Warning]: _td("encryption|cross_signing_room_warning"),
|
|
|
|
|
[E2EStatus.Normal]: _td("encryption|cross_signing_room_normal"),
|
|
|
|
|
[E2EStatus.Verified]: _td("encryption|cross_signing_room_verified"),
|
2020-01-23 13:00:17 +00:00
|
|
|
};
|
2020-01-23 14:38:17 +00:00
|
|
|
|
2023-05-05 09:26:11 +01:00
|
|
|
interface Props {
|
2021-09-20 13:23:02 +02:00
|
|
|
className?: string;
|
|
|
|
|
size?: number;
|
|
|
|
|
onClick?: () => void;
|
|
|
|
|
hideTooltip?: boolean;
|
2024-04-12 14:56:23 +02:00
|
|
|
tooltipPlacement?: ComponentProps<typeof Tooltip>["placement"];
|
2021-09-20 13:23:02 +02:00
|
|
|
bordered?: boolean;
|
2023-05-05 09:26:11 +01:00
|
|
|
status: E2EStatus;
|
2025-01-13 22:17:52 +05:30
|
|
|
isUser?: boolean;
|
2023-05-05 09:26:11 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-13 22:17:52 +05:30
|
|
|
const E2EIcon: React.FC<Props> = ({
|
2022-10-06 22:27:28 -04:00
|
|
|
isUser,
|
|
|
|
|
status,
|
|
|
|
|
className,
|
|
|
|
|
size,
|
|
|
|
|
onClick,
|
|
|
|
|
hideTooltip,
|
2024-04-12 14:56:23 +02:00
|
|
|
tooltipPlacement,
|
2022-10-06 22:27:28 -04:00
|
|
|
bordered,
|
|
|
|
|
}) => {
|
2020-01-24 10:13:03 +00:00
|
|
|
const classes = classNames(
|
|
|
|
|
{
|
2019-02-01 13:39:25 +01:00
|
|
|
mx_E2EIcon: true,
|
2020-07-14 00:52:03 +01:00
|
|
|
mx_E2EIcon_bordered: bordered,
|
2025-01-13 22:17:52 +05:30
|
|
|
mx_E2EIcon_warning: status === E2EStatus.Warning,
|
|
|
|
|
mx_E2EIcon_normal: status === E2EStatus.Normal,
|
|
|
|
|
mx_E2EIcon_verified: status === E2EStatus.Verified,
|
2020-01-22 16:54:31 +00:00
|
|
|
},
|
|
|
|
|
className,
|
|
|
|
|
);
|
2019-12-13 17:57:26 +00:00
|
|
|
|
2023-08-22 16:32:05 +01:00
|
|
|
let e2eTitle: TranslationKey | undefined;
|
2023-05-05 09:26:11 +01:00
|
|
|
if (isUser) {
|
|
|
|
|
e2eTitle = crossSigningUserTitles[status];
|
|
|
|
|
} else {
|
|
|
|
|
e2eTitle = crossSigningRoomTitles[status];
|
2019-02-01 13:39:25 +01:00
|
|
|
}
|
2019-11-12 16:25:38 +01:00
|
|
|
|
2023-03-13 15:07:20 +00:00
|
|
|
let style: CSSProperties | undefined;
|
2020-01-23 13:00:17 +00:00
|
|
|
if (size) {
|
2021-06-29 13:11:58 +01:00
|
|
|
style = { width: `${size}px`, height: `${size}px` };
|
2019-11-12 16:25:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-05-05 09:26:11 +01:00
|
|
|
const label = e2eTitle ? _t(e2eTitle) : "";
|
|
|
|
|
|
2023-12-21 15:21:41 +00:00
|
|
|
let content: JSX.Element;
|
|
|
|
|
if (onClick) {
|
|
|
|
|
content = <AccessibleButton onClick={onClick} className={classes} style={style} />;
|
|
|
|
|
} else {
|
|
|
|
|
content = <div className={classes} style={style} />;
|
2019-02-12 19:59:31 +01:00
|
|
|
}
|
2020-01-24 10:13:03 +00:00
|
|
|
|
2023-12-21 15:21:41 +00:00
|
|
|
if (!e2eTitle || hideTooltip) {
|
|
|
|
|
return content;
|
2020-01-24 10:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-18 12:01:51 +01:00
|
|
|
return (
|
2024-04-12 14:56:23 +02:00
|
|
|
<Tooltip label={label} placement={tooltipPlacement} isTriggerInteractive={!!onClick}>
|
2023-12-21 15:21:41 +00:00
|
|
|
{content}
|
|
|
|
|
</Tooltip>
|
2020-01-24 10:13:03 +00:00
|
|
|
);
|
2020-01-23 13:00:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default E2EIcon;
|