alert.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import * as React from 'react'
  2. import { cva, type VariantProps } from 'class-variance-authority'
  3. // @ts-ignore
  4. import { cn } from '@/lib/utils'
  5. const alertVariants = cva(
  6. 'ui__alert relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground',
  7. {
  8. variants: {
  9. variant: {
  10. default: 'bg-background text-foreground',
  11. destructive:
  12. 'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive',
  13. },
  14. },
  15. defaultVariants: {
  16. variant: 'default',
  17. },
  18. }
  19. )
  20. const Alert = React.forwardRef<
  21. HTMLDivElement,
  22. React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
  23. >(({ className, variant, ...props }, ref) => (
  24. <div
  25. ref={ref}
  26. role="alert"
  27. className={cn(alertVariants({ variant }), className)}
  28. {...props}
  29. />
  30. ))
  31. Alert.displayName = 'Alert'
  32. const AlertTitle = React.forwardRef<
  33. HTMLParagraphElement,
  34. React.HTMLAttributes<HTMLHeadingElement>
  35. >(({ className, ...props }, ref) => (
  36. <h5
  37. ref={ref}
  38. className={cn('ui__alert-title mb-1 font-medium leading-none tracking-tight', className)}
  39. {...props}
  40. />
  41. ))
  42. AlertTitle.displayName = 'AlertTitle'
  43. const AlertDescription = React.forwardRef<
  44. HTMLParagraphElement,
  45. React.HTMLAttributes<HTMLParagraphElement>
  46. >(({ className, ...props }, ref) => (
  47. <div
  48. ref={ref}
  49. className={cn('ui__alert-description text-sm [&_p]:leading-relaxed', className)}
  50. {...props}
  51. />
  52. ))
  53. AlertDescription.displayName = 'AlertDescription'
  54. export { Alert, AlertTitle, AlertDescription }