Alert Dialog
scrollxui/alert-dialogFreeComponent
A modal dialog used to convey critical information and require a user response before proceeding..
Live preview
live · rendered by the registry
Rendered by scrollxui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://scrollxui.dev/registry/alert-dialog.jsonSource
1'use client';23import * as React from 'react';4import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';5import { motion } from 'motion/react';6import { cn } from '@/lib/utils';7import { buttonVariants } from '@/components/ui/button';89const AlertDialog = AlertDialogPrimitive.Root;10const AlertDialogTrigger = AlertDialogPrimitive.Trigger;11const AlertDialogPortal = AlertDialogPrimitive.Portal;1213const AlertDialogOverlay = React.forwardRef<14 React.ComponentRef<typeof AlertDialogPrimitive.Overlay>,15 React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>16>(({ className, ...props }, ref) => (17 <AlertDialogPrimitive.Overlay18 ref={ref}19 className={cn(20 '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',21 className,22 )}23 {...props}24 />25));26AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;2728const AlertDialogContent = React.forwardRef<29 React.ComponentRef<typeof AlertDialogPrimitive.Content>,30 React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>31>(({ className, children }, _ref) => {32 const contentRef = React.useRef<HTMLDivElement>(null);33 const [shakeKey, setShakeKey] = React.useState(0);3435 React.useEffect(() => {36 function handleOutsideClick(event: MouseEvent | TouchEvent) {37 const node = contentRef.current;38 const target = event.target as Node | null;39 if (node && target && !node.contains(target)) {40 setShakeKey((k) => k + 1);41 }42 }4344 document.addEventListener('mousedown', handleOutsideClick);45 document.addEventListener('touchstart', handleOutsideClick);4647 return () => {48 document.removeEventListener('mousedown', handleOutsideClick);49 document.removeEventListener('touchstart', handleOutsideClick);50 };51 }, []);5253 return (54 <AlertDialogPortal>55 <AlertDialogOverlay />56 <AlertDialogPrimitive.Content asChild>57 <div className='fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2 sm:rounded-lg'>58 <motion.div59 key={shakeKey}60 ref={contentRef}61 animate={{ x: [0, -10, 10, -8, 8, -4, 4, 0] }}62 transition={{ duration: 0.5, ease: 'easeInOut' }}63 className={cn(64 'grid gap-4 border bg-background p-6 shadow-lg',65 className,66 )}67 >68 {children}69 </motion.div>70// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from scrollxui
All 180 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | scrollxui | Components | Free | 4 deps | |
| Animated Buttonanimated-button | scrollxui | Components | Free | 4 deps | |
| Animated Tabsanimated-tabs | scrollxui | Components | Free | 1 dep | |
| Animated Testimonialsanimated-testimonials | scrollxui | Components | Free | 2 deps | |
| Animated TextGenerateanimated-textgenerate | scrollxui | Components | Free | 3 deps | |
| Announcementannouncement | scrollxui | Components | Free | 5 deps | |
| Aspect Ratioaspect-ratio | scrollxui | Components | Free | 1 dep | |
| Aurora Dotsaurora-dots | scrollxui | Components | Free | 2 deps |
