import { XIcon } from "@heroicons/react/outline"; import { InformationCircleIcon, ExclamationCircleIcon, ExclamationIcon, CheckCircleIcon, } from "@heroicons/react/solid"; import React, { DetailedHTMLProps, HTMLAttributes } from "react"; import Button from "./Button"; import classNames from "./lib/classNames"; import Stack from "./Stack"; import Typography from "./Typography"; export type AlertVariant = "info" | "warning" | "danger" | "success"; export interface CustomAlertProps { variant?: AlertVariant; onClose?: () => void; description?: string; heading: string; } export interface AlertProps extends DetailedHTMLProps, HTMLDivElement>, CustomAlertProps {} export function getAlertIcon(variant: AlertVariant = "info") { switch (variant) { case "info": return ; case "warning": return ; case "success": return ; case "danger": return ; default: return ; } } export function getAlertStyles(variant: AlertVariant = "info") { const alertStyles = { base: "p-4 rounded-lg relative", variant: { warning: "bg-yellow-100 text-yellow-700", success: "bg-green-100 text-green-700", info: "bg-indigo-100 text-indigo-700", danger: "bg-red-100 text-red-700", }, }; return classNames(alertStyles.base, alertStyles.variant[variant]); } export default function Alert({ description, className, heading, variant, onClose, ...rest }: AlertProps) { const icon = getAlertIcon(variant); return (
{icon} {heading} {description} {onClose && ( )}
); }