Dialog

.dialog is for html dialog.

Applicable Elements

Basic Usage

Hello, this is a dialog.

<dialog class="dialog" id="dialog-element">
  <p>Hello, this is a dialog.</p>
  <form method="dialog"><button class="button">OK</button></form>
</dialog>
<button class="button" onclick="document.getElementById('dialog-element').showModal()">Open Dialog</button>

React Component

React component <Dialog/> is available.
It has following features:

export default function DialogUsageModal() {
  const [open, setOpen] = useState(false);
  return (
    <div>
      <button className="button" type="button" onClick={() => setOpen(true)}>
        Click to set open={"{true}"}
      </button>
      <Dialog
        mode="modal"
        open={open}
        onClickAway={() => { setOpen(false); }}
        onCancel={() => { setOpen(false); }}
      >
        Click away to close
      </Dialog>
    </div>
  );
}

Popover style

export default function DialogUsagePopover() {
  const buttonRef = React.useRef<HTMLButtonElement>(null);
  const [open, setOpen] = useState(false);
  return (
    <div>
      <button ref={buttonRef} className="button" type="button" onClick={() => setOpen(true)}>
        Menu
      </button>
      <Dialog
        mode="popover"
        open={open}
        anchor={buttonRef.current}
        onClickAway={() => { setOpen(false); }}
      >
        <ul style={{ listStyle: "none", padding: 0 }}>
          <li><button type="button" className="menu-item">Buri</button></li>
          <li><button type="button" className="menu-item">Kampachi</button></li>
          <li><button type="button" className="menu-item">Iwashi</button></li>
        </ul>
      </Dialog>
    </div>
  );
}