Modal
Modal blocks for confirmation, focused forms, and critical decisions.
@duskmoon-dev/components/modal Usage
When to use
- Use it immediately after user actions or system checks that need visible confirmation.
- Choose the least interruptive feedback surface that still makes the state clear.
Implementation notes
Features
Covers transient, inline, or blocking feedback patterns for user actions and system status.
Shows how the component keeps next actions visible after success, warning, or failure states.
Modal is most often configured through `open`, `defaultOpen`, `title`, `content`.
Renders open modal with title and children
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and Modal from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function Example() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Renders open modal with title and children
test-backedModal scenario from the component test coverage: renders open modal with title and children.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalRendersOpenModalWithDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Supports uncontrolled defaultOpen and close button
test-backedModal scenario from the component test coverage: supports uncontrolled defaultopen and close button.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalSupportsUncontrolledDefaultOpenAndDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Calls ok and cancel callbacks from default footer
test-backedModal scenario from the component test coverage: calls ok and cancel callbacks from default footer.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalCallsOkAndCancelDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Supports content, custom footer, width, centered, and custom classes
test-backedModal scenario from the component test coverage: supports content, custom footer, width, centered, and custom classes.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalSupportsContentCustomFooterDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Honors maskClosable and closable flags
test-backedModal scenario from the component test coverage: honors maskclosable and closable flags.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalHonorsMaskClosableAndClosableDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Supports destroyOnClose and afterOpenChange
test-backedModal scenario from the component test coverage: supports destroyonclose and afteropenchange.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalSupportsDestroyOnCloseAndAfterOpenChangeDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Applies confirmLoading to ok button
test-backedModal scenario from the component test coverage: applies confirmloading to ok button.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalAppliesConfirmLoadingToOkDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Forwards dialog ref and native props
test-backedModal scenario from the component test coverage: forwards dialog ref and native props.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalForwardsDialogRefAndDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Provides static service placeholders
test-backedModal scenario from the component test coverage: provides static service placeholders.
import "@duskmoon-dev/components/styles.css";
import { Modal } from "@duskmoon-dev/components/modal";
export function ModalProvidesStaticServicePlaceholdersDemo() {
return (<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>
</div>
<div data-theme="moonlight">
<Modal
open
title="Release checklist"
width={420}
onOk={() => console.log("ok")}
onCancel={() => console.log("cancel")}
>
Review component styles before publishing the package.
</Modal>
</div> API
The API reference below lists every parsed exported type or interface for Modal. Start with `open`, `defaultOpen`, `title`, `content` for common usage.
packages/components/src/components/modal/Modal.types.ts
Scenarios: packages/components/src/components/modal/Modal.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
open | boolean | No | open configures Modal. |
defaultOpen | boolean | No | defaultOpen configures Modal. |
title | ReactNode | No | title configures Modal. |
children | ReactNode | No | children configures Modal. |
content | ReactNode | No | content configures Modal. |
footer | ReactNode | null | No | footer configures Modal. |
onOk | (event: MouseEvent<HTMLButtonElement>) => void | No | onOk configures Modal. |
onCancel | (event: MouseEvent<HTMLButtonElement | HTMLDivElement>) => void | No | onCancel configures Modal. |
okText | ReactNode | No | okText configures Modal. |
cancelText | ReactNode | No | cancelText configures Modal. |
confirmLoading | boolean | No | confirmLoading configures Modal. |
closable | boolean | No | closable configures Modal. |
maskClosable | boolean | No | maskClosable configures Modal. |
width | CSSProperties["width"] | No | width configures Modal. |
centered | boolean | No | centered configures Modal. |
destroyOnClose | boolean | No | destroyOnClose configures Modal. |
afterOpenChange | (open: boolean) => void | No | afterOpenChange configures Modal. |
className | string | No | className configures Modal. |
maskClassName | string | No | maskClassName configures Modal. |
closeIcon | ReactNode | No | closeIcon configures Modal. |
| Prop | Type | Required | Description |
|---|---|---|---|
title | ReactNode | No | title configures Modal. |
content | ReactNode | No | content configures Modal. |
onOk | () => void | No | onOk configures Modal. |
onCancel | () => void | No | onCancel configures Modal. |
okText | ReactNode | No | okText configures Modal. |
cancelText | ReactNode | No | cancelText configures Modal. |
| Prop | Type | Required | Description |
|---|---|---|---|
destroy | () => void | Yes | destroy configures Modal. |
update | (config: ModalFuncProps) => void | Yes | update configures Modal. |
| Prop | Type | Required | Description |
|---|---|---|---|
confirm | (config: ModalFuncProps) => ModalFuncHandle | Yes | confirm configures Modal. |
info | (config: ModalFuncProps) => ModalFuncHandle | Yes | info configures Modal. |
success | (config: ModalFuncProps) => ModalFuncHandle | Yes | success configures Modal. |
error | (config: ModalFuncProps) => ModalFuncHandle | Yes | error configures Modal. |
warning | (config: ModalFuncProps) => ModalFuncHandle | Yes | warning configures Modal. |
destroyAll | () => void | Yes | destroyAll configures Modal. |