alert.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import * as React from "react"
  2. import { cva, type VariantProps } from "class-variance-authority"
  3. import { cn } from "@/lib/utils"
  4. const alertVariants = cva(
  5. "relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
  6. {
  7. variants: {
  8. variant: {
  9. default: "bg-card text-card-foreground",
  10. destructive:
  11. "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",
  12. },
  13. },
  14. defaultVariants: {
  15. variant: "default",
  16. },
  17. }
  18. )
  19. function Alert({
  20. className,
  21. variant,
  22. ...props
  23. }: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
  24. return (
  25. <div
  26. data-slot="alert"
  27. role="alert"
  28. className={cn(alertVariants({ variant }), className)}
  29. {...props}
  30. />
  31. )
  32. }
  33. function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
  34. return (
  35. <div
  36. data-slot="alert-title"
  37. className={cn(
  38. "col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
  39. className
  40. )}
  41. {...props}
  42. />
  43. )
  44. }
  45. function AlertDescription({
  46. className,
  47. ...props
  48. }: React.ComponentProps<"div">) {
  49. return (
  50. <div
  51. data-slot="alert-description"
  52. className={cn(
  53. "text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
  54. className
  55. )}
  56. {...props}
  57. />
  58. )
  59. }
  60. export { Alert, AlertTitle, AlertDescription }