Lunar Kit LogoLunar Kit
Components

Dialog

A modal dialog that interrupts the user with important content and expects a response.

Demo
Code
Open Dialog

Installation

lunar add dialog

Usage

import {
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
} from '@/components/ui/dialog';

Basic Usage

<Dialog>
<DialogTrigger>
  <Button>Open Dialog</Button>
</DialogTrigger>
<DialogContent>
  <DialogHeader>
    <DialogTitle>Dialog Title</DialogTitle>
    <DialogDescription>
      This is the dialog description.
    </DialogDescription>
  </DialogHeader>
  <DialogFooter>
    <DialogClose>
      <Button variant="outline">Cancel</Button>
    </DialogClose>
    <Button>Continue</Button>
  </DialogFooter>
</DialogContent>
</Dialog>

Controlled State

const [open, setOpen] = useState(false);
 
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger>
  <Button>Open Dialog</Button>
</DialogTrigger>
<DialogContent>
  <DialogHeader>
    <DialogTitle>Controlled Dialog</DialogTitle>
    <DialogDescription>
      This dialog's state is controlled externally.
    </DialogDescription>
  </DialogHeader>
  <DialogFooter>
    <Button onPress={() => setOpen(false)}>Close</Button>
  </DialogFooter>
</DialogContent>
</Dialog>
 
{/* Open programmatically */}
<Button onPress={() => setOpen(true)}>
Open from outside
</Button>

With Form Content

<Dialog>
<DialogTrigger>
  <Button>Edit Profile</Button>
</DialogTrigger>
<DialogContent>
  <DialogHeader>
    <DialogTitle>Edit Profile</DialogTitle>
    <DialogDescription>
      Make changes to your profile here.
    </DialogDescription>
  </DialogHeader>
  
  <View className="gap-4 py-4">
    <Input
      label="Name"
      value={name}
      onChangeText={setName}
    />
    <Input
      label="Email"
      value={email}
      onChangeText={setEmail}
    />
  </View>
  
  <DialogFooter>
    <DialogClose>
      <Button variant="outline">Cancel</Button>
    </DialogClose>
    <Button onPress={handleSave}>Save Changes</Button>
  </DialogFooter>
</DialogContent>
</Dialog>

Confirmation Dialog

export function ConfirmDialog({ onConfirm, onCancel }) {
return (
  <Dialog>
    <DialogTrigger>
      <Button variant="destructive">Delete Account</Button>
    </DialogTrigger>
    <DialogContent>
      <DialogHeader>
        <DialogTitle>Are you sure?</DialogTitle>
        <DialogDescription>
          This action cannot be undone. This will permanently delete your
          account and remove your data from our servers.
        </DialogDescription>
      </DialogHeader>
      <DialogFooter>
        <DialogClose>
          <Button variant="outline" onPress={onCancel}>
            Cancel
          </Button>
        </DialogClose>
        <Button variant="destructive" onPress={onConfirm}>
          Delete
        </Button>
      </DialogFooter>
    </DialogContent>
  </Dialog>
);
}

API Reference

Dialog

Root component that manages dialog state.

PropTypeDefaultDescription
openbooleanControlled open state
onOpenChange(open: boolean) => voidCallback when state changes
childrenReactNodeRequiredDialog content

DialogTrigger

Button that opens the dialog.

PropTypeDefaultDescription
childrenReactNodeRequiredTrigger element

DialogContent

The modal content container.

PropTypeDefaultDescription
childrenReactNodeRequiredDialog content
classNamestringAdditional classes

DialogHeader

Container for title and description.

PropTypeDefaultDescription
childrenReactNodeRequiredHeader content
classNamestringAdditional classes

DialogTitle

The dialog title.

PropTypeDefaultDescription
childrenReactNodeRequiredTitle text
classNamestringAdditional classes

DialogDescription

Description text below the title.

PropTypeDefaultDescription
childrenReactNodeRequiredDescription text
classNamestringAdditional classes

DialogFooter

Container for action buttons.

PropTypeDefaultDescription
childrenReactNodeRequiredFooter content
classNamestringAdditional classes

DialogClose

Closes the dialog when pressed.

PropTypeDefaultDescription
childrenReactNodeRequiredClose trigger

On this page