alert.jsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import * as React from "react"
  2. import { cva } 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. }) {
  24. return (
  25. <div
  26. data-slot="alert"
  27. role="alert"
  28. className={cn(alertVariants({ variant }), className)}
  29. {...props} />
  30. );
  31. }
  32. function AlertTitle({
  33. className,
  34. ...props
  35. }) {
  36. return (
  37. <div
  38. data-slot="alert-title"
  39. className={cn("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight", className)}
  40. {...props} />
  41. );
  42. }
  43. function AlertDescription({
  44. className,
  45. ...props
  46. }) {
  47. return (
  48. <div
  49. data-slot="alert-description"
  50. className={cn(
  51. "text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
  52. className
  53. )}
  54. {...props} />
  55. );
  56. }
  57. export { Alert, AlertTitle, AlertDescription }