gitscope
← marzneshin / v0.7.4 / dashboard/src/common/components/ui/alert-dialog.tsx
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/common/components/ui/alert-dialog.tsx · TypeScript
Blame Raw
  1import * as React from "react"
  2import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
  3
  4import { cn } from "@marzneshin/common/utils"
  5import { buttonVariants } from "@marzneshin/common/components/ui/button"
  6
  7const AlertDialog = AlertDialogPrimitive.Root
  8
  9const AlertDialogTrigger = AlertDialogPrimitive.Trigger
 10
 11const AlertDialogPortal = AlertDialogPrimitive.Portal
 12
 13const AlertDialogOverlay = React.forwardRef<
 14    React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
 15    React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
 16>(({ className, ...props }, ref) => (
 17    <AlertDialogPrimitive.Overlay
 18        className={cn(
 19            "fixed inset-0 z-50 bg-black/80  data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
 20            className
 21        )}
 22        {...props}
 23        ref={ref}
 24    />
 25))
 26AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
 27
 28const AlertDialogContent = React.forwardRef<
 29    React.ElementRef<typeof AlertDialogPrimitive.Content>,
 30    React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
 31>(({ className, ...props }, ref) => (
 32    <AlertDialogPortal>
 33        <AlertDialogOverlay />
 34        <AlertDialogPrimitive.Content
 35            ref={ref}
 36            className={cn(
 37                "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
 38                className
 39            )}
 40            {...props}
 41        />
 42    </AlertDialogPortal>
 43))
 44AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
 45
 46const AlertDialogHeader = ({
 47    className,
 48    ...props
 49}: React.HTMLAttributes<HTMLDivElement>) => (
 50    <div
 51        className={cn(
 52            "flex flex-col space-y-2 text-center sm:text-left",
 53            className
 54        )}
 55        {...props}
 56    />
 57)
 58AlertDialogHeader.displayName = "AlertDialogHeader"
 59
 60const AlertDialogFooter = ({
 61    className,
 62    ...props
 63}: React.HTMLAttributes<HTMLDivElement>) => (
 64    <div
 65        className={cn(
 66            "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
 67            className
 68        )}
 69        {...props}
 70    />
 71)
 72AlertDialogFooter.displayName = "AlertDialogFooter"
 73
 74const AlertDialogTitle = React.forwardRef<
 75    React.ElementRef<typeof AlertDialogPrimitive.Title>,
 76    React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
 77>(({ className, ...props }, ref) => (
 78    <AlertDialogPrimitive.Title
 79        ref={ref}
 80        className={cn("text-lg font-semibold", className)}
 81        {...props}
 82    />
 83))
 84AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
 85
 86const AlertDialogDescription = React.forwardRef<
 87    React.ElementRef<typeof AlertDialogPrimitive.Description>,
 88    React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
 89>(({ className, ...props }, ref) => (
 90    <AlertDialogPrimitive.Description
 91        ref={ref}
 92        className={cn("text-sm text-muted-foreground", className)}
 93        {...props}
 94    />
 95))
 96AlertDialogDescription.displayName =
 97    AlertDialogPrimitive.Description.displayName
 98
 99const AlertDialogAction = React.forwardRef<
100    React.ElementRef<typeof AlertDialogPrimitive.Action>,
101    React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
102>(({ className, ...props }, ref) => (
103    <AlertDialogPrimitive.Action
104        ref={ref}
105        className={cn(buttonVariants(), className)}
106        {...props}
107    />
108))
109AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
110
111const AlertDialogCancel = React.forwardRef<
112    React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
113    React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
114>(({ className, ...props }, ref) => (
115    <AlertDialogPrimitive.Cancel
116        ref={ref}
117        className={cn(
118            buttonVariants({ variant: "outline" }),
119            "mt-2 sm:mt-0",
120            className
121        )}
122        {...props}
123    />
124))
125AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
126
127export {
128    AlertDialog,
129    AlertDialogPortal,
130    AlertDialogOverlay,
131    AlertDialogTrigger,
132    AlertDialogContent,
133    AlertDialogHeader,
134    AlertDialogFooter,
135    AlertDialogTitle,
136    AlertDialogDescription,
137    AlertDialogAction,
138    AlertDialogCancel,
139}