mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-11-02 13:07:46 +00:00
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
import { X } from "lucide-react"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
const bannerVariants = cva(
|
|
"relative w-full border-b px-4 py-3 text-sm [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "bg-background text-foreground",
|
|
info: "border-blue-500/50 bg-blue-50 text-blue-900 dark:bg-blue-950 dark:text-blue-100 [&>svg]:text-blue-600 dark:[&>svg]:text-blue-400",
|
|
success:
|
|
"border-green-500/50 bg-green-50 text-green-900 dark:bg-green-950 dark:text-green-100 [&>svg]:text-green-600 dark:[&>svg]:text-green-400",
|
|
warning:
|
|
"border-yellow-500/50 bg-yellow-50 text-yellow-900 dark:bg-yellow-950 dark:text-yellow-100 [&>svg]:text-yellow-600 dark:[&>svg]:text-yellow-400",
|
|
error:
|
|
"border-red-500/50 bg-red-50 text-red-900 dark:bg-red-950 dark:text-red-100 [&>svg]:text-red-600 dark:[&>svg]:text-red-400",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: "default",
|
|
},
|
|
}
|
|
)
|
|
|
|
export interface BannerProps
|
|
extends React.HTMLAttributes<HTMLDivElement>,
|
|
VariantProps<typeof bannerVariants> {
|
|
onClose?: () => void
|
|
}
|
|
|
|
const Banner = React.forwardRef<HTMLDivElement, BannerProps>(
|
|
({ className, variant, onClose, children, ...props }, ref) => {
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
role="alert"
|
|
className={cn(bannerVariants({ variant }), className)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
{onClose && (
|
|
<button
|
|
type="button"
|
|
onClick={onClose}
|
|
className="absolute right-4 top-3 rounded-md p-1 hover:bg-black/5 dark:hover:bg-white/5"
|
|
>
|
|
<X className="h-4 w-4" />
|
|
<span className="sr-only">Close</span>
|
|
</button>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
Banner.displayName = "Banner"
|
|
|
|
export { Banner, bannerVariants }
|