alert.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { type VariantProps, cva } from 'class-variance-authority';
  2. import * as React from 'react';
  3. import { cn } from '@/common/helpers/cn';
  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-background text-foreground',
  10. destructive: 'text-destructive-foreground [&>svg]:text-current *:data-[slot=alert-description]:text-destructive-foreground/80',
  11. },
  12. },
  13. defaultVariants: {
  14. variant: 'default',
  15. },
  16. },
  17. );
  18. function Alert({ className, variant, ...props }: React.ComponentProps<'div'> & VariantProps<typeof alertVariants>) {
  19. return <div data-slot="alert" role="alert" className={cn(alertVariants({ variant }), className)} {...props} />;
  20. }
  21. function AlertTitle({ className, ...props }: React.ComponentProps<'div'>) {
  22. return <div data-slot="alert-title" className={cn('col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight', className)} {...props} />;
  23. }
  24. function AlertDescription({ className, ...props }: React.ComponentProps<'div'>) {
  25. return (
  26. <div
  27. data-slot="alert-description"
  28. className={cn('col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed', className)}
  29. {...props}
  30. />
  31. );
  32. }
  33. export { Alert, AlertDescription, AlertTitle };