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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
|
2021-12-09 11:47:50 +01:00
|
|
|
import { Alignment } from "./Tooltip";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2021-12-09 13:36:55 +01:00
|
|
|
import TooltipTarget from "./TooltipTarget";
|
2020-08-25 13:58:15 -06:00
|
|
|
|
2021-06-01 14:40:27 +02:00
|
|
|
export enum InfoTooltipKind {
|
|
|
|
|
Info = "info",
|
|
|
|
|
Warning = "warning",
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-25 13:58:15 -06:00
|
|
|
interface ITooltipProps {
|
|
|
|
|
tooltip?: React.ReactNode;
|
2021-07-02 13:23:18 +02:00
|
|
|
className?: string;
|
2020-08-25 13:58:15 -06:00
|
|
|
tooltipClassName?: string;
|
2021-06-01 14:40:27 +02:00
|
|
|
kind?: InfoTooltipKind;
|
2020-08-25 13:58:15 -06:00
|
|
|
}
|
|
|
|
|
|
2021-12-09 11:47:50 +01:00
|
|
|
export default class InfoTooltip extends React.PureComponent<ITooltipProps> {
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props: ITooltipProps) {
|
2020-08-25 13:58:15 -06:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public render() {
|
2021-07-02 13:14:14 +02:00
|
|
|
const { tooltip, children, tooltipClassName, className, kind } = this.props;
|
2020-08-25 13:58:15 -06:00
|
|
|
const title = _t("Information");
|
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 (
|
2021-12-09 11:47:50 +01:00
|
|
|
<TooltipTarget
|
|
|
|
|
tooltipTargetClassName={classNames("mx_InfoTooltip", className)}
|
|
|
|
|
className="mx_InfoTooltip_container"
|
|
|
|
|
tooltipClassName={classNames("mx_InfoTooltip_tooltip", tooltipClassName)}
|
|
|
|
|
label={tooltip || title}
|
|
|
|
|
alignment={Alignment.Right}
|
2021-06-01 14:28:00 +02:00
|
|
|
>
|
2021-06-01 14:40:27 +02:00
|
|
|
<span className={classNames("mx_InfoTooltip_icon", iconClassName)} aria-label={title} />
|
2021-07-19 22:43:11 +01:00
|
|
|
{children}
|
2021-12-09 11:47:50 +01:00
|
|
|
</TooltipTarget>
|
2020-08-25 13:58:15 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|