nteract elements

Dialog

A modal dialog for confirmations, forms, and focused interactions

A modal dialog component for displaying focused content that requires user interaction. Built on Radix UI Dialog for accessible keyboard navigation and focus trapping. Ideal for confirmations, settings forms, and kernel selection.

Installation

npx shadcn@latest add https://nteract-elements.vercel.app/r/dialog.json

Install the dependencies:

npm install radix-ui lucide-react

Copy from the nteract/elements registry.

Usage

import {
  Dialog,
  DialogTrigger,
  DialogContent,
  DialogHeader,
  DialogFooter,
  DialogTitle,
  DialogDescription,
} from "@/registry/primitives/dialog"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger>Open</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Dialog Title</DialogTitle>
          <DialogDescription>Dialog description text.</DialogDescription>
        </DialogHeader>
        <DialogFooter>
          <Button>Confirm</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}

Examples

Basic Dialog

<Dialog>
  <DialogTrigger asChild>
    <Button variant="outline">Show Details</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Cell Details</DialogTitle>
      <DialogDescription>
        Information about this cell and its execution history.
      </DialogDescription>
    </DialogHeader>
    <div className="grid gap-2 py-4">
      <div className="flex justify-between">
        <span>Cell ID:</span>
        <span>abc-123</span>
      </div>
    </div>
  </DialogContent>
</Dialog>

Confirmation Dialog

<Dialog>
  <DialogTrigger asChild>
    <Button variant="destructive">Delete Notebook</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Delete Notebook?</DialogTitle>
      <DialogDescription>
        This action cannot be undone.
      </DialogDescription>
    </DialogHeader>
    <DialogFooter>
      <DialogClose asChild>
        <Button variant="outline">Cancel</Button>
      </DialogClose>
      <Button variant="destructive">Delete</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

Form Dialog

<Dialog>
  <DialogTrigger asChild>
    <Button>Rename Notebook</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Rename Notebook</DialogTitle>
      <DialogDescription>
        Enter a new name for your notebook.
      </DialogDescription>
    </DialogHeader>
    <div className="py-4">
      <Input placeholder="Untitled.ipynb" />
    </div>
    <DialogFooter>
      <DialogClose asChild>
        <Button variant="outline">Cancel</Button>
      </DialogClose>
      <Button>Save</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

Notebook Examples

Kernel Selection

<Dialog>
  <DialogTrigger asChild>
    <Button variant="outline">Select Kernel</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Select Kernel</DialogTitle>
      <DialogDescription>Choose a kernel for this notebook.</DialogDescription>
    </DialogHeader>
    <div className="grid gap-2 py-4">
      {kernels.map((kernel) => (
        <KernelOption key={kernel.name} kernel={kernel} />
      ))}
    </div>
  </DialogContent>
</Dialog>

Components

ComponentDescription
DialogRoot component managing open state
DialogTriggerElement that opens the dialog
DialogContentModal container with overlay
DialogHeaderContainer for title and description
DialogFooterContainer for action buttons
DialogTitleAccessible title element
DialogDescriptionAccessible description element
DialogCloseElement that closes the dialog
DialogPortalPortal for rendering outside DOM hierarchy
DialogOverlayBackground overlay

Props

Dialog

PropTypeDefaultDescription
openbooleanControlled open state
defaultOpenbooleanfalseDefault open state
onOpenChange(open: boolean) => voidCallback when open state changes
modalbooleantrueWhether to render as modal

DialogContent

PropTypeDefaultDescription
showCloseButtonbooleantrueShow the close button in top-right
classNamestringAdditional CSS classes

DialogFooter

PropTypeDefaultDescription
showCloseButtonbooleanfalseAdd a close button to footer
classNamestringAdditional CSS classes

DialogTrigger

PropTypeDefaultDescription
asChildbooleanfalseRender as child element using Radix Slot

On this page