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";
|
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";
|
2022-07-23 00:39:50 +00:00
|
|
|
}
|
2023-05-11 17:31:51 +00:00
|
|
|
export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
|
2022-09-21 13:24:02 +00:00
|
|
|
const { severity, iconClassName } = 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(
|
2022-09-07 15:01:33 +00:00
|
|
|
"rounded-md border border-opacity-20 p-3",
|
2022-07-23 00:39:50 +00:00
|
|
|
props.className,
|
|
|
|
severity === "error" && "border-red-900 bg-red-50 text-red-800",
|
|
|
|
severity === "warning" && "border-yellow-700 bg-yellow-50 text-yellow-700",
|
|
|
|
severity === "info" && "border-sky-700 bg-sky-50 text-sky-700",
|
2023-04-05 18:14:46 +00:00
|
|
|
severity === "success" && "bg-inverted text-inverted",
|
|
|
|
severity === "neutral" && "bg-subtle text-default border-none"
|
2022-07-23 00:39:50 +00:00
|
|
|
)}>
|
2022-09-21 13:24:02 +00:00
|
|
|
<div className="relative flex flex-col md:flex-row">
|
2022-07-23 00:39:50 +00:00
|
|
|
<div className="flex-shrink-0">
|
|
|
|
{severity === "error" && (
|
2023-05-17 12:47:44 +00:00
|
|
|
<XCircle
|
|
|
|
className={classNames("h-5 w-5 fill-red-400 text-white", iconClassName)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
{severity === "warning" && (
|
2023-05-17 12:47:44 +00:00
|
|
|
<AlertTriangle
|
|
|
|
className={classNames("h-5 w-5 fill-yellow-400 text-white", iconClassName)}
|
2022-09-21 13:24:02 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
{severity === "info" && (
|
2023-05-17 12:47:44 +00:00
|
|
|
<Info
|
|
|
|
className={classNames("h-5 w-5 fill-sky-400 text-white", iconClassName)}
|
2022-09-21 13:24:02 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
2023-01-05 12:04:28 +00:00
|
|
|
{severity === "neutral" && (
|
2023-05-17 12:47:44 +00:00
|
|
|
<Info
|
|
|
|
className={classNames("text-default h-5 w-5 fill-transparent", iconClassName)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2023-01-05 12:04:28 +00:00
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
{severity === "success" && (
|
2023-05-17 12:47:44 +00:00
|
|
|
<CheckCircle2
|
|
|
|
className={classNames("fill-muted h-5 w-5 text-white", iconClassName)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="ml-3 flex-grow">
|
|
|
|
<h3 className="text-sm font-medium">{props.title}</h3>
|
|
|
|
<div className="text-sm">{props.message}</div>
|
|
|
|
</div>
|
2023-01-05 12:04:28 +00:00
|
|
|
{/* @TODO: Shouldn't be absolute. This makes it harder to give margin etc. */}
|
2022-09-21 13:24:02 +00:00
|
|
|
{props.actions && <div className="absolute top-1 right-1 text-sm md:relative">{props.actions}</div>}
|
2022-07-23 00:39:50 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-05-11 17:31:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Alert.displayName = "Alert";
|