Dialog

A centred white panel over a soft navy veil, with focus trap and Escape to close.

Install

$ npx shadcn@latest add @nudgekit/dialog

Or with no config: npx shadcn@latest add https://ui.nudgekit.app/r/dialog.json

Brings in @radix-ui/react-dialog, lucide-react, and the theme.

Usage

usage.tsx
import { Dialog, DialogTrigger, DialogContent, DialogTitle, DialogDescription, DialogFooter, DialogClose } from "@/components/ui/dialog"

<Dialog>
  <DialogTrigger asChild><Button variant="danger">Delete key</Button></DialogTrigger>
  <DialogContent>
    <DialogTitle>Delete this API key?</DialogTitle>
    <DialogDescription>Requests that use it stop working right away.</DialogDescription>
    <DialogFooter>
      <DialogClose asChild><Button variant="secondary" size="sm">Cancel</Button></DialogClose>
      <Button variant="danger" size="sm">Delete key</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

Do

  • Use for confirms and short focused tasks.
  • Name the action on the confirm button.

Don't

  • Open a dialog from a dialog.
  • Use OK and Cancel as button labels.

Code

What the CLI writes into your project. It is yours to change.

components/ui/dialog.tsx
"use client";

import * as React from "react";
import * as DialogPrimitive from "@radix-ui/react-dialog";
import { X } from "lucide-react";

import { cn } from "@/lib/utils";

const Dialog = DialogPrimitive.Root;
const DialogTrigger = DialogPrimitive.Trigger;
const DialogClose = DialogPrimitive.Close;

/** A centred white panel with a hairline, over a soft navy veil. Escape and the close button dismiss it. */
function DialogContent({ className, children, ...props }: React.ComponentProps<typeof DialogPrimitive.Content>) {
  return (
    <DialogPrimitive.Portal>
      <DialogPrimitive.Overlay className="fixed inset-0 z-50 bg-ink/30 data-[state=open]:animate-nk-fade" />
      <DialogPrimitive.Content
        data-slot="dialog-content"
        className={cn(
          "fixed left-1/2 top-1/2 z-50 w-[calc(100%-2rem)] max-w-md -translate-x-1/2 -translate-y-1/2 rounded-card border border-border bg-background p-6",
          "focus:outline-none data-[state=open]:animate-nk-pop motion-reduce:animate-none",
          className,
        )}
        {...props}
      >
        {children}
        <DialogPrimitive.Close
          className="absolute right-4 top-4 rounded-md p-1 text-muted-foreground transition-colors hover:bg-surface hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
          aria-label="Close"
        >
          <X className="size-4" />
        </DialogPrimitive.Close>
      </DialogPrimitive.Content>
    </DialogPrimitive.Portal>
  );
}

function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) {
  return <DialogPrimitive.Title className={cn("pr-8 text-lg font-medium tracking-[-0.01em] text-foreground", className)} {...props} />;
}

function DialogDescription({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Description>) {
  return <DialogPrimitive.Description className={cn("mt-1.5 text-sm leading-relaxed text-muted-foreground", className)} {...props} />;
}

function DialogFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
  return <div className={cn("mt-6 flex justify-end gap-2", className)} {...props} />;
}

export { Dialog, DialogTrigger, DialogClose, DialogContent, DialogTitle, DialogDescription, DialogFooter };