2022-07-23 00:39:50 +00:00
|
|
|
import classNames from "classnames";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ReactNode } from "react";
|
2023-05-11 17:31:51 +00:00
|
|
|
import { forwardRef } from "react";
|
2023-06-05 05:51:19 +00:00
|
|
|
import type { IconType } from "react-icons";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2023-05-17 12:47:44 +00:00
|
|
|
import { CheckCircle2, Info, XCircle, AlertTriangle } from "@calcom/ui/components/icon";
|
2023-01-05 12:04:28 +00:00
|
|
|
|
2022-07-23 00:39:50 +00:00
|
|
|
export interface AlertProps {
|
|
|
|
title?: ReactNode;
|
2023-01-05 12:04:28 +00:00
|
|
|
// @TODO: Message should be children, more flexible?
|
2022-07-23 00:39:50 +00:00
|
|
|
message?: ReactNode;
|
2023-01-05 12:04:28 +00:00
|
|
|
// @TODO: Provide action buttons so style is always the same.
|
2022-07-23 00:39:50 +00:00
|
|
|
actions?: ReactNode;
|
|
|
|
className?: string;
|
2022-09-21 13:24:02 +00:00
|
|
|
iconClassName?: string;
|
2023-01-05 12:04:28 +00:00
|
|
|
// @TODO: Success and info shouldn't exist as per design?
|
|
|
|
severity: "success" | "warning" | "error" | "info" | "neutral";
|
2023-06-05 05:51:19 +00:00
|
|
|
CustomIcon?: IconType;
|
2023-06-23 17:13:16 +00:00
|
|
|
customIconColor?: string;
|
2022-07-23 00:39:50 +00:00
|
|
|
}
|
2023-05-11 17:31:51 +00:00
|
|
|
export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
|
2023-06-23 17:13:16 +00:00
|
|
|
const { severity, iconClassName, CustomIcon, customIconColor } = props;
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2023-05-11 17:31:51 +00:00
|
|
|
ref={ref}
|
2022-07-23 00:39:50 +00:00
|
|
|
className={classNames(
|
2023-06-12 17:49:44 +00:00
|
|
|
"rounded-md p-3",
|
2022-07-23 00:39:50 +00:00
|
|
|
props.className,
|
2023-06-12 17:49:44 +00:00
|
|
|
severity === "error" && "bg-red-100 text-red-900 dark:bg-red-900 dark:text-red-200",
|
|
|
|
severity === "warning" && "text-attention bg-attention dark:bg-orange-900 dark:text-orange-200",
|
|
|
|
severity === "info" && "bg-blue-100 text-blue-900 dark:bg-blue-900 dark:text-blue-200",
|
2023-04-05 18:14:46 +00:00
|
|
|
severity === "success" && "bg-inverted text-inverted",
|
2023-06-12 17:49:44 +00:00
|
|
|
severity === "neutral" && "bg-subtle text-default"
|
2022-07-23 00:39:50 +00:00
|
|
|
)}>
|
2023-06-17 20:57:15 +00:00
|
|
|
<div className="relative flex md:flex-row">
|
2023-06-05 05:51:19 +00:00
|
|
|
{CustomIcon ? (
|
|
|
|
<div className="flex-shrink-0">
|
2023-06-23 17:13:16 +00:00
|
|
|
<CustomIcon
|
|
|
|
aria-hidden="true"
|
|
|
|
className={classNames(`h-5 w-5`, iconClassName, customIconColor ?? "text-default")}
|
|
|
|
/>
|
2023-06-05 05:51:19 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
{severity === "error" && (
|
|
|
|
<XCircle
|
2023-06-12 17:49:44 +00:00
|
|
|
className={classNames("h-5 w-5 text-red-900 dark:text-red-200", iconClassName)}
|
2023-06-05 05:51:19 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{severity === "warning" && (
|
|
|
|
<AlertTriangle
|
2023-06-12 17:49:44 +00:00
|
|
|
className={classNames("text-attention h-5 w-5 dark:text-orange-200", iconClassName)}
|
2023-06-05 05:51:19 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{severity === "info" && (
|
|
|
|
<Info
|
2023-06-12 17:49:44 +00:00
|
|
|
className={classNames("h-5 w-5 text-blue-900 dark:text-blue-200", iconClassName)}
|
2023-06-05 05:51:19 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{severity === "neutral" && (
|
|
|
|
<Info
|
|
|
|
className={classNames("text-default h-5 w-5 fill-transparent", iconClassName)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{severity === "success" && (
|
|
|
|
<CheckCircle2
|
2023-06-12 17:49:44 +00:00
|
|
|
className={classNames("fill-muted text-default h-5 w-5", iconClassName)}
|
2023-06-05 05:51:19 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-06-17 20:57:15 +00:00
|
|
|
<div className="flex flex-grow flex-col sm:flex-row">
|
|
|
|
<div className="ml-3 ">
|
|
|
|
<h3 className="text-sm font-medium">{props.title}</h3>
|
|
|
|
<div className="text-sm">{props.message}</div>
|
|
|
|
</div>
|
|
|
|
{props.actions && <div className="ml-auto mt-2 text-sm sm:mt-0 md:relative">{props.actions}</div>}
|
2022-07-23 00:39:50 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-05-11 17:31:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Alert.displayName = "Alert";
|