Dialog
Installation
npx shadcn@latest add https://uibrik.com/r/dialog.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/dialog/dialog.tsx"use client"; // A modal that grows out of the button that opened it and shrinks back into // it. Focus is held inside, the page behind stops scrolling, and Escape or a // click on the backdrop closes it. Opening a dialog from inside another one // eases the first back, so the stack reads at a glance. import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { createContext, useContext, useEffect, useId, useLayoutEffect, useRef, useState, type ReactNode } from "react"; import { cn } from "@/lib/utils"; import { EASE_OUT, FOCUS, Portal, SURFACE, useDismiss, useFocusTrap, useLayer, useScrollLock } from "../_overlay/overlay"; const SIZES = { sm: "max-w-sm", md: "max-w-md", lg: "max-w-lg" } as const; export type DialogProps = { /** The button that opens the dialog. Leave out when fully controlled. */ trigger?: ReactNode; title: ReactNode; description?: ReactNode; /** The body. A function receives `close`. */ children?: ReactNode | ((close: () => void) => ReactNode); /** Buttons along the bottom. A function receives `close`. */ footer?: ReactNode | ((close: () => void) => ReactNode); size?: keyof typeof SIZES;
Adds the files to
components/uibrik/dialog and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/dialog.Props
Dialog- size
- Type "sm" | "md" | "lg"
- "md"
- Maximum width of the panel.
- dismissible
- Type boolean
- true
- Close on Escape and backdrop click.
- blur
- Type boolean
- true
- Blur the page behind the backdrop.
- trigger
- Type ReactNode
- –
- The button that opens the dialog. Leave out when controlled.
- titlerequired
- Type ReactNode
- –
- Heading, also the dialog's accessible name.
- description
- Type ReactNode
- –
- A line under the title.
- children
- Type ReactNode | (close) => ReactNode
- –
- The body.
- footer
- Type ReactNode | (close) => ReactNode
- –
- Buttons along the bottom. dialogButton has matching styles.
- open / onOpenChange
- Type boolean / (open) => void
- –
- Controlled open state.
- className
- Type string
- –
- Classes for the panel.