TextField supports label, description, error state and hidden labels with proper aria wiring. Alert ships the four Aksel variants with matching icons from @navikt/aksel-icons. Adds stylesheets for both.
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
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<HTMLDivElement> {
|
|
/**
|
|
* 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<HTMLDivElement, AlertProps>(function Alert(
|
|
{ variant = "info", size = "medium", fullWidth = false, className, children, ...rest },
|
|
ref,
|
|
) {
|
|
const Icon = variantIcons[variant];
|
|
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
role={variant === "error" ? "alert" : "status"}
|
|
className={cn(
|
|
"navds-alert",
|
|
`navds-alert--${variant}`,
|
|
`navds-alert--${size}`,
|
|
fullWidth && "navds-alert--full-width",
|
|
className,
|
|
)}
|
|
{...rest}
|
|
>
|
|
<Icon className="navds-alert__icon" />
|
|
<div className="navds-alert__content">{children}</div>
|
|
</div>
|
|
);
|
|
});
|