Dialog
A modal window over a dimming scrim, with focus trap, Escape to close and a corner close button, built on the Radix Dialog primitive.
Preview
Pebble notes
14 pages · edited 3 min ago
IMMHPSTR
4 members
Delete project
Pages, comments and history.
Install
Add the editable source with the shadcn CLI. Your project also needs the shared theme tokens this component uses. Setup and requirements. The Pebble installer is not published yet.
npx shadcn@latest add https://pebbleui.com/r/dialog.jsonProps
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | — | Controlled open state (root). |
| defaultOpen | boolean | false | Uncontrolled initial state (root). |
| onOpenChange | (open: boolean) => void | — | Called when the open state changes (root). |
| showCloseButton | boolean | true | Render the corner close button (DialogContent). |
| size | "sm" | "md" | "lg" | "lg" | Panel max width from the sm breakpoint up: 384, 448 or 512 px (DialogContent). |
| asChild | boolean | false | Merge onto the child element (DialogTrigger, DialogClose). |
Build notes
Radix `Dialog` provides portal, focus trap, scroll lock, `aria-hidden` on siblings and dismissal. The scrim is `bg-black/50` rather than a `foreground` tint because foreground turns light in dark mode and would brighten the page. The panel is centred with `top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2`; Tailwind v4 writes these to the CSS `translate` property, so the entry keyframes can animate `transform: scale()` without overwriting the centring. Animations are arbitrary `animate-[...]` utilities keyed on Radix's `data-state` and wrapped in `motion-safe:`; Radix's Presence waits for `animationend` before unmounting, so the exit runs. Keyframes ship in the registry item `css` field: `dialog-fade-in/out` (opacity 0 to 1, 150 ms) and `dialog-zoom-in/out` (opacity plus scale 0.96 to 1, 200 ms in / 150 ms out, ease-out in / ease-in out). The surface uses `card`/`card-foreground` and gets a `CanvasText` border in forced colors. **Pebble (2026-11-03).** The panel is now a Pebble raised object: `rounded-2xl`, `ring-1 ring-hairline`, `shadow-raised-lg` and `inset-shadow-highlight`, with `gap-5` and `p-6`. The scrim is the `--scrim` token (`bg-scrim`: black at 40%, 60% dark) with a 2 px backdrop blur. Timing moved to the motion tokens: the zoom-in runs `--motion-slow` on `--motion-enter`, every exit `--motion-fast` on `--motion-exit`, the scrim fade `--motion-base`. Reduced motion swaps the zoom for the existing `dialog-fade-in` keyframe instead of nothing, so no new keyframes ship. A `size` prop (`sm`/`md`/`lg`, default `lg`) maps to the `sm:max-w-*` width and is mirrored as `data-size`. The title is 16 px semibold with -0.01em tracking; the description is `text-pretty` with relaxed leading. The demo is a project card whose real triggers (Rename, a danger-tinted Delete) open a rename form with a live slug and a type-to-confirm delete whose danger key stays disabled until the slug matches. <!-- PEBBLE-LICENSE -->
View source
registry/overlay/dialog/dialog.tsx
"use client";
/* PEBBLE-LICENSE
Built by Pebble. Component: dialog.
First-party license: MIT
The following first-party terms apply only to original Pebble material.
MIT License
Copyright (c) 2026 Praxys Solutions LLC (Pebble)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THIRD-PARTY NOTICES
These notices apply to identified upstream portions; Pebble terms do not replace or narrow their rights.
Upstream: https://raw.githubusercontent.com/shadcn-ui/ui/main/LICENSE.md
MIT License
Copyright (c) 2023 shadcn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
END PEBBLE-LICENSE */
import * as React from "react";
import { Dialog as DialogPrimitive } from "radix-ui";
import { cn } from "@/lib/utils";
export function Dialog(props: React.ComponentProps<typeof DialogPrimitive.Root>) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
}
export function DialogTrigger(props: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
}
export function DialogClose(props: React.ComponentProps<typeof DialogPrimitive.Close>) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
}
export function DialogPortal(props: React.ComponentProps<typeof DialogPrimitive.Portal>) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
}
export function DialogOverlay({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
return (
<DialogPrimitive.Overlay
data-slot="dialog-overlay"
className={cn(
// A black scrim, not a foreground tint: foreground turns light in dark
// mode and would brighten the page instead of dimming it. A 2 px blur
// softens the page behind so the panel reads as the one object in focus.
"fixed inset-0 z-50 bg-scrim backdrop-blur-[2px]",
// Opacity only, so it also runs under reduced motion.
"data-[state=open]:animate-[dialog-fade-in_var(--motion-base)_var(--motion-enter)]",
"data-[state=closed]:animate-[dialog-fade-out_var(--motion-fast)_var(--motion-exit)]",
className,
)}
{...props}
/>
);
}
const sizes = {
sm: "sm:max-w-sm",
md: "sm:max-w-md",
lg: "sm:max-w-lg",
} as const;
export type DialogContentProps = React.ComponentProps<typeof DialogPrimitive.Content> & {
/** Render the corner close button. */
showCloseButton?: boolean;
/** Panel width from the `sm` breakpoint up. */
size?: keyof typeof sizes;
};
export function DialogContent({
className,
children,
showCloseButton = true,
size = "lg",
...props
}: DialogContentProps) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
data-slot="dialog-content"
data-size={size}
className={cn(
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-5",
// Pebble raised surface at the highest step: hairline ring, layered
// shadow and a 1 px top highlight.
"rounded-2xl bg-card p-6 text-card-foreground shadow-raised-lg ring-1 inset-shadow-highlight ring-hairline outline-none",
"forced-colors:border forced-colors:border-[CanvasText]",
// Keyframes scale via `transform`; the centring uses the separate
// `translate` property, so the two compose instead of fighting.
// Enter: 0.96 -> 1 with fade on the slow curve. Exit: opacity only,
// fast. Reduced motion keeps the fade and drops the scale.
"motion-safe:data-[state=open]:animate-[dialog-zoom-in_var(--motion-slow)_var(--motion-enter)]",
"motion-reduce:data-[state=open]:animate-[dialog-fade-in_var(--motion-base)_linear]",
"data-[state=closed]:animate-[dialog-fade-out_var(--motion-fast)_var(--motion-exit)]",
sizes[size],
className,
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close
data-slot="dialog-close-button"
className={cn(
"absolute top-4 right-4 inline-flex size-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground",
"transition-[background-color,color,transform] duration-(--motion-fast) ease-enter motion-reduce:transition-none",
"hover:bg-muted hover:text-foreground active:scale-[0.94] motion-reduce:active:scale-100",
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card focus-visible:outline-none",
)}
>
<svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
aria-hidden="true"
className="size-4"
>
<path d="M4 4l8 8M12 4l-8 8" />
</svg>
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
);
}
export function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-1.5 pr-8 text-left", className)}
{...props}
/>
);
}
export function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-footer"
className={cn("flex flex-col-reverse gap-2 pt-1 sm:flex-row sm:justify-end", className)}
{...props}
/>
);
}
export function DialogTitle({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn("text-base leading-snug font-semibold tracking-[-0.01em]", className)}
{...props}
/>
);
}
export function DialogDescription({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn("text-sm leading-relaxed text-pretty text-muted-foreground", className)}
{...props}
/>
);
}
