2020-08-25 13:58:15 -06:00
|
|
|
/*
|
|
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
|
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-08 13:28:07 +00:00
|
|
|
import React, { ReactNode } from "react";
|
2020-08-25 13:58:15 -06:00
|
|
|
import classNames from "classnames";
|
2023-12-19 17:19:54 +00:00
|
|
|
import { Tooltip } from "@vector-im/compound-web";
|
2020-08-25 13:58:15 -06:00
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-08-25 13:58:15 -06:00
|
|
|
|
2021-06-01 14:40:27 +02:00
|
|
|
export enum InfoTooltipKind {
|
|
|
|
|
Info = "info",
|
|
|
|
|
Warning = "warning",
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-19 17:19:54 +00:00
|
|
|
interface TooltipProps {
|
|
|
|
|
tooltip?: string;
|
2021-07-02 13:23:18 +02:00
|
|
|
className?: string;
|
2021-06-01 14:40:27 +02:00
|
|
|
kind?: InfoTooltipKind;
|
2023-03-08 13:28:07 +00:00
|
|
|
children?: ReactNode;
|
2023-12-19 17:19:54 +00:00
|
|
|
tabIndex?: number;
|
2020-08-25 13:58:15 -06:00
|
|
|
}
|
|
|
|
|
|
2023-12-19 17:19:54 +00:00
|
|
|
export default class InfoTooltip extends React.PureComponent<TooltipProps> {
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2023-12-19 17:19:54 +00:00
|
|
|
const { tooltip, children, className, kind } = this.props;
|
2023-10-03 19:17:26 +01:00
|
|
|
const title = _t("info_tooltip_title");
|
2021-06-01 14:40:27 +02:00
|
|
|
const iconClassName =
|
|
|
|
|
kind !== InfoTooltipKind.Warning ? "mx_InfoTooltip_icon_info" : "mx_InfoTooltip_icon_warning";
|
2020-08-25 13:58:15 -06:00
|
|
|
|
|
|
|
|
// Tooltip are forced on the right for a more natural feel to them on info icons
|
|
|
|
|
return (
|
2023-12-19 17:19:54 +00:00
|
|
|
<Tooltip label={tooltip || title} side="right">
|
|
|
|
|
<div className={classNames("mx_InfoTooltip", className)} tabIndex={this.props.tabIndex ?? 0}>
|
|
|
|
|
<span className={classNames("mx_InfoTooltip_icon", iconClassName)} aria-label={title} />
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
</Tooltip>
|
2020-08-25 13:58:15 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|