Skip to content
Ginga UI
Ginga UI
日本語

Getting started

  • Overview
  • Quick start
  • Theme generation
  • Custom rendering
  • All components

Forms

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

Display

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

Typography

  • Heading
  • Paragraph

Navigation

  • Anchor

Layout

  • Box

Resources

  • Changelog
  • GitHub (opens in a new tab)

Logo: Twemoji (opens in a new tab) (CC-BY 4.0)

Dialog

A modal dialog with role="dialog". Use it for content the user works with at their own pace, such as forms, details, and notices. For confirmations that interrupt the user and require an immediate answer, use AlertDialog.

View in Storybook (opens in a new tab)

Installation

import { Dialog } from "@ginga-ui/core";

Basic usage

A simple dialog example.

dialog.tsx
dialog.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import { PanelTop, X } from "lucide-react";
import styles from "./dialog.module.css";

export function BasicExample() {
  return (
    <DialogTrigger>
      <Button variant="filled" startIcon={<PanelTop />}>
        Open dialog
      </Button>
      <Modal>
        <Dialog>
          <DialogTitle>Welcome</DialogTitle>
          <p>This is a basic dialog.</p>
          <div className={styles.actions}>
            <Button slot="close" variant="outline" startIcon={<X />}>
              Close
            </Button>
          </div>
        </Dialog>
      </Modal>
    </DialogTrigger>
  );
}

With a form

An example of a form inside a dialog. Passing a function as children gives you close, which closes the dialog on submit.

dialog.tsx
dialog.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, FormControl, Input, Modal } from "@ginga-ui/core";
import { Plus, UserPlus } from "lucide-react";
import styles from "./dialog.module.css";

export function FormExample() {
  return (
    <DialogTrigger>
      <Button variant="filled" startIcon={<UserPlus />}>
        Sign up
      </Button>
      <Modal>
        <Dialog>
          {({ close }) => (
            <form
              onSubmit={(e) => {
                e.preventDefault();
                close();
              }}
            >
              <DialogTitle>Create account</DialogTitle>
              <div className={styles.formFields}>
                <FormControl label="Name">
                  <Input type="text" autoComplete="name" />
                </FormControl>
                <FormControl label="Email address">
                  <Input type="email" autoComplete="email" />
                </FormControl>
                <FormControl label="Password">
                  <Input type="password" autoComplete="new-password" />
                </FormControl>
              </div>
              <div className={styles.actions}>
                <Button slot="close" variant="outline">
                  Cancel
                </Button>
                <Button type="submit" variant="filled" startIcon={<Plus />}>
                  Create
                </Button>
              </div>
            </form>
          )}
        </Dialog>
      </Modal>
    </DialogTrigger>
  );
}

Notice

A dialog that shows information to read. For confirmations that interrupt the user and require an immediate answer, use AlertDialog instead.

dialog.tsx
dialog.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import { Check, Megaphone } from "lucide-react";
import styles from "./dialog.module.css";

export function NoticeExample() {
  return (
    <DialogTrigger>
      <Button variant="outline" startIcon={<Megaphone />}>
        Important notice
      </Button>
      <Modal>
        <Dialog>
          <DialogTitle>System maintenance</DialogTitle>
          <p>
            System maintenance is scheduled for December 20, 2024, from 2:00 to
            4:00 AM. The service will be unavailable during this time.
          </p>
          <div className={styles.actions}>
            <Button slot="close" variant="filled" startIcon={<Check />}>
              Got it
            </Button>
          </div>
        </Dialog>
      </Modal>
    </DialogTrigger>
  );
}

Props

DialogTrigger

Accepts the props of React Aria's DialogTrigger (opens in a new tab).

Modal

NameTypeDefaultDescription
dismissablebooleanfalseCloses the modal when the user clicks outside it.
overlayClassNamestring-Class name added to the overlay behind the modal.
classNamestring | ((renderProps) => string)-Class name added to the modal element, not the overlay.
render(props, renderProps) => ReactElement-Replaces the modal element. Like className, it applies to the modal, not the overlay.

Also accepts the props of React Aria's ModalOverlay (opens in a new tab).

Dialog

Accepts the props of React Aria's Dialog (opens in a new tab).

DialogTitle

Accepts the props of React Aria's Heading (opens in a new tab).