@synerise/ds-modal 1.6.4 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/CLAUDE.md +185 -0
  3. package/package.json +9 -8
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.6.6](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.6.5...@synerise/ds-modal@1.6.6) (2026-07-23)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-modal
9
+
10
+ ## [1.6.5](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.6.4...@synerise/ds-modal@1.6.5) (2026-07-16)
11
+
12
+ **Note:** Version bump only for package @synerise/ds-modal
13
+
6
14
  ## [1.6.4](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.6.3...@synerise/ds-modal@1.6.4) (2026-07-09)
7
15
 
8
16
  **Note:** Version bump only for package @synerise/ds-modal
package/CLAUDE.md ADDED
@@ -0,0 +1,185 @@
1
+ # Modal (`@synerise/ds-modal`)
2
+
3
+ > A native React modal dialog with portal-based rendering, predefined sizes, a structured header (title, tabs, actions), a slot-based footer, async handler support, and optional scrollable height capping. No Ant Design dependency.
4
+
5
+ ## Package structure
6
+
7
+ ```
8
+ src/
9
+ Modal.tsx — main component: state, portal, forwardRef
10
+ Modal.types.ts — ModalProps, ModalContentProps, ModalTitleProps, ModalFooterProps, ModalRef, ModalHandle
11
+ Modal.const.ts — SIZE_MAP (size name → pixel width)
12
+ ShowModal.tsx — imperative showModal() API via ds-core's setPortalContent
13
+ ShowModal.spec.tsx — tests for showModal
14
+ Modal.spec.tsx — tests for Modal
15
+ index.ts — public exports
16
+ Elements/
17
+ ModalContent/
18
+ ModalContent.tsx — visual structure: root, mask, scroll wrap, container, body
19
+ ModalContent.styles.ts — ModalRoot, ModalMask, ModalScrollWrap, ModalContainer, ModalBody, Scrollbar
20
+ ModalTitle/
21
+ ModalTitle.tsx — header region: title, description (deprecated), tabs, actions, close button
22
+ ModalTitle.styles.ts
23
+ ModalTitle.spec.tsx
24
+ index.ts
25
+ ModalFooter/
26
+ ModalFooter.tsx — footer region: prefix / cancel / infix / ok / suffix slots
27
+ ModalFooter.styles.ts
28
+ ModalFooter.spec.tsx
29
+ index.ts
30
+ ```
31
+
32
+ ## Public exports
33
+
34
+ ### `Modal` (default export)
35
+
36
+ `forwardRef` component. Renders `ModalContent` via `createPortal` into `getContainer() || document.body`.
37
+
38
+ **Props (ModalProps):**
39
+
40
+ | Prop | Type | Default | Description |
41
+ |------|------|---------|-------------|
42
+ | `open` | `boolean` | `false` | Whether the modal is visible |
43
+ | `destroyOnClose` | `boolean` | `false` | When true, unmounts children on close. When false, keeps mounted but hidden |
44
+ | `title` | `ReactNode` | — | Modal header title |
45
+ | `size` | `ModalSize` | — | Predefined width: `small` (520px), `medium` (792px), `large` (1044px), `extraLarge` (1280px), `fullSize` (100%), `fullScreen` (100% fixed) |
46
+ | `bodyBackground` | `'white' \| 'grey'` | `'white'` | Background colour of the modal body |
47
+ | `blank` | `boolean` | — | Strips header/footer chrome; shows only a close button if `onCancel` is provided |
48
+ | `closable` | `boolean` | `true` | Whether the close button is shown (gated in ModalContent before reaching ModalTitle) |
49
+ | `maskClosable` | `boolean` | `true` | Whether clicking the backdrop closes the modal |
50
+ | `centered` | `boolean` | `false` | Vertically centres the modal |
51
+ | `maxViewportHeight` | `true \| number` | — | Caps height. `true` → 80vh; number → Nvh. Wraps children in scrollbar. Anchors modal to bottom of viewport |
52
+ | `disableScrollbar` | `boolean` | — | Disables scrollbar wrapping from `maxViewportHeight` |
53
+ | `bodyScrollRef` | `MutableRefObject<HTMLDivElement \| null>` | — | Ref to the body's scroll element. With the custom scrollbar active (`maxViewportHeight`, no `disableScrollbar`) it resolves to that scrollbar's scroll node; with `disableScrollbar` it resolves to `ModalBody`. Pass the same ref to a child `VirtualTable`'s `scrollElementRef` so the modal's scroll drives virtualization. When the custom scrollbar is active, the node binds one tick after mount |
54
+ | `headerActions` | `ReactNode` | — | Extra buttons/icons in header action row |
55
+ | `headerBottomBar` | `ReactNode` | — | Full-width bar below the header |
56
+ | `headerTabProps` | `TabsProps` | — | Renders a `Tabs` component in the header |
57
+ | `titleContainerStyle` | `CSSProperties` | — | Inline styles for the title container |
58
+ | `description` | `ReactNode` | — | **Deprecated.** Sub-title with dashed separator |
59
+ | `onOk` | `(e) => void \| Promise` | — | OK button handler; async supported — modal stays open until resolved |
60
+ | `onCancel` | `(e) => void \| Promise` | — | Cancel/close handler; async supported |
61
+ | `afterClose` | `() => void` | — | Called after each close (every `open: true → false` transition). Matches antd Modal semantics. Does not fire on initial mount or on hard unmount of an open modal. |
62
+ | `footer` | `ReactNode \| null` | auto-generated | `null` suppresses footer; custom ReactNode overrides it |
63
+ | `texts` | `{ okButton?; cancelButton? }` | `{ okButton: 'Apply', cancelButton: 'Cancel' }` | Default button labels |
64
+ | `prefix` | `ReactNode` | — | Slot before cancel button |
65
+ | `infix` | `ReactNode` | — | Slot between cancel and OK |
66
+ | `suffix` | `ReactNode` | — | Slot after OK button |
67
+ | `okButton` / `cancelButton` | `ReactNode` | — | Replaces the auto-generated button entirely |
68
+ | `CustomFooterButton` | `ComponentType<ButtonProps>` | `Button` | Custom button component for ok/cancel |
69
+ | `okText` / `cancelText` | `ReactNode` | — | Button labels (override `texts`) |
70
+ | `okType` | `ButtonType` | `'primary'` | Button type for OK |
71
+ | `okButtonProps` / `cancelButtonProps` | `ButtonProps` | — | Extra props for buttons |
72
+ | `bodyStyle` | `CSSProperties` | — | Inline styles for body |
73
+ | `bodyFullWidth` | `boolean` | — | Removes body padding |
74
+ | `ariaLabel` | `string` | — | Accessible name for the dialog; fallback when `title` is absent or non-text |
75
+ | `closeButtonAriaLabel` | `string` | `DS.MODAL.CLOSE` (`'Close'`) | Accessible name for the close button; defaults to the localised translation |
76
+ | `initialFocusRef` | `RefObject<HTMLElement \| null>` | dialog container | Element focused on open. Defaults to the dialog container (announced by its accessible name). Pass a ref only when focusing a specific control is genuinely useful (search/rename dialogs) |
77
+ | `getContainer` | `() => HTMLElement` | `document.body` | Portal mount target |
78
+ | `zIndex` | `number` | theme `zindex-modal` | z-index of the modal root |
79
+
80
+ ### `showModal(props: ModalProps): ModalHandle`
81
+
82
+ Imperative API. Uses `setPortalContent` from `@synerise/ds-core` to render a modal via the DSProvider's `PortalRenderer`. Returns `{ destroy }` to unmount.
83
+
84
+ ### `ModalTitle`
85
+
86
+ Header sub-component. Exported for advanced composition. Props: `Pick<ModalContentProps, 'headerActions' | 'headerTabProps' | 'onCancel' | 'titleContainerStyle' | 'blank' | 'description' | 'title' | 'headerBottomBar'>`.
87
+
88
+ ### `TitleContainer`
89
+
90
+ Exported styled-component — the flex row holding title text and action buttons.
91
+
92
+ ### `ModalFooter`
93
+
94
+ Footer sub-component. Props: `Pick<ModalContentProps, 'footer' | 'prefix' | 'infix' | 'suffix' | 'okButton' | 'cancelButton' | 'CustomFooterButton' | 'texts' | 'onOk' | 'onCancel' | 'cancelText' | 'okText' | 'cancelButtonProps' | 'okType' | 'okButtonProps'>`.
95
+
96
+ ### Exported types
97
+
98
+ `ModalProps`, `ModalSize`, `ModalContentProps`, `ModalTitleProps`, `ModalFooterProps`, `ModalRef`, `ModalHandle`
99
+
100
+ ## Usage patterns
101
+
102
+ ```tsx
103
+ import Modal, { showModal } from '@synerise/ds-modal';
104
+
105
+ // Basic
106
+ <Modal open={isOpen} title="Edit record" onOk={handleOk} onCancel={handleClose}>
107
+ <p>Content here</p>
108
+ </Modal>
109
+
110
+ // Sized, no auto-footer
111
+ <Modal open={isOpen} title="Large view" size="large" footer={null} onCancel={handleClose}>
112
+ <CustomContent />
113
+ </Modal>
114
+
115
+ // Blank modal
116
+ <Modal open={isOpen} blank onCancel={handleClose} footer={myFooter} bodyStyle={{ padding: 0 }}>
117
+ <MyContent />
118
+ </Modal>
119
+
120
+ // Height-capped scrollable
121
+ <Modal open={isOpen} title="Long list" maxViewportHeight={60} onCancel={handleClose}>
122
+ <LongList />
123
+ </Modal>
124
+
125
+ // Imperative
126
+ const ref = showModal({ title: 'Confirm', onOk: () => ref.destroy() });
127
+
128
+ // Async handlers
129
+ <Modal onOk={async () => { await save(); }} onCancel={async () => { await cleanup(); }} />
130
+
131
+ // Scroll ref
132
+ const ref = useRef<ModalRef>(null);
133
+ <Modal ref={ref} open>{/* content */}</Modal>
134
+ ref.current?.scrollToTop();
135
+
136
+ // VirtualTable virtualizing against the modal's body scroll
137
+ const scrollRef = useRef<HTMLDivElement>(null);
138
+ <Modal open maxViewportHeight bodyScrollRef={scrollRef} onCancel={handleClose}>
139
+ <VirtualTable stickyHeader scrollElementRef={scrollRef} columns={cols} data={data} />
140
+ </Modal>
141
+ ```
142
+
143
+ ## Higher-level modal components
144
+
145
+ Built on top of `Modal` in `@synerise/ds-confirmation`:
146
+
147
+ - **`Confirmation`** — typed dialog (negative/warning/success/informative) with icon, batch-items list, decision radio, related-objects view. Uses `size="small"`, `blank={true}`.
148
+ - **`Prompt`** — minimal variant with free-form content and typed button colour. Uses `size="small"`.
149
+
150
+ ## Rendering architecture
151
+
152
+ `Modal` (`forwardRef`) manages `isOpen` / `hasBeenOpened` state and renders `ModalContent` via `createPortal`. When `hidden` (closed but not destroyed), `ModalContent` applies `display: none` on the same `ModalRoot` element — preserving the React tree structure so children are never unmounted/remounted.
153
+
154
+ DOM structure when visible:
155
+ ```
156
+ document.body (portal target)
157
+ └─ ModalRoot (position: absolute, z-index from theme)
158
+ ├─ ModalMask (position: fixed, full viewport, semi-transparent)
159
+ └─ ModalScrollWrap (position: fixed, full viewport, overflow: auto)
160
+ └─ ModalContainer (absolute or fixed, sized, centered)
161
+ ├─ ModalTitle (header: title, tabs, actions, close button)
162
+ ├─ ModalBody (content, optional grey background)
163
+ └─ ModalFooter (prefix / cancel / infix / ok / suffix)
164
+ ```
165
+
166
+ ## Implementation notes
167
+
168
+ - **Close button:** Rendered by `ModalTitle` when `onCancel` is provided and `closable !== false`. `closable` is evaluated in `ModalContent` which gates `onCancel` before passing to `ModalTitle`.
169
+ - **Title render condition:** Header renders when at least one of `title`, `description`, `headerTabProps` is truthy. `headerBottomBar` renders independently.
170
+ - **Footer render logic:** `footer={null}` suppresses entirely. Explicit `footer` value overrides auto-generated `ModalFooter`. Omitted `footer` renders the default.
171
+ - **`fullScreen`** positions the modal `fixed` covering the viewport; body scrolls via `overflow: scroll`.
172
+ - **`maxViewportHeight`** anchors the modal to the bottom of the viewport (sheet-style), not the centre.
173
+ - **Async handlers:** Both `onOk` and `onCancel` can return `Promise`. `onCancel` awaits the promise then calls `closeModal()`. `onOk` resolves then calls `closeModal()` only if the handler was detected as promise-returning via `'then' in onOk`.
174
+ - **Accessibility:** `ModalContainer` carries `role="dialog"` + `aria-modal`. `ModalContent` generates two ids with React's `useId()` — `titleId` and `descriptionId` — passed to `ModalTitle` which applies them to `S.Title` (the `<h3>`) and `S.Description`. The dialog references them via `aria-labelledby` (when `title` is set) and `aria-describedby` (when `description` is set); `aria-label` falls back to the `ariaLabel` prop when there is no title. Both close buttons (header and `blank`) get `aria-label` from `closeButtonAriaLabel`, falling back to the localised `DS.MODAL.CLOSE` message (`useIntl().formatMessage`, default `'Close'`); `react-intl` is a peer dependency. Focus trap/restore is handled by `useFocusTrap`; `Escape` closes via `handleKeyDown`. **Initial focus:** on open, focus moves to the `ModalContainer` (`role="dialog"`, `tabIndex={-1}`) itself — screen readers announce the dialog's accessible name + role and no cursor lands in a non-critical field. This satisfies the WAI-ARIA APG Dialog pattern (focus must move *into* the dialog, but not necessarily onto the first focusable element). Consumers can override the target with `initialFocusRef` (e.g. focus a search field); it is passed straight to `useFocusTrap`'s `initialFocus` option.
175
+
176
+ ## Key dependencies
177
+
178
+ - `@synerise/ds-button` — close button in header, ok/cancel in footer
179
+ - `@synerise/ds-icon` — `CloseM` icon
180
+ - `@synerise/ds-tabs` — optional tab bar via `headerTabProps`
181
+ - `@synerise/ds-scrollbar` — wraps children when `maxViewportHeight` is set
182
+ - `@synerise/ds-typography` — `Typography.Title` for the modal title
183
+ - `@synerise/ds-core` (peer) — `setPortalContent` for `showModal`, `renderWithProvider` for tests
184
+ - `styled-components` (peer) — all styling
185
+ - `react` (peer) — `createPortal`, `forwardRef`, `useImperativeHandle`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-modal",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "Modal UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -17,6 +17,7 @@
17
17
  "files": [
18
18
  "/dist",
19
19
  "CHANGELOG.md",
20
+ "CLAUDE.md",
20
21
  "README.md",
21
22
  "package.json",
22
23
  "LICENSE.md"
@@ -38,12 +39,12 @@
38
39
  "sideEffects": false,
39
40
  "types": "dist/index.d.ts",
40
41
  "dependencies": {
41
- "@synerise/ds-button": "^1.5.33",
42
- "@synerise/ds-icon": "^1.18.4",
43
- "@synerise/ds-scrollbar": "^1.5.1",
44
- "@synerise/ds-tabs": "^1.2.4",
45
- "@synerise/ds-typography": "^1.1.26",
46
- "@synerise/ds-utils": "^1.10.1"
42
+ "@synerise/ds-button": "^1.5.35",
43
+ "@synerise/ds-icon": "^1.18.5",
44
+ "@synerise/ds-scrollbar": "^1.5.2",
45
+ "@synerise/ds-tabs": "^1.2.6",
46
+ "@synerise/ds-typography": "^1.1.27",
47
+ "@synerise/ds-utils": "^1.10.2"
47
48
  },
48
49
  "devDependencies": {
49
50
  "vitest": "4"
@@ -54,5 +55,5 @@
54
55
  "react-intl": ">=3.12.0 <= 6.8",
55
56
  "styled-components": "^5.3.3"
56
57
  },
57
- "gitHead": "5c90008871be36fb52553a2ed3a633acf5db5b3b"
58
+ "gitHead": "d0a43cc43d8528a36f105aceea52ab470edb71d9"
58
59
  }