# ebay/nice-modal-react architecture

> Architecture diagram of the GitHub repository ebay/nice-modal-react, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ebay/nice-modal-react
- Repository: https://github.com/ebay/nice-modal-react

## Overview

NiceModal is a small React utility for globally managing modal visibility, arguments, registration, and completion. A caller shows a modal by component or ID; shared state drives a provider placeholder, which renders registered modal wrappers only when needed. Modal components use the hook to hide, remove, or resolve promise-based interactions, while adapter helpers map state to UI-library dialog props. The runtime is concentrated in one source file, so distinct responsibilities share that path; relationships and capabilities are documented or visible in its excerpt.

Main entry points: [`src/index.tsx`](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx) (Show / Hide API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Modal API"]
  node_modal_api["Show / Hide API<br/>[index.tsx]"]
  node_promise_api["Promise Results<br/>[index.tsx]"]
  node_modal_hook["useModal Hook<br/>[index.tsx]"]
end

subgraph group_runtime["State and Rendering"]
  node_registry["Modal Registry<br/>[index.tsx]"]
  node_provider["Context Provider<br/>[index.tsx]"]
  node_reducer["Modal Reducer<br/>[index.tsx]"]
  node_modal_state[("Modal State<br/>[index.tsx]")]
  node_placeholder["Modal Placeholder<br/>[index.tsx]"]
  node_modal_wrapper["Created Modal Wrapper<br/>[index.tsx]"]
end

subgraph group_adapters["UI Adapters"]
  node_antd_adapter["Ant Design Adapters<br/>[index.tsx]"]
  node_mui_adapter["Material UI Adapter<br/>[index.tsx]"]
end

node_caller(("Application Caller"))
node_dialog_component["UI Dialog Component"]

node_caller -->|"calls show"| node_modal_api
node_modal_api -->|"dispatches updates"| node_modal_state
node_modal_api -->|"creates promises"| node_promise_api
node_provider -->|"provides context"| node_modal_state
node_provider -->|"renders"| node_placeholder
node_placeholder -->|"looks up modals"| node_registry
node_placeholder -->|"renders registered"| node_modal_wrapper
node_modal_wrapper -->|"supplies modal ID"| node_modal_hook
node_modal_hook -->|"calls show / hide"| node_modal_api
node_modal_api -->|"dispatches actions"| node_reducer
node_reducer -->|"updates state"| node_modal_state
node_dialog_component -->|"uses hook"| node_modal_hook
node_dialog_component -->|"hides or resolves"| node_modal_hook
node_antd_adapter -->|"maps dialog props"| node_dialog_component
node_mui_adapter -->|"maps dialog props"| node_dialog_component
node_promise_api -->|"returns promise"| node_caller
node_registry -->|"registers components"| node_placeholder

click node_modal_api "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_promise_api "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_registry "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_provider "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_reducer "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_modal_state "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_placeholder "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_modal_wrapper "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_modal_hook "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_antd_adapter "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"
click node_mui_adapter "https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_modal_api,node_promise_api,node_modal_hook,node_dialog_component toneBlue
class node_registry,node_provider,node_reducer,node_modal_state,node_placeholder,node_modal_wrapper toneAmber
class node_antd_adapter,node_mui_adapter toneMint
class node_caller toneIndigo
```

## Components

### Modal API

- [Show / Hide API](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [Promise Results](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [useModal Hook](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`

### State and Rendering

- [Modal Registry](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [Context Provider](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [Modal Reducer](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [Modal State](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [Modal Placeholder](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [Created Modal Wrapper](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`

### UI Adapters

- [Ant Design Adapters](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`
- [Material UI Adapter](https://github.com/ebay/nice-modal-react/blob/main/src/index.tsx): `src/index.tsx`

### Other components

- **Application Caller**
- **UI Dialog Component**

## Connections

- Application Caller → Show / Hide API: calls show (evidence: `README.md`)
- Show / Hide API → Modal State: dispatches updates (evidence: `src/index.tsx`)
- Show / Hide API → Promise Results: creates promises (evidence: `src/index.tsx`)
- Context Provider → Modal State: provides context (evidence: `src/index.tsx`)
- Context Provider → Modal Placeholder: renders (evidence: `src/index.tsx`)
- Modal Placeholder → Modal Registry: looks up modals (evidence: `src/index.tsx`)
- Modal Placeholder → Created Modal Wrapper: renders registered (evidence: `src/index.tsx`)
- Created Modal Wrapper → useModal Hook: supplies modal ID (evidence: `src/index.tsx`)
- useModal Hook → Show / Hide API: calls show / hide (evidence: `src/index.tsx`)
- Show / Hide API → Modal Reducer: dispatches actions (evidence: `src/index.tsx`)
- Modal Reducer → Modal State: updates state (evidence: `src/index.tsx`)
- UI Dialog Component → useModal Hook: uses hook (evidence: `README.md`)
- UI Dialog Component → useModal Hook: hides or resolves (evidence: `README.md`)
- Ant Design Adapters → UI Dialog Component: maps dialog props (evidence: `src/index.tsx`)
- Material UI Adapter → UI Dialog Component: maps dialog props (evidence: `src/index.tsx`)
- Promise Results → Application Caller: returns promise (evidence: `README.md`)
- Modal Registry → Modal Placeholder: registers components (evidence: `src/index.tsx`)
