Dialog
fluid-functionalism/dialogFreeComponent
Animated modal dialog with spring-based scale and opacity transitions. Built on Radix UI Dialog with overlay, header, footer, title, and description sub-components.
Install it
npx shadcn@latest add https://fluidfunctionalism.com/r/dialog.jsonSource
1"use client";23import {4 createContext,5 forwardRef,6 useContext,7 useEffect,8 useState,9 type ComponentPropsWithoutRef,10 type HTMLAttributes,11} from "react";12import * as DialogPrimitive from "@radix-ui/react-dialog";13import { motion } from "framer-motion";14import { cn } from "@/lib/utils";15import { useIcon } from "@/lib/icon-context";16import { spring, exitFallbackMs } from "@/lib/springs";17import { useShape } from "@/lib/shape-context";18import { SurfaceProvider, useSurface } from "@/lib/surface-context";19import { surfaceClasses } from "@/lib/surface-classes";20import { Button } from "@/components/ui/button";2122const DIALOG_OFFSET = 4;2324const DialogOpenContext = createContext(false);2526function Dialog({27 children,28 open: controlledOpen,29 defaultOpen,30 onOpenChange,31 ...props32}: DialogPrimitive.DialogProps) {33 // Internal state always tracks changes, and the consumer's onOpenChange is34 // notified alongside it — a listener must not replace state handling, or an35 // uncontrolled dialog with an onOpenChange prop could never open. The Root36 // below is always controlled by `open`, so defaultOpen seeds our state37 // instead of being forwarded.38 const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen ?? false);39 const open = controlledOpen ?? uncontrolledOpen;40 const handleOpenChange = (next: boolean) => {41 setUncontrolledOpen(next);42 onOpenChange?.(next);43 };4445 return (46 <DialogOpenContext.Provider value={open}>47 <DialogPrimitive.Root open={open} onOpenChange={handleOpenChange} {...props}>48 {children}49 </DialogPrimitive.Root>50 </DialogOpenContext.Provider>51 );52}5354const DialogTrigger = DialogPrimitive.Trigger;55const DialogClose = DialogPrimitive.Close;5657interface DialogContentProps58 extends ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {59 size?: "sm" | "lg";60 /** Portal target. When set, the overlay and panel render inside this element61 * (positioned `absolute`) instead of covering the viewport (`fixed`). Pair62 * with a `position: relative; overflow: hidden` container — and usually63 * `<Dialog modal={false}>` — to scope a dialog to a bounded region, e.g. a64 * docs preview. Defaults to the document body / full-viewport behaviour. */65 container?: HTMLElement | null;66}6768const DialogContent = forwardRef<HTMLDivElement, DialogContentProps>(69 ({ className, children, size = "sm", container, ...props }, ref) => {70 const XIcon = useIcon("x");71// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from fluid-functionalism
All 53 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | fluid-functionalism | Components | Free | 3 deps | |
| Accordion (Base UI)accordion-base | fluid-functionalism | Components | Free | 3 deps | |
| Ask User Questionsask-user-questions | fluid-functionalism | Components | Free | 2 deps | |
| Badgebadge | fluid-functionalism | Components | Free | 1 dep | |
| Buttonbutton | fluid-functionalism | Components | Free | 4 deps | |
| Button (Base UI)button-base | fluid-functionalism | Components | Free | 4 deps | |
| Cardcard | fluid-functionalism | Components | Free | 1 dep | |
| Chat Messagechat-message | fluid-functionalism | Components | Free | 1 dep |
