aark-react-modalify 1.1.0 → 1.2.0
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.
- package/README.md +683 -46
- package/dist/aark-react-modalify.css +1 -1
- package/dist/components/modals/StandardModal.d.ts +8 -0
- package/dist/components/modals/index.d.ts +1 -0
- package/dist/components/notifications/StandardNotification.d.ts +8 -0
- package/dist/components/notifications/index.d.ts +1 -0
- package/dist/index-no-styles.cjs.js +1 -0
- package/dist/{index.esm.js → index-no-styles.esm.js} +406 -76
- package/dist/index.d.ts +2 -1
- package/dist/logic/ModalManager.d.ts +4 -4
- package/dist/logic/aark.d.ts +4 -4
- package/dist/types/index.d.ts +66 -2
- package/dist/utils/inject-styles.d.ts +3 -0
- package/dist/utils/modal-root.d.ts +18 -0
- package/package.json +10 -8
- package/dist/index.cjs.js +0 -32
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# AARK React Modalify 🚀
|
|
2
2
|
|
|
3
|
-
A lightweight, customizable, and easy-to-use modal library for React applications with TypeScript support and
|
|
3
|
+
A lightweight, customizable, and easy-to-use modal library for React applications with TypeScript support and automatic CSS inclusion. Now supports both **component-based** and **props-based** modals and notifications!
|
|
4
4
|
|
|
5
5
|
## ✨ Features
|
|
6
6
|
|
|
7
7
|
- **Zero Dependencies**: Pure React implementation
|
|
8
8
|
- **TypeScript Support**: Full type safety out of the box
|
|
9
|
+
- **Automatic CSS**: Styles are included automatically when you import the library
|
|
10
|
+
- **Dual API**: Use components OR simple props-based configuration
|
|
9
11
|
- **Class-based Architecture**: Clean, singleton-based API
|
|
10
12
|
- **Fully Customizable**: CSS variables for complete theme control
|
|
11
13
|
- **Portal Rendering**: Modals render outside your component tree
|
|
@@ -14,6 +16,7 @@ A lightweight, customizable, and easy-to-use modal library for React application
|
|
|
14
16
|
- **Animation Support**: Smooth fade and slide animations
|
|
15
17
|
- **Hook Integration**: useModal hook for advanced use cases
|
|
16
18
|
- **No Provider Required**: Just import and use anywhere
|
|
19
|
+
- **Minified CSS**: Only 8.97 kB of optimized styles
|
|
17
20
|
|
|
18
21
|
## 📦 Installation
|
|
19
22
|
|
|
@@ -23,8 +26,11 @@ npm install aark-react-modalify
|
|
|
23
26
|
|
|
24
27
|
## 🚀 Quick Start
|
|
25
28
|
|
|
29
|
+
### Basic Usage (CSS Included Automatically)
|
|
30
|
+
|
|
26
31
|
```jsx
|
|
27
32
|
import { aark } from "aark-react-modalify";
|
|
33
|
+
// ✅ CSS is automatically included - no separate import needed!
|
|
28
34
|
|
|
29
35
|
function App() {
|
|
30
36
|
const openModal = () => {
|
|
@@ -35,7 +41,6 @@ function App() {
|
|
|
35
41
|
<button onClick={() => aark.close()}>Close</button>
|
|
36
42
|
</div>,
|
|
37
43
|
{
|
|
38
|
-
mode: "modal",
|
|
39
44
|
position: "center",
|
|
40
45
|
showCloseIcon: true,
|
|
41
46
|
}
|
|
@@ -50,88 +55,696 @@ function App() {
|
|
|
50
55
|
}
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
### Alternative: Import Without CSS
|
|
54
59
|
|
|
55
|
-
|
|
60
|
+
If you prefer to manage CSS separately:
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
import { aark } from "aark-react-modalify/no-styles";
|
|
64
|
+
import "aark-react-modalify/css";
|
|
65
|
+
|
|
66
|
+
// Rest of your code...
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 🎯 Component-Based Approach
|
|
70
|
+
|
|
71
|
+
Perfect for complex, reusable modal content:
|
|
56
72
|
|
|
57
73
|
```jsx
|
|
58
74
|
import { aark } from "aark-react-modalify";
|
|
59
75
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
function App() {
|
|
77
|
+
const openCustomModal = () => {
|
|
78
|
+
aark.fire(
|
|
79
|
+
<div className="my-custom-modal">
|
|
80
|
+
<h2>Custom Modal</h2>
|
|
81
|
+
<form>
|
|
82
|
+
<input type="text" placeholder="Enter your name" />
|
|
83
|
+
<button type="submit">Submit</button>
|
|
84
|
+
</form>
|
|
85
|
+
<button onClick={() => aark.close()}>Cancel</button>
|
|
86
|
+
</div>,
|
|
87
|
+
{
|
|
88
|
+
position: "center",
|
|
89
|
+
showCloseIcon: true,
|
|
90
|
+
clickOutsideToClose: true,
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return <button onClick={openCustomModal}>Open Custom Modal</button>;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 🎯 Props-Based Approach
|
|
100
|
+
|
|
101
|
+
Perfect for quick alerts, confirmations, and notifications:
|
|
102
|
+
|
|
103
|
+
```jsx
|
|
104
|
+
import { aark } from "aark-react-modalify";
|
|
105
|
+
|
|
106
|
+
function App() {
|
|
107
|
+
const showConfirmation = () => {
|
|
108
|
+
aark.fire({
|
|
109
|
+
title: "Delete Item",
|
|
110
|
+
text: "Are you sure you want to delete this item? This action cannot be undone.",
|
|
111
|
+
type: "warning",
|
|
112
|
+
showCancelButton: true,
|
|
113
|
+
confirmText: "Yes, delete it!",
|
|
114
|
+
cancelText: "Cancel",
|
|
115
|
+
confirmButtonColor: "#d33",
|
|
116
|
+
onConfirm: () => {
|
|
117
|
+
console.log("Item deleted!");
|
|
118
|
+
aark.notification({
|
|
119
|
+
title: "Deleted!",
|
|
120
|
+
text: "The item has been deleted successfully.",
|
|
121
|
+
type: "success",
|
|
122
|
+
timer: 3000,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
onCancel: () => console.log("Deletion cancelled"),
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const showNotification = () => {
|
|
130
|
+
aark.notification({
|
|
131
|
+
title: "Welcome!",
|
|
132
|
+
text: "Thanks for using AARK React Modalify!",
|
|
133
|
+
type: "info",
|
|
134
|
+
timer: 4000,
|
|
135
|
+
position: "top-right",
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div>
|
|
141
|
+
<button onClick={showConfirmation}>Delete Item</button>
|
|
142
|
+
<button onClick={showNotification}>Show Notification</button>
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 📚 API Reference
|
|
149
|
+
|
|
150
|
+
### Modal API
|
|
151
|
+
|
|
152
|
+
#### `aark.fire(content, options?)`
|
|
153
|
+
|
|
154
|
+
**Component-based:**
|
|
155
|
+
|
|
156
|
+
```jsx
|
|
157
|
+
aark.fire(<YourComponent />, options);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Props-based:**
|
|
161
|
+
|
|
162
|
+
```jsx
|
|
163
|
+
aark.fire({
|
|
164
|
+
title: "Modal Title",
|
|
165
|
+
text: "Modal content",
|
|
166
|
+
type: "info", // "success" | "error" | "warning" | "info" | "question"
|
|
167
|
+
showCancelButton: true,
|
|
168
|
+
confirmText: "OK",
|
|
169
|
+
cancelText: "Cancel",
|
|
170
|
+
onConfirm: () => {},
|
|
171
|
+
onCancel: () => {},
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### Modal Options
|
|
176
|
+
|
|
177
|
+
| Option | Type | Default | Description |
|
|
178
|
+
| --------------------- | --------------- | ---------- | ------------------------ |
|
|
179
|
+
| `position` | `ModalPosition` | `"center"` | Modal position |
|
|
180
|
+
| `showCloseIcon` | `boolean` | `false` | Show close button |
|
|
181
|
+
| `clickOutsideToClose` | `boolean` | `true` | Close on backdrop click |
|
|
182
|
+
| `escapeKeyToClose` | `boolean` | `true` | Close on ESC key |
|
|
183
|
+
| `onOpen` | `() => void` | - | Called when modal opens |
|
|
184
|
+
| `onClose` | `() => void` | - | Called when modal closes |
|
|
185
|
+
|
|
186
|
+
### Notification API
|
|
187
|
+
|
|
188
|
+
#### `aark.notification(options)`
|
|
189
|
+
|
|
190
|
+
```jsx
|
|
191
|
+
aark.notification({
|
|
192
|
+
title: "Notification Title",
|
|
193
|
+
text: "Notification message",
|
|
194
|
+
type: "success", // "success" | "error" | "warning" | "info" | "question"
|
|
195
|
+
timer: 3000, // Auto-close after 3 seconds
|
|
196
|
+
position: "top-right",
|
|
197
|
+
showCloseButton: true,
|
|
198
|
+
onClick: () => {},
|
|
199
|
+
onClose: () => {},
|
|
200
|
+
});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Notification Options
|
|
204
|
+
|
|
205
|
+
| Option | Type | Default | Description |
|
|
206
|
+
| ----------------- | ---------------------- | ------------- | --------------------- |
|
|
207
|
+
| `title` | `string` | - | Notification title |
|
|
208
|
+
| `text` | `string` | - | Notification content |
|
|
209
|
+
| `type` | `NotificationType` | `"info"` | Notification type |
|
|
210
|
+
| `timer` | `number` | `0` | Auto-close timer (ms) |
|
|
211
|
+
| `position` | `NotificationPosition` | `"top-right"` | Notification position |
|
|
212
|
+
| `showCloseButton` | `boolean` | `true` | Show close button |
|
|
213
|
+
| `onClick` | `() => void` | - | Click handler |
|
|
214
|
+
| `onClose` | `() => void` | - | Close handler |
|
|
215
|
+
|
|
216
|
+
### Position Types
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
type ModalPosition =
|
|
220
|
+
| "center"
|
|
221
|
+
| "top-center"
|
|
222
|
+
| "top-left"
|
|
223
|
+
| "top-right"
|
|
224
|
+
| "bottom-center"
|
|
225
|
+
| "bottom-left"
|
|
226
|
+
| "bottom-right";
|
|
227
|
+
|
|
228
|
+
type NotificationPosition =
|
|
229
|
+
| "top-left"
|
|
230
|
+
| "top-center"
|
|
231
|
+
| "top-right"
|
|
232
|
+
| "bottom-left"
|
|
233
|
+
| "bottom-center"
|
|
234
|
+
| "bottom-right";
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Other Methods
|
|
238
|
+
|
|
239
|
+
```jsx
|
|
240
|
+
aark.close(); // Close current modal
|
|
241
|
+
aark.closeAll(); // Close all modals and notifications
|
|
242
|
+
aark.isOpen(); // Check if any modal is open
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## 🎨 Customization
|
|
246
|
+
|
|
247
|
+
### CSS Variables
|
|
248
|
+
|
|
249
|
+
Customize the appearance using CSS variables:
|
|
250
|
+
|
|
251
|
+
```css
|
|
252
|
+
:root {
|
|
253
|
+
/* Modal Variables */
|
|
254
|
+
--aark-modal-overlay-bg: rgba(0, 0, 0, 0.5);
|
|
255
|
+
--aark-modal-bg: #fff;
|
|
256
|
+
--aark-modal-radius: 8px;
|
|
257
|
+
--aark-modal-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
|
|
258
|
+
--aark-modal-pad: 16px;
|
|
259
|
+
--aark-modal-z: 9999;
|
|
260
|
+
|
|
261
|
+
/* Notification Variables */
|
|
262
|
+
--aark-notification-bg: #fff;
|
|
263
|
+
--aark-notification-radius: 8px;
|
|
264
|
+
--aark-notification-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
265
|
+
--aark-notification-pad: 16px;
|
|
266
|
+
--aark-notification-z: 10000;
|
|
267
|
+
|
|
268
|
+
/* Shared Variables */
|
|
269
|
+
--aark-close-color: #666;
|
|
270
|
+
--aark-close-hover: #f5f5f5;
|
|
271
|
+
--aark-anim: 0.2s;
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Dark Mode Example
|
|
276
|
+
|
|
277
|
+
```css
|
|
278
|
+
[data-theme="dark"] {
|
|
279
|
+
--aark-modal-bg: #1f2937;
|
|
280
|
+
--aark-modal-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
|
|
281
|
+
--aark-notification-bg: #374151;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
[data-theme="dark"] .aark-standard-modal .aark-modal-title {
|
|
285
|
+
color: #ffffff;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
[data-theme="dark"] .aark-standard-modal .aark-modal-content p {
|
|
289
|
+
color: #d1d5db;
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Custom Button Colors
|
|
294
|
+
|
|
295
|
+
```css
|
|
296
|
+
.aark-standard-modal .aark-modal-confirm-button {
|
|
297
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.aark-notification-success {
|
|
301
|
+
border-left: 4px solid #10b981;
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## 🔧 Advanced Usage
|
|
306
|
+
|
|
307
|
+
### Using with Hooks
|
|
308
|
+
|
|
309
|
+
```jsx
|
|
310
|
+
import { useModal } from "aark-react-modalify";
|
|
311
|
+
|
|
312
|
+
function MyComponent() {
|
|
313
|
+
const { openModal, closeModal, isOpen } = useModal();
|
|
314
|
+
|
|
315
|
+
const handleOpen = () => {
|
|
316
|
+
openModal(<div>My modal content</div>, { position: "center" });
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
return (
|
|
320
|
+
<div>
|
|
321
|
+
<button onClick={handleOpen}>Open Modal</button>
|
|
322
|
+
{isOpen && <p>Modal is currently open</p>}
|
|
323
|
+
</div>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Theme Management
|
|
329
|
+
|
|
330
|
+
```jsx
|
|
331
|
+
import { setAarkModalTheme, resetAarkModalTheme } from "aark-react-modalify";
|
|
332
|
+
|
|
333
|
+
// Apply custom theme
|
|
334
|
+
setAarkModalTheme({
|
|
335
|
+
modalBg: "#1f2937",
|
|
336
|
+
modalRadius: "12px",
|
|
67
337
|
animationDuration: "0.3s",
|
|
68
338
|
});
|
|
69
339
|
|
|
70
|
-
//
|
|
71
|
-
|
|
340
|
+
// Reset to defaults
|
|
341
|
+
resetAarkModalTheme();
|
|
342
|
+
```
|
|
72
343
|
|
|
73
|
-
|
|
74
|
-
aark.resetTheme();
|
|
344
|
+
## 📁 CSS Import Options
|
|
75
345
|
|
|
76
|
-
|
|
77
|
-
|
|
346
|
+
### Option 1: Automatic (Recommended)
|
|
347
|
+
|
|
348
|
+
```jsx
|
|
349
|
+
import { aark } from "aark-react-modalify";
|
|
350
|
+
// CSS is included automatically ✅
|
|
78
351
|
```
|
|
79
352
|
|
|
80
|
-
|
|
353
|
+
### Option 2: Manual Import
|
|
81
354
|
|
|
82
|
-
|
|
355
|
+
```jsx
|
|
356
|
+
import { aark } from "aark-react-modalify/no-styles";
|
|
357
|
+
import "aark-react-modalify/css";
|
|
358
|
+
```
|
|
83
359
|
|
|
84
|
-
|
|
360
|
+
### Option 3: Individual Style Files
|
|
85
361
|
|
|
86
|
-
|
|
362
|
+
```jsx
|
|
363
|
+
// For modal-only usage
|
|
364
|
+
import "aark-react-modalify/src/assets/styles/aark-modal-only.css";
|
|
365
|
+
|
|
366
|
+
// For notification-only usage
|
|
367
|
+
import "aark-react-modalify/src/assets/styles/aark-notification-only.css";
|
|
368
|
+
```
|
|
87
369
|
|
|
88
|
-
|
|
89
|
-
- `options` (ModalOptions): Configuration options
|
|
370
|
+
## 🌐 Framework Compatibility
|
|
90
371
|
|
|
91
|
-
|
|
372
|
+
Works seamlessly with:
|
|
92
373
|
|
|
93
|
-
|
|
374
|
+
- ✅ **Vite** - CSS automatically processed
|
|
375
|
+
- ✅ **Create React App** - Styles included in bundle
|
|
376
|
+
- ✅ **Next.js** - Works with both App and Pages router
|
|
377
|
+
- ✅ **Webpack** - CSS automatically bundled
|
|
378
|
+
- ✅ **Parcel** - Styles processed automatically
|
|
94
379
|
|
|
95
|
-
|
|
380
|
+
## 📊 Bundle Size
|
|
96
381
|
|
|
97
|
-
|
|
382
|
+
- **JavaScript**: ~16 kB (minified)
|
|
383
|
+
- **CSS**: 8.97 kB (minified)
|
|
384
|
+
- **Total**: ~25 kB
|
|
385
|
+
- **Gzipped**: ~8 kB (estimated)
|
|
98
386
|
|
|
99
|
-
|
|
387
|
+
## 🤝 Contributing
|
|
100
388
|
|
|
101
|
-
|
|
389
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
102
390
|
|
|
103
|
-
|
|
391
|
+
## 📄 License
|
|
104
392
|
|
|
105
|
-
|
|
393
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
106
394
|
|
|
107
|
-
|
|
395
|
+
## 🆕 What's New in v1.1.0
|
|
108
396
|
|
|
109
|
-
|
|
397
|
+
- ✅ **Automatic CSS Import**: No need to import CSS separately
|
|
398
|
+
- ✅ **Optimized Bundle**: CSS minified to 8.97 kB
|
|
399
|
+
- ✅ **Better Tree Shaking**: Import only what you need
|
|
400
|
+
- ✅ **Enhanced TypeScript**: Improved type definitions
|
|
401
|
+
- ✅ **Framework Agnostic**: Works with any modern bundler
|
|
110
402
|
|
|
111
|
-
|
|
403
|
+
---
|
|
112
404
|
|
|
113
|
-
|
|
405
|
+
Made with ❤️ by [Mohammad Sumon](https://github.com/sumonsbgc)
|
|
114
406
|
|
|
115
|
-
|
|
407
|
+
## ✨ Features
|
|
116
408
|
|
|
117
|
-
|
|
409
|
+
- **Zero Dependencies**: Pure React implementation
|
|
410
|
+
- **TypeScript Support**: Full type safety out of the box
|
|
411
|
+
- **Dual API**: Use components OR simple props-based configuration
|
|
412
|
+
- **Class-based Architecture**: Clean, singleton-based API
|
|
413
|
+
- **Fully Customizable**: CSS variables for complete theme control
|
|
414
|
+
- **Portal Rendering**: Modals render outside your component tree
|
|
415
|
+
- **Accessibility**: Built-in keyboard navigation and focus management
|
|
416
|
+
- **Multiple Positions**: Center, top, bottom, left, right positioning
|
|
417
|
+
- **Animation Support**: Smooth fade and slide animations
|
|
418
|
+
- **Hook Integration**: useModal hook for advanced use cases
|
|
419
|
+
- **No Provider Required**: Just import and use anywhere
|
|
118
420
|
|
|
119
|
-
|
|
421
|
+
## 📦 Installation
|
|
120
422
|
|
|
121
|
-
|
|
423
|
+
```bash
|
|
424
|
+
npm install aark-react-modalify
|
|
425
|
+
```
|
|
122
426
|
|
|
123
|
-
|
|
427
|
+
## 🚀 Quick Start
|
|
124
428
|
|
|
125
|
-
|
|
429
|
+
### Component-Based Approach (Original)
|
|
430
|
+
|
|
431
|
+
```jsx
|
|
432
|
+
import { aark } from "aark-react-modalify";
|
|
433
|
+
|
|
434
|
+
function App() {
|
|
435
|
+
const openModal = () => {
|
|
436
|
+
aark.fire(
|
|
437
|
+
<div>
|
|
438
|
+
<h2>Hello World!</h2>
|
|
439
|
+
<p>This is a simple modal.</p>
|
|
440
|
+
<button onClick={() => aark.close()}>Close</button>
|
|
441
|
+
</div>,
|
|
442
|
+
{
|
|
443
|
+
position: "center",
|
|
444
|
+
showCloseIcon: true,
|
|
445
|
+
}
|
|
446
|
+
);
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
return (
|
|
450
|
+
<div>
|
|
451
|
+
<button onClick={openModal}>Open Modal</button>
|
|
452
|
+
</div>
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Props-Based Approach (New!)
|
|
458
|
+
|
|
459
|
+
```jsx
|
|
460
|
+
import { aark } from "aark-react-modalify";
|
|
461
|
+
|
|
462
|
+
function App() {
|
|
463
|
+
const openModal = () => {
|
|
464
|
+
aark.fire({
|
|
465
|
+
title: "Confirmation",
|
|
466
|
+
text: "Are you sure you want to proceed?",
|
|
467
|
+
type: "question",
|
|
468
|
+
showCancelButton: true,
|
|
469
|
+
confirmText: "Yes, proceed!",
|
|
470
|
+
cancelText: "Cancel",
|
|
471
|
+
onConfirm: () => console.log("Confirmed!"),
|
|
472
|
+
onCancel: () => console.log("Cancelled!"),
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const openNotification = () => {
|
|
477
|
+
aark.notification({
|
|
478
|
+
title: "Success!",
|
|
479
|
+
text: "Your action was completed successfully.",
|
|
480
|
+
type: "success",
|
|
481
|
+
timer: 3000,
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
return (
|
|
486
|
+
<div>
|
|
487
|
+
<button onClick={openModal}>Open Props Modal</button>
|
|
488
|
+
<button onClick={openNotification}>Show Notification</button>
|
|
489
|
+
</div>
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## 📋 API Methods
|
|
495
|
+
|
|
496
|
+
### `aark.fire(contentOrProps, options?)`
|
|
497
|
+
|
|
498
|
+
Display a modal with either component content or props configuration.
|
|
499
|
+
|
|
500
|
+
**Component-based usage:**
|
|
501
|
+
|
|
502
|
+
```jsx
|
|
503
|
+
aark.fire(<MyComponent />, { position: "center" });
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
**Props-based usage:**
|
|
507
|
+
|
|
508
|
+
```jsx
|
|
509
|
+
aark.fire({
|
|
510
|
+
title: "Alert",
|
|
511
|
+
text: "This is a simple alert",
|
|
512
|
+
type: "info",
|
|
513
|
+
});
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### `aark.modal(contentOrProps, options?)`
|
|
517
|
+
|
|
518
|
+
Same as `aark.fire()` - display a modal.
|
|
519
|
+
|
|
520
|
+
### `aark.notification(contentOrProps, options?)`
|
|
521
|
+
|
|
522
|
+
Display a notification with either component content or props configuration.
|
|
523
|
+
|
|
524
|
+
**Component-based usage:**
|
|
525
|
+
|
|
526
|
+
```jsx
|
|
527
|
+
aark.notification(<MyNotification />, { position: "top-right" });
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
**Props-based usage:**
|
|
531
|
+
|
|
532
|
+
```jsx
|
|
533
|
+
aark.notification({
|
|
534
|
+
title: "New Message",
|
|
535
|
+
text: "You have a new message!",
|
|
536
|
+
type: "info",
|
|
537
|
+
timer: 5000,
|
|
538
|
+
});
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
### Other Methods
|
|
542
|
+
|
|
543
|
+
- `aark.close()` - Close the currently open modal/notification
|
|
544
|
+
- `aark.isOpen()` - Check if a modal is currently open
|
|
545
|
+
- `aark.closeAll()` - Close all open modals/notifications
|
|
546
|
+
|
|
547
|
+
## 🎨 Props-Based Configuration
|
|
548
|
+
|
|
549
|
+
### Modal Props
|
|
550
|
+
|
|
551
|
+
```typescript
|
|
552
|
+
interface ModalProps {
|
|
553
|
+
title?: string; // Modal title
|
|
554
|
+
text?: string; // Modal text content
|
|
555
|
+
type?: "success" | "error" | "warning" | "info" | "question";
|
|
556
|
+
cancelText?: string; // Cancel button text
|
|
557
|
+
confirmText?: string; // Confirm button text
|
|
558
|
+
onCancel?: () => void; // Cancel button callback
|
|
559
|
+
onConfirm?: () => void; // Confirm button callback
|
|
560
|
+
icon?: string | ReactNode; // Custom icon
|
|
561
|
+
html?: string | ReactNode; // HTML content (instead of text)
|
|
562
|
+
showCancelButton?: boolean; // Show cancel button
|
|
563
|
+
showConfirmButton?: boolean; // Show confirm button
|
|
564
|
+
allowOutsideClick?: boolean; // Allow closing by clicking outside
|
|
565
|
+
allowEscapeKey?: boolean; // Allow closing with Escape key
|
|
566
|
+
reverseButtons?: boolean; // Reverse button order
|
|
567
|
+
width?: string | number; // Modal width
|
|
568
|
+
padding?: string | number; // Modal padding
|
|
569
|
+
background?: string; // Modal background color
|
|
570
|
+
customClass?: {
|
|
571
|
+
// Custom CSS classes
|
|
572
|
+
container?: string;
|
|
573
|
+
popup?: string;
|
|
574
|
+
header?: string;
|
|
575
|
+
title?: string;
|
|
576
|
+
closeButton?: string;
|
|
577
|
+
icon?: string;
|
|
578
|
+
content?: string;
|
|
579
|
+
actions?: string;
|
|
580
|
+
confirmButton?: string;
|
|
581
|
+
cancelButton?: string;
|
|
582
|
+
footer?: string;
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
### Notification Props
|
|
588
|
+
|
|
589
|
+
```typescript
|
|
590
|
+
interface NotificationProps {
|
|
591
|
+
title?: string; // Notification title
|
|
592
|
+
text?: string; // Notification text content
|
|
593
|
+
type?: "success" | "error" | "warning" | "info" | "question";
|
|
594
|
+
icon?: string | ReactNode; // Custom icon
|
|
595
|
+
html?: string | ReactNode; // HTML content (instead of text)
|
|
596
|
+
timer?: number; // Auto-close timer (ms)
|
|
597
|
+
showCloseButton?: boolean; // Show close button
|
|
598
|
+
clickToClose?: boolean; // Close on click
|
|
599
|
+
width?: string | number; // Notification width
|
|
600
|
+
padding?: string | number; // Notification padding
|
|
601
|
+
background?: string; // Notification background color
|
|
602
|
+
customClass?: {
|
|
603
|
+
// Custom CSS classes
|
|
604
|
+
container?: string;
|
|
605
|
+
popup?: string;
|
|
606
|
+
header?: string;
|
|
607
|
+
title?: string;
|
|
608
|
+
closeButton?: string;
|
|
609
|
+
icon?: string;
|
|
610
|
+
content?: string;
|
|
611
|
+
footer?: string;
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
## 💡 Usage Examples
|
|
617
|
+
|
|
618
|
+
### Success Modal
|
|
619
|
+
|
|
620
|
+
```jsx
|
|
621
|
+
aark.modal({
|
|
622
|
+
title: "Success!",
|
|
623
|
+
text: "Your data has been saved successfully.",
|
|
624
|
+
type: "success",
|
|
625
|
+
confirmText: "Great!",
|
|
626
|
+
});
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
### Confirmation Dialog
|
|
630
|
+
|
|
631
|
+
```jsx
|
|
632
|
+
aark.modal({
|
|
633
|
+
title: "Delete Item",
|
|
634
|
+
text: "Are you sure you want to delete this item? This action cannot be undone.",
|
|
635
|
+
type: "warning",
|
|
636
|
+
showCancelButton: true,
|
|
637
|
+
confirmText: "Yes, delete it!",
|
|
638
|
+
cancelText: "Cancel",
|
|
639
|
+
onConfirm: () => {
|
|
640
|
+
// Delete logic here
|
|
641
|
+
console.log("Item deleted");
|
|
642
|
+
},
|
|
643
|
+
});
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
### Error Notification
|
|
647
|
+
|
|
648
|
+
```jsx
|
|
649
|
+
aark.notification({
|
|
650
|
+
title: "Error",
|
|
651
|
+
text: "Something went wrong. Please try again.",
|
|
652
|
+
type: "error",
|
|
653
|
+
timer: 4000,
|
|
654
|
+
});
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
### Custom HTML Content
|
|
658
|
+
|
|
659
|
+
```jsx
|
|
660
|
+
aark.modal({
|
|
661
|
+
title: "Custom Content",
|
|
662
|
+
html: `
|
|
663
|
+
<div>
|
|
664
|
+
<p>This is <strong>custom HTML</strong> content.</p>
|
|
665
|
+
<ul>
|
|
666
|
+
<li>Feature 1</li>
|
|
667
|
+
<li>Feature 2</li>
|
|
668
|
+
</ul>
|
|
669
|
+
</div>
|
|
670
|
+
`,
|
|
671
|
+
type: "info",
|
|
672
|
+
});
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
### Using Component-Based Approach (Original)
|
|
676
|
+
|
|
677
|
+
```jsx
|
|
678
|
+
// You can still use the original component-based approach
|
|
679
|
+
aark.modal(
|
|
680
|
+
<div style={{ padding: "2rem" }}>
|
|
681
|
+
<h2>Custom Component</h2>
|
|
682
|
+
<p>This is a custom React component!</p>
|
|
683
|
+
<button onClick={() => aark.close()}>Close</button>
|
|
684
|
+
</div>,
|
|
685
|
+
{
|
|
686
|
+
position: "center",
|
|
687
|
+
showCloseIcon: false,
|
|
688
|
+
}
|
|
689
|
+
);
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
## 🎨 Theme Customization
|
|
693
|
+
|
|
694
|
+
AARK React Modalify supports full theme customization through CSS variables:
|
|
695
|
+
|
|
696
|
+
```jsx
|
|
697
|
+
import { aark } from "aark-react-modalify";
|
|
698
|
+
|
|
699
|
+
// Set custom theme
|
|
700
|
+
aark.setTheme({
|
|
701
|
+
modalBackground: "#1a1a1a",
|
|
702
|
+
overlayBackground: "rgba(0, 0, 0, 0.8)",
|
|
703
|
+
closeButtonColor: "#ffffff",
|
|
704
|
+
closeButtonHoverBackground: "rgba(255, 255, 255, 0.1)",
|
|
705
|
+
modalBorderRadius: "12px",
|
|
706
|
+
animationDuration: "0.3s",
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
// Fire modal with custom theme
|
|
710
|
+
aark.fire({ title: "Themed Modal", text: "This modal uses custom theme!" });
|
|
711
|
+
|
|
712
|
+
// Reset to default theme
|
|
713
|
+
aark.resetTheme();
|
|
714
|
+
|
|
715
|
+
// Get current theme
|
|
716
|
+
const currentTheme = aark.getTheme();
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
## ⚙️ Modal Options (for component-based approach)
|
|
126
720
|
|
|
127
721
|
```typescript
|
|
128
722
|
interface ModalOptions {
|
|
129
|
-
|
|
130
|
-
|
|
723
|
+
position?:
|
|
724
|
+
| "center"
|
|
725
|
+
| "top-center"
|
|
726
|
+
| "top-right"
|
|
727
|
+
| "bottom-right"
|
|
728
|
+
| "bottom-center";
|
|
131
729
|
showCloseIcon?: boolean;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
730
|
+
className?: string;
|
|
731
|
+
overlayClassName?: string;
|
|
732
|
+
preventEscClose?: boolean;
|
|
733
|
+
preventOverlayClose?: boolean;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
interface NotificationOptions {
|
|
737
|
+
position?:
|
|
738
|
+
| "top-right"
|
|
739
|
+
| "top-center"
|
|
740
|
+
| "top-left"
|
|
741
|
+
| "bottom-right"
|
|
742
|
+
| "bottom-center"
|
|
743
|
+
| "bottom-left";
|
|
744
|
+
showCloseIcon?: boolean;
|
|
745
|
+
autoCloseTime?: number;
|
|
746
|
+
className?: string;
|
|
747
|
+
preventEscClose?: boolean;
|
|
135
748
|
}
|
|
136
749
|
```
|
|
137
750
|
|
|
@@ -192,6 +805,30 @@ function MyComponent() {
|
|
|
192
805
|
}
|
|
193
806
|
```
|
|
194
807
|
|
|
808
|
+
## 🆚 Comparison: Component vs Props-Based
|
|
809
|
+
|
|
810
|
+
| Feature | Component-Based | Props-Based |
|
|
811
|
+
| --------------- | --------------------------- | --------------------------- |
|
|
812
|
+
| **Flexibility** | Complete control over JSX | Predefined templates |
|
|
813
|
+
| **Ease of Use** | Requires React knowledge | Simple object configuration |
|
|
814
|
+
| **Styling** | Full CSS control | Built-in styled templates |
|
|
815
|
+
| **Type Safety** | ReactNode typing | Structured props interface |
|
|
816
|
+
| **Best for** | Complex UIs, custom designs | Quick alerts, confirmations |
|
|
817
|
+
|
|
818
|
+
**When to use Component-Based:**
|
|
819
|
+
|
|
820
|
+
- Complex modal content
|
|
821
|
+
- Custom styling requirements
|
|
822
|
+
- Existing React components
|
|
823
|
+
- Advanced interactions
|
|
824
|
+
|
|
825
|
+
**When to use Props-Based:**
|
|
826
|
+
|
|
827
|
+
- Quick alerts and confirmations
|
|
828
|
+
- Consistent design system
|
|
829
|
+
- Simple notifications
|
|
830
|
+
- Rapid prototyping
|
|
831
|
+
|
|
195
832
|
## 🛠️ Development
|
|
196
833
|
|
|
197
834
|
```bash
|