Dialog
trovecn/dialogFreeComponent
Centered modal with a spring-scaled popup and fading backdrop.
Install it
npx shadcn@latest add https://trovecn.dev/r/dialog.jsonSource
1"use client";23import type { ComponentProps } from "react";4import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";5import { motion, useReducedMotion } from "motion/react";6import { XIcon } from "lucide-react";78import { cn } from "@/lib/utils";9import { spring } from "@/lib/springs";10import { Button } from "@/components/ui/button";1112function Dialog({ ...props }: DialogPrimitive.Root.Props) {13 return <DialogPrimitive.Root data-slot="dialog" {...props} />;14}1516function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props) {17 return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;18}1920function DialogClose({ ...props }: DialogPrimitive.Close.Props) {21 return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;22}2324function DialogPortal({ ...props }: DialogPrimitive.Portal.Props) {25 return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;26}2728/**29 * Rendered through Base UI's `render` function-prop rather than a plain30 * `className` so the backdrop can read `state.transitionStatus` — Base UI31 * keeps the element mounted through a "ending" status and only removes it32 * once it detects the animation on it has finished, so handing that status33 * to motion (instead of a CSS transition) is enough to get a correct34 * exit with no manual mount-tracking, unlike Accordion's Panel (which35 * doesn't defer removal the same way).36 */37function DialogOverlay({ className, ...props }: DialogPrimitive.Backdrop.Props) {38 const reduceMotion = useReducedMotion();3940 return (41 <DialogPrimitive.Backdrop42 data-slot="dialog-overlay"43 render={(backdropProps, state) => {44 const exiting = state.transitionStatus === "ending";45 return (46 <motion.div47 {...(backdropProps as Record<string, unknown>)}48 className={cn("fixed inset-0 z-50 bg-black/40 backdrop-blur-sm", className)}49 initial={{ opacity: 0 }}50 animate={{ opacity: exiting ? 0 : 1 }}51 transition={52 reduceMotion ? spring.fast.enter : exiting ? spring.slow.exit : spring.slow.enter53 }54 />55 );56 }}57 {...props}58 />59 );60}6162/**63 * Centered, fully-rounded surface — unlike Drawer (which sits flush against64 * a viewport edge), a dialog is a detached floating plane, so it gets the65 * `--popover` step and `shadow-panel` on every side rather than Drawer's66 * edge-attached treatment.67 */68function DialogContent({69 className,70 children,71// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from trovecn
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | trovecn | Components | Free | 3 deps | |
| Agent Activityagent-activity | trovecn | Components | Free | 2 deps | |
| Approval Requestapproval-request | trovecn | Components | Free | 2 deps | |
| Buttonbutton | trovecn | Components | Free | 2 deps | |
| Checkboxcheckbox | trovecn | Components | Free | 2 deps | |
| Checkbox Groupcheckbox-group | trovecn | Components | Free | 2 deps | |
| Comboboxcombobox | trovecn | Components | Free | 3 deps | |
| Comparison Slidercomparison-slider | trovecn | Components | Free | 1 dep |
