solid-tom-ui 1.0.10 → 1.0.14

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 (120) hide show
  1. package/README.md +246 -246
  2. package/dist/README.md +246 -246
  3. package/dist/components/avatar/avatar.js.map +1 -1
  4. package/dist/components/badge/badge.js.map +1 -1
  5. package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
  6. package/dist/components/button/button.js.map +1 -1
  7. package/dist/components/carousel/carousel.js.map +1 -1
  8. package/dist/components/chat-bubble/chatBubble.js.map +1 -1
  9. package/dist/components/checkbox/checkbox.js.map +1 -1
  10. package/dist/components/collapse/collapse.js.map +1 -1
  11. package/dist/components/context-menu/context-menu.js.map +1 -1
  12. package/dist/components/context-menu/context-menu.store.js.map +1 -1
  13. package/dist/components/divider/divider.js.map +1 -1
  14. package/dist/components/dropdown/dropdown.js.map +1 -1
  15. package/dist/components/dropdown/dropdown.store.js.map +1 -1
  16. package/dist/components/float-button/float-button.js.map +1 -1
  17. package/dist/components/hover-3d-image/hover-3d-image.js.map +1 -1
  18. package/dist/components/image-preview/image-preview.js.map +1 -1
  19. package/dist/components/input/input.js.map +1 -1
  20. package/dist/components/input/input.utils.js.map +1 -1
  21. package/dist/components/input/variants/input-color.js.map +1 -1
  22. package/dist/components/input/variants/input-date.js.map +1 -1
  23. package/dist/components/input/variants/input-number.d.ts.map +1 -1
  24. package/dist/components/input/variants/input-number.js +1 -1
  25. package/dist/components/input/variants/input-number.js.map +1 -1
  26. package/dist/components/input/variants/input-otp.js.map +1 -1
  27. package/dist/components/input/variants/input-password.js.map +1 -1
  28. package/dist/components/input/variants/input-radio.js.map +1 -1
  29. package/dist/components/input/variants/input-range.js.map +1 -1
  30. package/dist/components/input/variants/input-text.d.ts.map +1 -1
  31. package/dist/components/input/variants/input-text.js +1 -1
  32. package/dist/components/input/variants/input-text.js.map +1 -1
  33. package/dist/components/input/variants/input-textarea.js.map +1 -1
  34. package/dist/components/loading/loading.js.map +1 -1
  35. package/dist/components/mansory/mansory.js.map +1 -1
  36. package/dist/components/menu/menu.js.map +1 -1
  37. package/dist/components/menu/menu.types.d.ts +2 -3
  38. package/dist/components/menu/menu.types.d.ts.map +1 -1
  39. package/dist/components/modal/modal.js.map +1 -1
  40. package/dist/components/modal/modalContext.js.map +1 -1
  41. package/dist/components/pagination/pagination.js.map +1 -1
  42. package/dist/components/progress-bar/progress-bar.js.map +1 -1
  43. package/dist/components/qr-code/qr-code.js.map +1 -1
  44. package/dist/components/select/select.js.map +1 -1
  45. package/dist/components/select-zone/select-zone.js.map +1 -1
  46. package/dist/components/skeleton/skeleton.js.map +1 -1
  47. package/dist/components/slider/slider.js.map +1 -1
  48. package/dist/components/splitter/splitter.js.map +1 -1
  49. package/dist/components/steps/steps.js.map +1 -1
  50. package/dist/components/swap/swap.js.map +1 -1
  51. package/dist/components/switch/switch.js.map +1 -1
  52. package/dist/components/tab/tab.js.map +1 -1
  53. package/dist/components/table/table.js.map +1 -1
  54. package/dist/components/timeline/timeline.js.map +1 -1
  55. package/dist/components/toast/icons/ErrorIcon.js.map +1 -1
  56. package/dist/components/toast/icons/IconCircle.js.map +1 -1
  57. package/dist/components/toast/icons/InfoIcon.js.map +1 -1
  58. package/dist/components/toast/icons/LoaderIcon.js.map +1 -1
  59. package/dist/components/toast/icons/SuccessIcon.js.map +1 -1
  60. package/dist/components/toast/icons/WarningIcon.js.map +1 -1
  61. package/dist/components/toast/toast.js.map +1 -1
  62. package/dist/components/toast/toast.store.js.map +1 -1
  63. package/dist/components/tooltip/tooltip.js.map +1 -1
  64. package/dist/components/tour/tour.js.map +1 -1
  65. package/dist/components/upload/upload.js.map +1 -1
  66. package/dist/components/z-index/z-index.context.js.map +1 -1
  67. package/dist/components/z-index/z-index.js.map +1 -1
  68. package/dist/components/z-index/z-index.store.js.map +1 -1
  69. package/dist/components/z-index/z-index.types.js.map +1 -1
  70. package/dist/package.json +1 -1
  71. package/dist/skill/avatar.skill.md.txt +255 -255
  72. package/dist/skill/badge.skill.md.txt +223 -223
  73. package/dist/skill/breadcrumb.skill.md.txt +177 -177
  74. package/dist/skill/button.skill.md.txt +198 -198
  75. package/dist/skill/carousel.skill.md.txt +406 -406
  76. package/dist/skill/chat-bubble.skill.md.txt +342 -342
  77. package/dist/skill/checkbox.skill.md.txt +326 -326
  78. package/dist/skill/code-preview.skill.md.txt +240 -240
  79. package/dist/skill/collapse.skill.md.txt +329 -329
  80. package/dist/skill/context-menu.skill.md.txt +233 -233
  81. package/dist/skill/diff.skill.md.txt +244 -244
  82. package/dist/skill/divider.skill.md.txt +151 -151
  83. package/dist/skill/doc.skill.md.txt +191 -191
  84. package/dist/skill/drawer.skill.md.txt +157 -157
  85. package/dist/skill/dropdown.skill.md.txt +198 -198
  86. package/dist/skill/float-button.skill.md.txt +315 -315
  87. package/dist/skill/hover-3d-image.skill.md.txt +120 -120
  88. package/dist/skill/iframe.skill.md.txt +114 -114
  89. package/dist/skill/image-preview.skill.md.txt +162 -162
  90. package/dist/skill/indicator.skill.md.txt +60 -60
  91. package/dist/skill/input.skill.md.txt +489 -489
  92. package/dist/skill/loading.skill.md.txt +127 -127
  93. package/dist/skill/menu.skill.md.txt +476 -476
  94. package/dist/skill/modal.skill.md.txt +359 -359
  95. package/dist/skill/pagination.skill.md.txt +405 -405
  96. package/dist/skill/progress-bar.skill.md.txt +207 -207
  97. package/dist/skill/qr-code.skill.md.txt +136 -136
  98. package/dist/skill/rating.skill.md.txt +167 -167
  99. package/dist/skill/select-zone.skill.md.txt +93 -93
  100. package/dist/skill/select.skill.md.txt +663 -663
  101. package/dist/skill/skeleton.skill.md.txt +192 -192
  102. package/dist/skill/slider.skill.md.txt +404 -404
  103. package/dist/skill/splitter.skill.md.txt +411 -411
  104. package/dist/skill/steps.skill.md.txt +264 -264
  105. package/dist/skill/swap.skill.md.txt +139 -139
  106. package/dist/skill/switch.skill.md.txt +191 -191
  107. package/dist/skill/tab.skill.md.txt +484 -484
  108. package/dist/skill/table.example.header.md.txt +666 -666
  109. package/dist/skill/table.skill.md.txt +1407 -1407
  110. package/dist/skill/text-rotate.skill.md.txt +186 -186
  111. package/dist/skill/timeline.skill.md.txt +247 -247
  112. package/dist/skill/toast.skill.md.txt +531 -531
  113. package/dist/skill/tooltip.skill.md.txt +222 -222
  114. package/dist/skill/tour.skill.md.txt +156 -156
  115. package/dist/skill/upload.skill.md.txt +358 -358
  116. package/dist/utils/cn.js.map +1 -1
  117. package/dist/utils/element-tracker.js.map +1 -1
  118. package/dist/utils/helper.js.map +1 -1
  119. package/dist/utils/hoc.js.map +1 -1
  120. package/package.json +132 -133
@@ -1,359 +1,359 @@
1
- ## COMPONENT IDENTITY
2
- - **Import**: `import { Modal, createModal, closeAllModals } from 'solid-tom-ui';`
3
- - **Exports**: `Modal` (declarative JSX), `createModal` (imperative API), `closeAllModals`, `ModalType` (type export)
4
- - **Framework**: SolidJS
5
- - **Purpose**: Modal dialog built on native `<dialog>` — supports both declarative JSX and imperative `createModal()` API
6
-
7
- ---
8
-
9
- ## PROP REFERENCE (`ModalType`)
10
-
11
- | Prop | Type | Default | Description |
12
- |---|---|---|---|
13
- | `open` | `boolean` | `true` | Controls visibility. `true` → calls `dialog.showModal()`. `false` → calls `dialog.close()`. |
14
- | `onClose` | `() => void` | `() => {}` | Required callback — fired on native `close` event (ESC, backdrop click, close button). **Must set `open` to `false` here in controlled usage.** |
15
- | `header` | `SolidComponent` | Modal ID fallback | JSX rendered inside `.sui-modal-header`. |
16
- | `body` | `SolidComponent` | Fallback paragraph | JSX rendered inside `.sui-modal-body`. Pass as function `() => <JSX>` to defer evaluation. |
17
- | `footer` | `SolidComponent` | `<></>` | JSX rendered inside `.sui-modal-footer`. Pass as function `() => <JSX>` or as static JSX. |
18
- | `width` | `string` | — | Sets both `width` and `min-width` on `.modal-box`. Accepts any CSS size (`'500px'`, `'80vw'`, etc.). |
19
- | `closeOnOutsideClick` | `boolean` | `true` | Renders a `<form method="dialog">` backdrop. Click outside `.modal-box` closes the dialog. |
20
- | `closable` | `boolean` | `true` | Show/hide the X close button in the top-right corner of `.modal-box`. |
21
- | `mask` | `boolean \| { enabled: boolean; blur: boolean }` | `true` | Overlay behind the modal. `true` → default overlay + blur. `false` → no overlay. `{ enabled: true, blur: false }` → overlay without blur. |
22
- | `preRender` | `boolean` | `false` | If `true`, component is always mounted in the DOM regardless of `open`. If `false`, component unmounts when `open` is `false` (via `<Show>`). |
23
- | `animate` | `{ name: AnimateType } & AnimationConfig` | `{ name: 'puffInCenter', duration: '300ms' }` | CSS animation played on `.modal-box` when modal opens. Set `name: 'none'` to disable. |
24
- | `class` | `Partial<Record<'dialog' \| 'modal' \| 'closeButton', string>>` | — | Merge custom classes onto specific elements. |
25
-
26
- ### `AnimateType` values
27
-
28
- ```
29
- 'none' | 'lightSpeedInRight' | 'lightSpeedInLeft' | 'fadeIn' | 'fadeInLeft'
30
- | 'fadeInRight' | 'fadeInDown' | 'fadeInUp' | 'bounceIn' | 'scaleInCenter'
31
- | 'slideInFwdCenter' | 'slideInBck' | 'tiltIn' | 'swingInRightBck'
32
- | 'puffInCenter' | 'scaleInBl'
33
- ```
34
-
35
- ### `AnimationConfig` fields (all optional)
36
-
37
- | Field | Type | Default |
38
- |---|---|---|
39
- | `duration` | `` `${number}s` \| `${number}ms` `` | `'1s'` |
40
- | `timingFunction` | `'ease' \| 'ease-in' \| 'ease-out' \| ...` | `'ease'` |
41
- | `delay` | `TimeUnit` | `'0s'` |
42
- | `iterationCount` | `number \| 'infinite'` | `1` |
43
- | `direction` | `'normal' \| 'reverse' \| 'alternate' \| 'alternate-reverse'` | `'normal'` |
44
- | `fillMode` | `'none' \| 'forwards' \| 'backwards' \| 'both'` | `'none'` |
45
- | `playState` | `'running' \| 'paused'` | `'running'` |
46
-
47
- ---
48
-
49
- ## IMPERATIVE API (`modalContext`)
50
-
51
- ### `createModal(options)`
52
-
53
- ```ts
54
- function createModal(options: Omit<ModalType, 'open' | 'preRender'>): ModalInstance
55
- ```
56
-
57
- - Mounts a `ComponentModal` imperatively into `document.body` via `insert`.
58
- - Returns a `ModalInstance` with a `destroy()` method.
59
- - The modal opens immediately (`isOpen = true`).
60
- - Calling `onClose` in options automatically destroys the instance after 150ms.
61
- - Tracks all active instances internally in `activeModalInstances`.
62
-
63
- ```ts
64
- type ModalInstance = {
65
- destroy: () => void; // Immediately unmounts the modal
66
- };
67
- ```
68
-
69
- ### `closeAllModals()`
70
-
71
- ```ts
72
- function closeAllModals(): void
73
- ```
74
-
75
- - Calls `destroy()` on all currently active modal instances.
76
- - Use for global cleanup (e.g., route changes, session expiration).
77
-
78
- ---
79
-
80
- ## BEHAVIORAL RULES (inferred from implementation)
81
-
82
- ### Controlled pattern
83
-
84
- `Modal` is always **fully controlled**. The parent must:
85
- 1. Hold `open` state via `createSignal`.
86
- 2. Set `open` to `false` inside `onClose`.
87
-
88
- If `onClose` does not update the signal, the dialog closes natively but `open` stays `true` → next render re-opens the dialog.
89
-
90
- ### Native `<dialog>` element
91
-
92
- The component renders a native HTML `<dialog>`. It uses:
93
- - `dialog.showModal()` when `open` becomes `true`.
94
- - `dialog.close()` when `open` becomes `false`.
95
- - The `close` DOM event maps to the `onClose` prop.
96
- - ESC key fires the native `close` event automatically.
97
- - Rendered via `<Portal>` — always mounts to `document.body`, outside component tree.
98
-
99
- ### Stacking / Z-index
100
-
101
- - Each modal gets a unique ID via `createUniqueId()`.
102
- - Active modal IDs are tracked in a module-level signal `modalIds`.
103
- - Overlay (`.modalOverlay`) is only applied to the **topmost** modal (`modalId === modalIds().at(-1)`).
104
- - Lower modals lose the overlay class, keeping the visual stack clean.
105
-
106
- ### `preRender` behavior
107
-
108
- ```
109
- preRender=false (default) → <Show when={open}><Modal /></Show>
110
- → component is unmounted when closed; internal state resets on next open.
111
-
112
- preRender=true → <Modal /> always mounted
113
- → component persists in DOM; internal state preserved between open/close.
114
- ```
115
-
116
- Use `preRender={true}` when:
117
- - Modal content is expensive to re-initialize.
118
- - You need to preserve form state across open/close cycles.
119
-
120
- Use `preRender={false}` (default) when:
121
- - Modal content should reset each time it opens.
122
- - Memory efficiency matters.
123
-
124
- ### Cleanup
125
-
126
- `onCleanup` removes the modal's ID from `modalIds` when the component unmounts. Prevents stale overlay assignments in nested modal scenarios.
127
-
128
- ---
129
-
130
- ## USAGE PATTERNS
131
-
132
- ### 1. Minimal controlled modal
133
-
134
- ```tsx
135
- const [open, setOpen] = createSignal(false);
136
-
137
- <Button onClick={() => setOpen(true)}>Open</Button>
138
- <Modal
139
- open={open()}
140
- onClose={() => setOpen(false)}
141
- body={() => <p>Modal content</p>}
142
- />
143
- ```
144
-
145
- ### 2. With header, body, footer
146
-
147
- ```tsx
148
- <Modal
149
- open={open()}
150
- onClose={() => setOpen(false)}
151
- header={<h2 class="text-lg font-bold">Title</h2>}
152
- body={() => <p>Body content</p>}
153
- footer={
154
- <div class="flex justify-end gap-2">
155
- <Button variant="simple" onClick={() => setOpen(false)}>Cancel</Button>
156
- <Button variant="solid" color="primary" onClick={handleSave}>Save</Button>
157
- </div>
158
- }
159
- />
160
- ```
161
-
162
- ### 3. Custom width
163
-
164
- ```tsx
165
- <Modal
166
- open={open()}
167
- onClose={() => setOpen(false)}
168
- width="900px"
169
- class={{ modal: 'h-[500px]' }}
170
- body={() => <MyLargeContent />}
171
- />
172
- ```
173
-
174
- ### 4. Disable outside click close
175
-
176
- ```tsx
177
- <Modal
178
- open={open()}
179
- onClose={() => setOpen(false)}
180
- closeOnOutsideClick={false}
181
- body={() => <ImportantForm />}
182
- />
183
- ```
184
-
185
- ### 5. No close button
186
-
187
- ```tsx
188
- <Modal
189
- open={open()}
190
- onClose={() => setOpen(false)}
191
- closable={false}
192
- body={() => <div>No X button shown</div>}
193
- />
194
- ```
195
-
196
- ### 6. No overlay / custom mask
197
-
198
- ```tsx
199
- // No overlay at all
200
- <Modal open={open()} onClose={() => setOpen(false)} mask={false} body={() => <div />} />
201
-
202
- // Overlay without blur
203
- <Modal
204
- open={open()}
205
- onClose={() => setOpen(false)}
206
- mask={{ enabled: true, blur: false }}
207
- body={() => <div />}
208
- />
209
- ```
210
-
211
- ### 7. Custom animation
212
-
213
- ```tsx
214
- <Modal
215
- open={open()}
216
- onClose={() => setOpen(false)}
217
- animate={{ name: 'fadeInDown', duration: '200ms', timingFunction: 'ease-out' }}
218
- body={() => <div>Animated</div>}
219
- />
220
-
221
- // Disable animation
222
- <Modal
223
- open={open()}
224
- onClose={() => setOpen(false)}
225
- animate={{ name: 'none' }}
226
- body={() => <div>No animation</div>}
227
- />
228
- ```
229
-
230
- ### 8. Preserve state across open/close (`preRender`)
231
-
232
- ```tsx
233
- <Modal
234
- open={open()}
235
- onClose={() => setOpen(false)}
236
- preRender={true}
237
- body={() => <ExpensiveForm />}
238
- />
239
- ```
240
-
241
- ### 9. Custom classes on inner elements
242
-
243
- ```tsx
244
- <Modal
245
- open={open()}
246
- onClose={() => setOpen(false)}
247
- class={{
248
- dialog: 'my-dialog-class',
249
- modal: 'rounded-2xl shadow-2xl',
250
- closeButton: 'text-red-500',
251
- }}
252
- body={() => <div />}
253
- />
254
- ```
255
-
256
- ### 10. Nested modals (multi-level)
257
-
258
- ```tsx
259
- // Level 1
260
- const [l1, setL1] = createSignal(false);
261
- // Level 2
262
- const [l2, setL2] = createSignal(false);
263
-
264
- <Modal open={l1()} onClose={() => setL1(false)} body={() => (
265
- <>
266
- <Button onClick={() => setL2(true)}>Open L2</Button>
267
- <Modal open={l2()} onClose={() => setL2(false)} body={() => <div>L2 content</div>} preRender={false} />
268
- </>
269
- )} />
270
- ```
271
-
272
- Overlay is only applied to the topmost active modal automatically.
273
-
274
- ### 11. Imperative API — fire-and-forget
275
-
276
- ```tsx
277
- import { createModal } from 'solid-tom-ui';
278
-
279
- function showAlert() {
280
- const modal = createModal({
281
- header: <h2>Alert</h2>,
282
- body: () => <p>Something happened.</p>,
283
- footer: (
284
- <Button onClick={() => modal.destroy()}>OK</Button>
285
- ),
286
- onClose: () => {}, // optional extra cleanup
287
- });
288
- }
289
- ```
290
-
291
- ### 12. Close all modals (e.g., on route change)
292
-
293
- ```tsx
294
- import { closeAllModals } from 'solid-tom-ui';
295
-
296
- onCleanup(() => closeAllModals());
297
- ```
298
-
299
- ---
300
-
301
- ## CSS CLASSES (public API for customization)
302
-
303
- | Class | Applied to |
304
- |---|---|
305
- | `modal` | `<dialog>` root element |
306
- | `modalOverlay` | `<dialog>` when it is the topmost modal and `mask` is active |
307
- | `modal-box` | Inner content container `<div>` |
308
- | `sui-modal-header` | Header slot `<div>` |
309
- | `sui-modal-body` | Body slot `<div>` |
310
- | `sui-modal-footer` | Footer slot `<div>` |
311
-
312
- Use `class={{ dialog: '...', modal: '...', closeButton: '...' }}` prop to append classes to specific elements.
313
-
314
- ---
315
-
316
- ## ANIMATION SYSTEM
317
-
318
- - Animation runs via CSS custom property `--openAnimate` set as inline style on `.modal-box`.
319
- - `renderCSSAnimation(config)` from `@/utils/helper` generates the `animation` shorthand string.
320
- - Animation triggers on `.modal[open] .modal-box` (CSS layer `components`).
321
- - Changing `animate.name` to `'none'` prevents setting `--openAnimate` → no animation.
322
- - Animation only fires on **open**, not on close (native `<dialog>` has no built-in close animation hook).
323
-
324
- ---
325
-
326
- ## CONSTRAINTS & EDGE CASES
327
-
328
- - `onClose` is **required** in practice — without updating `open` signal inside it, the modal will re-open immediately after closing.
329
- - `body`, `header`, `footer` accept `SolidComponent` (i.e., `() => JSX.Element` or `JSX.Element`). Pass expensive subtrees as functions `() => <JSX>` to avoid evaluating them before the modal opens.
330
- - `Portal` renders into `document.body`. The modal is outside any parent's DOM subtree — CSS `overflow: hidden` on ancestors does NOT clip the modal.
331
- - `createModal` does NOT accept `open` or `preRender` — the modal is always immediately open and never pre-renders.
332
- - `createModal` instances must be destroyed manually via `instance.destroy()` or `closeAllModals()` if `onClose` is not configured to auto-destroy.
333
- - Multiple simultaneous `createModal` calls stack correctly — each gets its own `createRoot` reactive scope.
334
- - The `close` DOM event fires **after** the dialog is already visually closed. Do not rely on `onClose` timing for animations.
335
-
336
- ---
337
-
338
- ## DO / DON'T
339
-
340
- **DO**
341
- - Always pair `open={signal()}` with `onClose={() => setSignal(false)}`.
342
- - Pass `body` and expensive content as `() => <JSX>` (function) to defer rendering.
343
- - Use `preRender={true}` when you need to retain form state between open/close cycles.
344
- - Use `createModal` for fire-and-forget alerts, confirmations, or notifications outside the component tree.
345
- - Use `class={{ modal: '...' }}` to control `.modal-box` dimensions (height, border-radius, etc.).
346
- - Import from the barrel: `import { Modal, createModal, closeAllModals } from 'solid-tom-ui'`.
347
-
348
- **DON'T**
349
- - Don't omit `onClose` or leave it as a no-op — the dialog will fight between native closed state and `open` prop.
350
- - Don't use `ComponentModal` directly unless you need the raw unguarded component (no `<Show>` wrapping).
351
- - Don't import `ModalExample` in production — it's a demo component only.
352
- - Don't expect `createModal` instances to auto-cleanup — call `destroy()` or `closeAllModals()` when appropriate.
353
- - Don't nest `<Portal>` inside modal body — the modal itself already renders via `<Portal>`.
354
- - Don't try to control the overlay on lower-level modals — the stacking system handles it automatically via `modalIds`.
355
- ---
356
-
357
- ## Component Conventions
358
-
359
- > **CSS encoding**: internal CSS classes use short encoded names (e.g. `mo01`, `mo02`) per project convention.
1
+ ## COMPONENT IDENTITY
2
+ - **Import**: `import { Modal, createModal, closeAllModals } from 'solid-tom-ui';`
3
+ - **Exports**: `Modal` (declarative JSX), `createModal` (imperative API), `closeAllModals`, `ModalType` (type export)
4
+ - **Framework**: SolidJS
5
+ - **Purpose**: Modal dialog built on native `<dialog>` — supports both declarative JSX and imperative `createModal()` API
6
+
7
+ ---
8
+
9
+ ## PROP REFERENCE (`ModalType`)
10
+
11
+ | Prop | Type | Default | Description |
12
+ |---|---|---|---|
13
+ | `open` | `boolean` | `true` | Controls visibility. `true` → calls `dialog.showModal()`. `false` → calls `dialog.close()`. |
14
+ | `onClose` | `() => void` | `() => {}` | Required callback — fired on native `close` event (ESC, backdrop click, close button). **Must set `open` to `false` here in controlled usage.** |
15
+ | `header` | `SolidComponent` | Modal ID fallback | JSX rendered inside `.sui-modal-header`. |
16
+ | `body` | `SolidComponent` | Fallback paragraph | JSX rendered inside `.sui-modal-body`. Pass as function `() => <JSX>` to defer evaluation. |
17
+ | `footer` | `SolidComponent` | `<></>` | JSX rendered inside `.sui-modal-footer`. Pass as function `() => <JSX>` or as static JSX. |
18
+ | `width` | `string` | — | Sets both `width` and `min-width` on `.modal-box`. Accepts any CSS size (`'500px'`, `'80vw'`, etc.). |
19
+ | `closeOnOutsideClick` | `boolean` | `true` | Renders a `<form method="dialog">` backdrop. Click outside `.modal-box` closes the dialog. |
20
+ | `closable` | `boolean` | `true` | Show/hide the X close button in the top-right corner of `.modal-box`. |
21
+ | `mask` | `boolean \| { enabled: boolean; blur: boolean }` | `true` | Overlay behind the modal. `true` → default overlay + blur. `false` → no overlay. `{ enabled: true, blur: false }` → overlay without blur. |
22
+ | `preRender` | `boolean` | `false` | If `true`, component is always mounted in the DOM regardless of `open`. If `false`, component unmounts when `open` is `false` (via `<Show>`). |
23
+ | `animate` | `{ name: AnimateType } & AnimationConfig` | `{ name: 'puffInCenter', duration: '300ms' }` | CSS animation played on `.modal-box` when modal opens. Set `name: 'none'` to disable. |
24
+ | `class` | `Partial<Record<'dialog' \| 'modal' \| 'closeButton', string>>` | — | Merge custom classes onto specific elements. |
25
+
26
+ ### `AnimateType` values
27
+
28
+ ```
29
+ 'none' | 'lightSpeedInRight' | 'lightSpeedInLeft' | 'fadeIn' | 'fadeInLeft'
30
+ | 'fadeInRight' | 'fadeInDown' | 'fadeInUp' | 'bounceIn' | 'scaleInCenter'
31
+ | 'slideInFwdCenter' | 'slideInBck' | 'tiltIn' | 'swingInRightBck'
32
+ | 'puffInCenter' | 'scaleInBl'
33
+ ```
34
+
35
+ ### `AnimationConfig` fields (all optional)
36
+
37
+ | Field | Type | Default |
38
+ |---|---|---|
39
+ | `duration` | `` `${number}s` \| `${number}ms` `` | `'1s'` |
40
+ | `timingFunction` | `'ease' \| 'ease-in' \| 'ease-out' \| ...` | `'ease'` |
41
+ | `delay` | `TimeUnit` | `'0s'` |
42
+ | `iterationCount` | `number \| 'infinite'` | `1` |
43
+ | `direction` | `'normal' \| 'reverse' \| 'alternate' \| 'alternate-reverse'` | `'normal'` |
44
+ | `fillMode` | `'none' \| 'forwards' \| 'backwards' \| 'both'` | `'none'` |
45
+ | `playState` | `'running' \| 'paused'` | `'running'` |
46
+
47
+ ---
48
+
49
+ ## IMPERATIVE API (`modalContext`)
50
+
51
+ ### `createModal(options)`
52
+
53
+ ```ts
54
+ function createModal(options: Omit<ModalType, 'open' | 'preRender'>): ModalInstance
55
+ ```
56
+
57
+ - Mounts a `ComponentModal` imperatively into `document.body` via `insert`.
58
+ - Returns a `ModalInstance` with a `destroy()` method.
59
+ - The modal opens immediately (`isOpen = true`).
60
+ - Calling `onClose` in options automatically destroys the instance after 150ms.
61
+ - Tracks all active instances internally in `activeModalInstances`.
62
+
63
+ ```ts
64
+ type ModalInstance = {
65
+ destroy: () => void; // Immediately unmounts the modal
66
+ };
67
+ ```
68
+
69
+ ### `closeAllModals()`
70
+
71
+ ```ts
72
+ function closeAllModals(): void
73
+ ```
74
+
75
+ - Calls `destroy()` on all currently active modal instances.
76
+ - Use for global cleanup (e.g., route changes, session expiration).
77
+
78
+ ---
79
+
80
+ ## BEHAVIORAL RULES (inferred from implementation)
81
+
82
+ ### Controlled pattern
83
+
84
+ `Modal` is always **fully controlled**. The parent must:
85
+ 1. Hold `open` state via `createSignal`.
86
+ 2. Set `open` to `false` inside `onClose`.
87
+
88
+ If `onClose` does not update the signal, the dialog closes natively but `open` stays `true` → next render re-opens the dialog.
89
+
90
+ ### Native `<dialog>` element
91
+
92
+ The component renders a native HTML `<dialog>`. It uses:
93
+ - `dialog.showModal()` when `open` becomes `true`.
94
+ - `dialog.close()` when `open` becomes `false`.
95
+ - The `close` DOM event maps to the `onClose` prop.
96
+ - ESC key fires the native `close` event automatically.
97
+ - Rendered via `<Portal>` — always mounts to `document.body`, outside component tree.
98
+
99
+ ### Stacking / Z-index
100
+
101
+ - Each modal gets a unique ID via `createUniqueId()`.
102
+ - Active modal IDs are tracked in a module-level signal `modalIds`.
103
+ - Overlay (`.modalOverlay`) is only applied to the **topmost** modal (`modalId === modalIds().at(-1)`).
104
+ - Lower modals lose the overlay class, keeping the visual stack clean.
105
+
106
+ ### `preRender` behavior
107
+
108
+ ```
109
+ preRender=false (default) → <Show when={open}><Modal /></Show>
110
+ → component is unmounted when closed; internal state resets on next open.
111
+
112
+ preRender=true → <Modal /> always mounted
113
+ → component persists in DOM; internal state preserved between open/close.
114
+ ```
115
+
116
+ Use `preRender={true}` when:
117
+ - Modal content is expensive to re-initialize.
118
+ - You need to preserve form state across open/close cycles.
119
+
120
+ Use `preRender={false}` (default) when:
121
+ - Modal content should reset each time it opens.
122
+ - Memory efficiency matters.
123
+
124
+ ### Cleanup
125
+
126
+ `onCleanup` removes the modal's ID from `modalIds` when the component unmounts. Prevents stale overlay assignments in nested modal scenarios.
127
+
128
+ ---
129
+
130
+ ## USAGE PATTERNS
131
+
132
+ ### 1. Minimal controlled modal
133
+
134
+ ```tsx
135
+ const [open, setOpen] = createSignal(false);
136
+
137
+ <Button onClick={() => setOpen(true)}>Open</Button>
138
+ <Modal
139
+ open={open()}
140
+ onClose={() => setOpen(false)}
141
+ body={() => <p>Modal content</p>}
142
+ />
143
+ ```
144
+
145
+ ### 2. With header, body, footer
146
+
147
+ ```tsx
148
+ <Modal
149
+ open={open()}
150
+ onClose={() => setOpen(false)}
151
+ header={<h2 class="text-lg font-bold">Title</h2>}
152
+ body={() => <p>Body content</p>}
153
+ footer={
154
+ <div class="flex justify-end gap-2">
155
+ <Button variant="simple" onClick={() => setOpen(false)}>Cancel</Button>
156
+ <Button variant="solid" color="primary" onClick={handleSave}>Save</Button>
157
+ </div>
158
+ }
159
+ />
160
+ ```
161
+
162
+ ### 3. Custom width
163
+
164
+ ```tsx
165
+ <Modal
166
+ open={open()}
167
+ onClose={() => setOpen(false)}
168
+ width="900px"
169
+ class={{ modal: 'h-[500px]' }}
170
+ body={() => <MyLargeContent />}
171
+ />
172
+ ```
173
+
174
+ ### 4. Disable outside click close
175
+
176
+ ```tsx
177
+ <Modal
178
+ open={open()}
179
+ onClose={() => setOpen(false)}
180
+ closeOnOutsideClick={false}
181
+ body={() => <ImportantForm />}
182
+ />
183
+ ```
184
+
185
+ ### 5. No close button
186
+
187
+ ```tsx
188
+ <Modal
189
+ open={open()}
190
+ onClose={() => setOpen(false)}
191
+ closable={false}
192
+ body={() => <div>No X button shown</div>}
193
+ />
194
+ ```
195
+
196
+ ### 6. No overlay / custom mask
197
+
198
+ ```tsx
199
+ // No overlay at all
200
+ <Modal open={open()} onClose={() => setOpen(false)} mask={false} body={() => <div />} />
201
+
202
+ // Overlay without blur
203
+ <Modal
204
+ open={open()}
205
+ onClose={() => setOpen(false)}
206
+ mask={{ enabled: true, blur: false }}
207
+ body={() => <div />}
208
+ />
209
+ ```
210
+
211
+ ### 7. Custom animation
212
+
213
+ ```tsx
214
+ <Modal
215
+ open={open()}
216
+ onClose={() => setOpen(false)}
217
+ animate={{ name: 'fadeInDown', duration: '200ms', timingFunction: 'ease-out' }}
218
+ body={() => <div>Animated</div>}
219
+ />
220
+
221
+ // Disable animation
222
+ <Modal
223
+ open={open()}
224
+ onClose={() => setOpen(false)}
225
+ animate={{ name: 'none' }}
226
+ body={() => <div>No animation</div>}
227
+ />
228
+ ```
229
+
230
+ ### 8. Preserve state across open/close (`preRender`)
231
+
232
+ ```tsx
233
+ <Modal
234
+ open={open()}
235
+ onClose={() => setOpen(false)}
236
+ preRender={true}
237
+ body={() => <ExpensiveForm />}
238
+ />
239
+ ```
240
+
241
+ ### 9. Custom classes on inner elements
242
+
243
+ ```tsx
244
+ <Modal
245
+ open={open()}
246
+ onClose={() => setOpen(false)}
247
+ class={{
248
+ dialog: 'my-dialog-class',
249
+ modal: 'rounded-2xl shadow-2xl',
250
+ closeButton: 'text-red-500',
251
+ }}
252
+ body={() => <div />}
253
+ />
254
+ ```
255
+
256
+ ### 10. Nested modals (multi-level)
257
+
258
+ ```tsx
259
+ // Level 1
260
+ const [l1, setL1] = createSignal(false);
261
+ // Level 2
262
+ const [l2, setL2] = createSignal(false);
263
+
264
+ <Modal open={l1()} onClose={() => setL1(false)} body={() => (
265
+ <>
266
+ <Button onClick={() => setL2(true)}>Open L2</Button>
267
+ <Modal open={l2()} onClose={() => setL2(false)} body={() => <div>L2 content</div>} preRender={false} />
268
+ </>
269
+ )} />
270
+ ```
271
+
272
+ Overlay is only applied to the topmost active modal automatically.
273
+
274
+ ### 11. Imperative API — fire-and-forget
275
+
276
+ ```tsx
277
+ import { createModal } from 'solid-tom-ui';
278
+
279
+ function showAlert() {
280
+ const modal = createModal({
281
+ header: <h2>Alert</h2>,
282
+ body: () => <p>Something happened.</p>,
283
+ footer: (
284
+ <Button onClick={() => modal.destroy()}>OK</Button>
285
+ ),
286
+ onClose: () => {}, // optional extra cleanup
287
+ });
288
+ }
289
+ ```
290
+
291
+ ### 12. Close all modals (e.g., on route change)
292
+
293
+ ```tsx
294
+ import { closeAllModals } from 'solid-tom-ui';
295
+
296
+ onCleanup(() => closeAllModals());
297
+ ```
298
+
299
+ ---
300
+
301
+ ## CSS CLASSES (public API for customization)
302
+
303
+ | Class | Applied to |
304
+ |---|---|
305
+ | `modal` | `<dialog>` root element |
306
+ | `modalOverlay` | `<dialog>` when it is the topmost modal and `mask` is active |
307
+ | `modal-box` | Inner content container `<div>` |
308
+ | `sui-modal-header` | Header slot `<div>` |
309
+ | `sui-modal-body` | Body slot `<div>` |
310
+ | `sui-modal-footer` | Footer slot `<div>` |
311
+
312
+ Use `class={{ dialog: '...', modal: '...', closeButton: '...' }}` prop to append classes to specific elements.
313
+
314
+ ---
315
+
316
+ ## ANIMATION SYSTEM
317
+
318
+ - Animation runs via CSS custom property `--openAnimate` set as inline style on `.modal-box`.
319
+ - `renderCSSAnimation(config)` from `@/utils/helper` generates the `animation` shorthand string.
320
+ - Animation triggers on `.modal[open] .modal-box` (CSS layer `components`).
321
+ - Changing `animate.name` to `'none'` prevents setting `--openAnimate` → no animation.
322
+ - Animation only fires on **open**, not on close (native `<dialog>` has no built-in close animation hook).
323
+
324
+ ---
325
+
326
+ ## CONSTRAINTS & EDGE CASES
327
+
328
+ - `onClose` is **required** in practice — without updating `open` signal inside it, the modal will re-open immediately after closing.
329
+ - `body`, `header`, `footer` accept `SolidComponent` (i.e., `() => JSX.Element` or `JSX.Element`). Pass expensive subtrees as functions `() => <JSX>` to avoid evaluating them before the modal opens.
330
+ - `Portal` renders into `document.body`. The modal is outside any parent's DOM subtree — CSS `overflow: hidden` on ancestors does NOT clip the modal.
331
+ - `createModal` does NOT accept `open` or `preRender` — the modal is always immediately open and never pre-renders.
332
+ - `createModal` instances must be destroyed manually via `instance.destroy()` or `closeAllModals()` if `onClose` is not configured to auto-destroy.
333
+ - Multiple simultaneous `createModal` calls stack correctly — each gets its own `createRoot` reactive scope.
334
+ - The `close` DOM event fires **after** the dialog is already visually closed. Do not rely on `onClose` timing for animations.
335
+
336
+ ---
337
+
338
+ ## DO / DON'T
339
+
340
+ **DO**
341
+ - Always pair `open={signal()}` with `onClose={() => setSignal(false)}`.
342
+ - Pass `body` and expensive content as `() => <JSX>` (function) to defer rendering.
343
+ - Use `preRender={true}` when you need to retain form state between open/close cycles.
344
+ - Use `createModal` for fire-and-forget alerts, confirmations, or notifications outside the component tree.
345
+ - Use `class={{ modal: '...' }}` to control `.modal-box` dimensions (height, border-radius, etc.).
346
+ - Import from the barrel: `import { Modal, createModal, closeAllModals } from 'solid-tom-ui'`.
347
+
348
+ **DON'T**
349
+ - Don't omit `onClose` or leave it as a no-op — the dialog will fight between native closed state and `open` prop.
350
+ - Don't use `ComponentModal` directly unless you need the raw unguarded component (no `<Show>` wrapping).
351
+ - Don't import `ModalExample` in production — it's a demo component only.
352
+ - Don't expect `createModal` instances to auto-cleanup — call `destroy()` or `closeAllModals()` when appropriate.
353
+ - Don't nest `<Portal>` inside modal body — the modal itself already renders via `<Portal>`.
354
+ - Don't try to control the overlay on lower-level modals — the stacking system handles it automatically via `modalIds`.
355
+ ---
356
+
357
+ ## Component Conventions
358
+
359
+ > **CSS encoding**: internal CSS classes use short encoded names (e.g. `mo01`, `mo02`) per project convention.