import { forwardRef } from "react"; import type { HTMLAttributes, ReactNode } from "react"; import { CheckmarkIcon, InformationIcon, WarningIcon, XMarkIcon, } from "@navikt/aksel-icons"; import { cn } from "../util/cn"; export interface AlertProps extends HTMLAttributes { /** * Alert variant. * @default "info" */ variant?: "info" | "success" | "warning" | "error"; /** * Alert size. * @default "medium" */ size?: "medium" | "small"; /** * Stretches the alert to fill its container. * @default false */ fullWidth?: boolean; children: ReactNode; } const variantIcons = { info: InformationIcon, success: CheckmarkIcon, warning: WarningIcon, error: XMarkIcon, } as const; export const Alert = forwardRef(function Alert( { variant = "info", size = "medium", fullWidth = false, className, children, ...rest }, ref, ) { const Icon = variantIcons[variant]; return (
{children}
); });