Modal

LabelNavigation Menu

Animated, focus-trapped, closes on Escape.

Installation

pnpm add krz-ui

Usage

import { useState } from "react";
import { Button, Modal } from "krz-ui";
export function DeleteProject() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button variant="danger" onClick={() => setOpen(true)}>
        Delete project
      </Button>

      <Modal
        open={open}
        onClose={() => setOpen(false)}
        role="alertdialog"
        title="Delete project?"
        description="This action cannot be undone."
        footer={
          <>
            <Button variant="ghost" onClick={() => setOpen(false)}>
              Cancel
            </Button>
            <Button
              variant="danger"
              onClick={() => {
                deleteProject();
                setOpen(false);
              }}
            >
              Delete
            </Button>
          </>
        }
      />
    </>
  );
}

API Reference

PropTypeDescription
openbooleanWhether the modal is visible.
onClose() => voidCalled on Escape, overlay click or close button.
title / descriptionReactNodeHeader content.
footerReactNodeActions at the bottom.
size"sm" | "md" | "lg" | "full"Panel width.
role"dialog" | "alertdialog"Use "alertdialog" for confirmations that need a response.
closeOnOverlayClick / closeOnEscbooleanAllow closing by backdrop click or Escape. Default true.
hideCloseButtonbooleanHide the × button in the header.
className / style / ref—All go to the dialog panel. Style the backdrop with classNames.overlay. See Customization.
classNames{ root?, overlay?, header?, title?, description?, close?, body?, footer? }Extra classes for inner parts.