|
| 1 | +import { HtmlHTMLAttributes } from "react"; |
| 2 | +import { cva, type VariantProps } from "class-variance-authority"; |
| 3 | + |
| 4 | +import { cn } from "@/lib/utils"; |
| 5 | +import { Text } from "../Text"; |
| 6 | + |
| 7 | +const alertVariants = cva("relative w-full border-2 border-black p-4", { |
| 8 | + variants: { |
| 9 | + variant: { |
| 10 | + default: "bg-primary-300 text-foreground", |
| 11 | + solid: "bg-black text-white", |
| 12 | + destructive: |
| 13 | + "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", |
| 14 | + }, |
| 15 | + status: { |
| 16 | + error: "bg-red-300 text-red-800 border-red-800", |
| 17 | + success: "bg-green-300 text-green-800 border-green-800", |
| 18 | + warning: "bg-yellow-300 text-yellow-800 border-yellow-800", |
| 19 | + info: "bg-blue-300 text-blue-800 border-blue-800", |
| 20 | + }, |
| 21 | + }, |
| 22 | + defaultVariants: { |
| 23 | + variant: "default", |
| 24 | + }, |
| 25 | +}); |
| 26 | + |
| 27 | +interface IAlertProps |
| 28 | + extends HtmlHTMLAttributes<HTMLDivElement>, |
| 29 | + VariantProps<typeof alertVariants> {} |
| 30 | + |
| 31 | +const Alert = ({ className, variant, status, ...props }: IAlertProps) => ( |
| 32 | + <div |
| 33 | + role="alert" |
| 34 | + className={cn(alertVariants({ variant, status }), className)} |
| 35 | + {...props} |
| 36 | + /> |
| 37 | +); |
| 38 | +Alert.displayName = "Alert"; |
| 39 | + |
| 40 | +interface IAlertTitleProps extends HtmlHTMLAttributes<HTMLHeadingElement> {} |
| 41 | +const AlertTitle = ({ className, ...props }: IAlertTitleProps) => ( |
| 42 | + <Text as="h5" className={cn(className)} {...props} /> |
| 43 | +); |
| 44 | +AlertTitle.displayName = "AlertTitle"; |
| 45 | + |
| 46 | +interface IAlertDescriptionProps |
| 47 | + extends HtmlHTMLAttributes<HTMLParagraphElement> {} |
| 48 | +const AlertDescription = ({ className, ...props }: IAlertDescriptionProps) => ( |
| 49 | + <div className={cn("text-muted", className)} {...props} /> |
| 50 | +); |
| 51 | + |
| 52 | +AlertDescription.displayName = "AlertDescription"; |
| 53 | + |
| 54 | +const AlertComponent = Object.assign(Alert, { |
| 55 | + Title: AlertTitle, |
| 56 | + Description: AlertDescription, |
| 57 | +}); |
| 58 | + |
| 59 | +export { AlertComponent as Alert }; |
0 commit comments