✨ Add TextField and Alert components
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.
This commit is contained in:
1 parent
1bcf7f5d53
commit
bb9501ea31
9 files changed
+286
No files matched your search
@@ -0,0 +1,60 @@
|
||||
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>
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user