2022-07-23 00:39:50 +00:00
|
|
|
import { CheckCircleIcon, ExclamationIcon, InformationCircleIcon, XCircleIcon } from "@heroicons/react/solid";
|
|
|
|
import classNames from "classnames";
|
|
|
|
import { ReactNode } from "react";
|
|
|
|
|
2023-01-23 23:08:01 +00:00
|
|
|
import { FiInfo } from "../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
|
|
|
}
|
|
|
|
export function Alert(props: AlertProps) {
|
2022-09-21 13:24:02 +00:00
|
|
|
const { severity, iconClassName } = props;
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
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-01-05 12:04:28 +00:00
|
|
|
severity === "success" && "bg-gray-900 text-white",
|
|
|
|
severity === "neutral" && "border-none bg-gray-100"
|
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" && (
|
2022-09-21 13:24:02 +00:00
|
|
|
<XCircleIcon className={classNames("h-5 w-5 text-red-400", iconClassName)} aria-hidden="true" />
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
{severity === "warning" && (
|
2022-09-21 13:24:02 +00:00
|
|
|
<ExclamationIcon
|
|
|
|
className={classNames("h-5 w-5 text-yellow-400", iconClassName)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
{severity === "info" && (
|
2022-09-21 13:24:02 +00:00
|
|
|
<InformationCircleIcon
|
|
|
|
className={classNames("h-5 w-5 text-sky-400", iconClassName)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
2023-01-05 12:04:28 +00:00
|
|
|
{severity === "neutral" && (
|
2023-01-23 23:08:01 +00:00
|
|
|
<FiInfo className={classNames("h-5 w-5 text-gray-800", iconClassName)} aria-hidden="true" />
|
2023-01-05 12:04:28 +00:00
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
{severity === "success" && (
|
2022-09-21 13:24:02 +00:00
|
|
|
<CheckCircleIcon
|
|
|
|
className={classNames("h-5 w-5 text-gray-400", 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>
|
|
|
|
);
|
|
|
|
}
|