aio-popup 3.2.1 → 4.0.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/index.css +166 -134
- package/index.d.ts +135 -0
- package/index.js +8 -9
- package/package.json +3 -3
package/index.css
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
.aio-popup-backdrop.not-mounted {
|
|
2
|
+
background: none !important;
|
|
3
|
+
transition: 0.3s;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
.aio-popup-backdrop {
|
|
2
7
|
position: fixed;
|
|
3
8
|
display: flex;
|
|
@@ -11,105 +16,8 @@
|
|
|
11
16
|
background: rgba(0, 0, 0, 0.1);
|
|
12
17
|
transition: 0.3s;
|
|
13
18
|
pointer-events: all;
|
|
19
|
+
outline:none;
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
.aio-popup.not-mounted {
|
|
17
|
-
transition: 0.3s;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.aio-popup-position-fullscreen>.aio-popup.not-mounted {
|
|
21
|
-
transform: scale(0);
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.aio-popup-position-popover>.aio-popup.not-mounted {
|
|
26
|
-
opacity: 0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.aio-popup-position-top>.aio-popup.not-mounted {
|
|
30
|
-
top: -500px;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.aio-popup-position-bottom>.aio-popup.not-mounted {
|
|
34
|
-
bottom: -500px;
|
|
35
|
-
opacity: 0;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.aio-popup-position-right>.aio-popup.not-mounted {
|
|
39
|
-
right: -500px;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.aio-popup-position-left>.aio-popup.not-mounted {
|
|
43
|
-
left: -500px;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.aio-popup-position-center>.aio-popup.not-mounted {
|
|
47
|
-
transform: translateY(500px);
|
|
48
|
-
opacity: 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.aio-popup-position-fullscreen>.aio-popup {
|
|
52
|
-
width: 100%;
|
|
53
|
-
height: 100%;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.aio-popup-position-popover {
|
|
57
|
-
opacity: 1;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.aio-popup-position-top {
|
|
61
|
-
align-items: flex-start;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.aio-popup-position-top>.aio-popup {
|
|
65
|
-
width: 100%;
|
|
66
|
-
max-height: 90vh;
|
|
67
|
-
top: 0;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
.aio-popup-position-bottom {
|
|
71
|
-
align-items: flex-end;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.aio-popup-position-bottom>.aio-popup {
|
|
75
|
-
width: 100%;
|
|
76
|
-
max-height: 90vh;
|
|
77
|
-
bottom: 0;
|
|
78
|
-
opacity: 1;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.aio-popup-backdrop.not-mounted {
|
|
82
|
-
background: none !important;
|
|
83
|
-
transition: 0.3s;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.aio-popup-position-right {
|
|
87
|
-
justify-content: right;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.aio-popup-position-right .aio-popup {
|
|
91
|
-
height: 100%;
|
|
92
|
-
max-width: 90vh;
|
|
93
|
-
right: 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.aio-popup-position-left {
|
|
97
|
-
justify-content: left;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
.aio-popup-position-left>.aio-popup {
|
|
101
|
-
height: 100%;
|
|
102
|
-
max-width: 90vh;
|
|
103
|
-
left: 0;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.aio-popup-position-center>.aio-popup {
|
|
107
|
-
max-width: 100vw;
|
|
108
|
-
width: fit-content;
|
|
109
|
-
opacity: 1;
|
|
110
|
-
max-height: 100vh;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
21
|
.aio-popup {
|
|
114
22
|
border-radius: 4px;
|
|
115
23
|
font-size: 14px;
|
|
@@ -117,13 +25,42 @@
|
|
|
117
25
|
max-width: 100vw;
|
|
118
26
|
max-height: 100vh;
|
|
119
27
|
pointer-events: auto;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
28
|
+
display:flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
position: absolute;
|
|
31
|
+
outline:none;
|
|
32
|
+
}
|
|
33
|
+
.aio-popup.rtl {direction: rtl;}
|
|
34
|
+
.aio-popup.not-mounted {transition: 0.3s;}
|
|
35
|
+
/**********position (fullscreen)*******/
|
|
36
|
+
.aio-popup-position-fullscreen>.aio-popup.not-mounted {transform: scale(0);}
|
|
37
|
+
.aio-popup-position-fullscreen>.aio-popup {width: 100%;height: 100%;}
|
|
38
|
+
/**********position (top)**************/
|
|
39
|
+
.aio-popup-position-top {align-items: flex-start;}
|
|
40
|
+
.aio-popup-position-top > .aio-popup.not-mounted {top: -500px;}
|
|
41
|
+
.aio-popup-position-top > .aio-popup {width: 100%;max-height: 90vh;top: 0;}
|
|
42
|
+
/**********position (bottom)***********/
|
|
43
|
+
.aio-popup-position-bottom {align-items: flex-end;}
|
|
44
|
+
.aio-popup-position-bottom>.aio-popup.not-mounted {bottom: -500px;opacity: 0;}
|
|
45
|
+
.aio-popup-position-bottom>.aio-popup {width: 100%;max-height: 90vh;bottom: 0;opacity: 1;}
|
|
46
|
+
/**********position (left)*************/
|
|
47
|
+
.aio-popup-position-left {justify-content: left;}
|
|
48
|
+
.aio-popup-position-left > .aio-popup.not-mounted {left: -500px;}
|
|
49
|
+
.aio-popup-position-left > .aio-popup {height: 100%;max-width: 90vh;left: 0;}
|
|
50
|
+
/**********position (right)************/
|
|
51
|
+
.aio-popup-position-right {justify-content: right;}
|
|
52
|
+
.aio-popup-position-right > .aio-popup.not-mounted {right: -500px;}
|
|
53
|
+
.aio-popup-position-right > .aio-popup {height: 100%;max-width: 90vh;right: 0;}
|
|
54
|
+
/**********position (popover)************/
|
|
55
|
+
.aio-popup-position-popover {opacity: 1;}
|
|
56
|
+
.aio-popup-position-popover>.aio-popup.not-mounted {opacity: 0;}
|
|
57
|
+
/**********position (center)***********/
|
|
58
|
+
.aio-popup-position-center>.aio-popup.not-mounted {transform: translateY(500px);opacity: 0;}
|
|
59
|
+
.aio-popup-position-center>.aio-popup {max-width: 100vw;width: fit-content;opacity: 1;max-height: 100vh;}
|
|
60
|
+
/**************************************/
|
|
125
61
|
|
|
126
62
|
.aio-popup-header {
|
|
63
|
+
display:flex;
|
|
127
64
|
border-bottom: 1px solid #e7e9ec;
|
|
128
65
|
background: #fff;
|
|
129
66
|
color: #323130;
|
|
@@ -133,7 +70,7 @@
|
|
|
133
70
|
min-height: 48px;
|
|
134
71
|
}
|
|
135
72
|
|
|
136
|
-
.aio-popup-subtitle {
|
|
73
|
+
.aio-popup-header-subtitle {
|
|
137
74
|
font-size: 85%;
|
|
138
75
|
opacity: 0.5;
|
|
139
76
|
}
|
|
@@ -143,6 +80,10 @@
|
|
|
143
80
|
flex: 1;
|
|
144
81
|
width: 100%;
|
|
145
82
|
overflow-y: auto;
|
|
83
|
+
box-sizing:border-box;
|
|
84
|
+
}
|
|
85
|
+
.aio-popup-body *{
|
|
86
|
+
box-sizing: border-box;
|
|
146
87
|
}
|
|
147
88
|
|
|
148
89
|
.aio-popup-footer {
|
|
@@ -153,19 +94,31 @@
|
|
|
153
94
|
display: flex;
|
|
154
95
|
border-top: 1px solid #f2f4f7;
|
|
155
96
|
justify-content: flex-end;
|
|
97
|
+
box-sizing: border-box;
|
|
98
|
+
}
|
|
99
|
+
.aio-popup-header-buttons{
|
|
100
|
+
display:flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
gap:6px;
|
|
156
104
|
}
|
|
157
|
-
|
|
158
105
|
.aio-popup-header-button {
|
|
159
106
|
padding: 0 6px;
|
|
160
107
|
background: none;
|
|
161
108
|
border: none;
|
|
162
109
|
cursor: pointer;
|
|
163
110
|
}
|
|
164
|
-
|
|
165
111
|
.aio-popup-header-close-button {
|
|
112
|
+
display:flex;
|
|
113
|
+
align-items: center;
|
|
114
|
+
justify-content: center;
|
|
166
115
|
width: 36px;
|
|
167
116
|
}
|
|
168
|
-
|
|
117
|
+
.aio-popup-header-after{
|
|
118
|
+
display:flex;
|
|
119
|
+
align-items: center;
|
|
120
|
+
height:100%;
|
|
121
|
+
}
|
|
169
122
|
.aio-popup-footer-button {
|
|
170
123
|
height: 30px;
|
|
171
124
|
background: dodgerblue;
|
|
@@ -202,6 +155,12 @@
|
|
|
202
155
|
align-items: center;
|
|
203
156
|
justify-content: center;
|
|
204
157
|
font-family: inherit;
|
|
158
|
+
transition:0.2s;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.aio-popup-alert-container.not-mounted{
|
|
162
|
+
background: rgba(0, 0, 0, 0);
|
|
163
|
+
transition:0.2;
|
|
205
164
|
}
|
|
206
165
|
|
|
207
166
|
.aio-popup-alert {
|
|
@@ -216,6 +175,31 @@
|
|
|
216
175
|
overflow: hidden;
|
|
217
176
|
}
|
|
218
177
|
|
|
178
|
+
.aio-popup-alert-container-center .aio-popup-alert{
|
|
179
|
+
transform:scale(1);
|
|
180
|
+
transition:0.2s;
|
|
181
|
+
}
|
|
182
|
+
.aio-popup-alert-container-center.not-mounted .aio-popup-alert {
|
|
183
|
+
transform:scale(0);
|
|
184
|
+
transition:0.2s;
|
|
185
|
+
}
|
|
186
|
+
.aio-popup-alert-container-top .aio-popup-alert{
|
|
187
|
+
transform:translateY(0vh);
|
|
188
|
+
transition:0.2s;
|
|
189
|
+
}
|
|
190
|
+
.aio-popup-alert-container-top.not-mounted .aio-popup-alert {
|
|
191
|
+
transform:translateY(-100vh);
|
|
192
|
+
transition:0.2s;
|
|
193
|
+
}
|
|
194
|
+
.aio-popup-alert-container-bottom .aio-popup-alert{
|
|
195
|
+
transform:translateY(0vh);
|
|
196
|
+
transition:0.2s;
|
|
197
|
+
}
|
|
198
|
+
.aio-popup-alert-container-bottom.not-mounted .aio-popup-alert {
|
|
199
|
+
transform:translateY(100vh);
|
|
200
|
+
transition:0.2s;
|
|
201
|
+
}
|
|
202
|
+
|
|
219
203
|
.aio-popup-alert-error .aio-popup-alert-header svg {
|
|
220
204
|
fill: red;
|
|
221
205
|
}
|
|
@@ -270,9 +254,9 @@
|
|
|
270
254
|
|
|
271
255
|
.aio-popup-time {
|
|
272
256
|
position: absolute;
|
|
273
|
-
height:
|
|
274
|
-
width:
|
|
275
|
-
left:
|
|
257
|
+
height: 4px;
|
|
258
|
+
width: 100%;
|
|
259
|
+
left: 0;
|
|
276
260
|
bottom: 0;
|
|
277
261
|
}
|
|
278
262
|
|
|
@@ -310,8 +294,8 @@
|
|
|
310
294
|
border-radius: 3px;
|
|
311
295
|
}
|
|
312
296
|
|
|
313
|
-
.aio-popup-
|
|
314
|
-
font-size:
|
|
297
|
+
.aio-popup-snackebar-item-container {
|
|
298
|
+
font-size: 14px;
|
|
315
299
|
height: fit-content;
|
|
316
300
|
color: #fff;
|
|
317
301
|
width: 100%;
|
|
@@ -325,8 +309,25 @@
|
|
|
325
309
|
justify-content: center;
|
|
326
310
|
z-index: 1000000;
|
|
327
311
|
}
|
|
328
|
-
|
|
329
|
-
|
|
312
|
+
.aio-popup-snackebar-item-container.aio-popup-snackebar-item-container-horizontal-align-start {
|
|
313
|
+
justify-content: flex-start;
|
|
314
|
+
}
|
|
315
|
+
.aio-popup-snackebar-item-container.aio-popup-snackebar-item-container-horizontal-align-end {
|
|
316
|
+
justify-content: flex-end;
|
|
317
|
+
}
|
|
318
|
+
.aio-popup-snackebar-item-container.aio-popup-snackebar-item-container-horizontal-align-center {
|
|
319
|
+
justify-content: center;
|
|
320
|
+
}
|
|
321
|
+
.aio-popup-snackebar-item-container.rtl {
|
|
322
|
+
direction:rtl;
|
|
323
|
+
}
|
|
324
|
+
.aio-popup-snackebar-item-container .aio-popup-snackebar-item-uptext{
|
|
325
|
+
text-align:left;
|
|
326
|
+
}
|
|
327
|
+
.aio-popup-snackebar-item-container.rtl .aio-popup-snackebar-item-uptext{
|
|
328
|
+
text-align:right;
|
|
329
|
+
}
|
|
330
|
+
.aio-popup-snackebar-item {
|
|
330
331
|
background: rgb(24 28 41 / 95%);
|
|
331
332
|
padding: 12px;
|
|
332
333
|
right: 100%;
|
|
@@ -338,34 +339,35 @@
|
|
|
338
339
|
align-items: center;
|
|
339
340
|
transition: 0.2s;
|
|
340
341
|
overflow: hidden;
|
|
342
|
+
box-shadow:1px 1px 10px 0 rgba(0,0,0,0.2);
|
|
341
343
|
}
|
|
342
344
|
|
|
343
|
-
.aio-popup-
|
|
345
|
+
.aio-popup-snackebar-item-container.mounted .aio-popup-snackebar-item {
|
|
344
346
|
transition: 0.5s;
|
|
345
347
|
right: 0;
|
|
346
348
|
}
|
|
347
349
|
|
|
348
|
-
.aio-popup-
|
|
350
|
+
.aio-popup-snackebar-item-text {
|
|
349
351
|
flex: 1;
|
|
350
352
|
}
|
|
351
353
|
|
|
352
|
-
.aio-popup-
|
|
354
|
+
.aio-popup-snackebar-item-subtext {
|
|
353
355
|
font-size: 85%;
|
|
354
356
|
opacity: 0.67;
|
|
355
357
|
}
|
|
356
358
|
|
|
357
|
-
.aio-popup-
|
|
359
|
+
.aio-popup-snackebar-item-text svg {
|
|
358
360
|
flex: 1;
|
|
359
361
|
}
|
|
360
362
|
|
|
361
|
-
.aio-popup-
|
|
363
|
+
.aio-popup-snackebar-item-remove {
|
|
362
364
|
display: flex;
|
|
363
365
|
align-items: center;
|
|
364
366
|
justify-content: center;
|
|
365
367
|
border-radius: 100%;
|
|
366
368
|
}
|
|
367
369
|
|
|
368
|
-
.aio-popup-
|
|
370
|
+
.aio-popup-snackebar-item-icon {
|
|
369
371
|
display: flex;
|
|
370
372
|
align-items: center;
|
|
371
373
|
justify-content: center;
|
|
@@ -374,55 +376,59 @@
|
|
|
374
376
|
padding: 3px;
|
|
375
377
|
}
|
|
376
378
|
|
|
377
|
-
.aio-popup-
|
|
379
|
+
.aio-popup-snackebar-item-success .aio-popup-snackebar-item-icon {
|
|
378
380
|
color: #5ba427;
|
|
379
381
|
}
|
|
380
382
|
|
|
381
|
-
.aio-popup-
|
|
383
|
+
.aio-popup-snackebar-item-error .aio-popup-snackebar-item-icon {
|
|
382
384
|
color: #e83232;
|
|
383
385
|
}
|
|
384
386
|
|
|
385
|
-
.aio-popup-
|
|
387
|
+
.aio-popup-snackebar-item-warning .aio-popup-snackebar-item-icon {
|
|
386
388
|
color: #ffb300;
|
|
387
389
|
}
|
|
388
390
|
|
|
389
|
-
.aio-popup-
|
|
391
|
+
.aio-popup-snackebar-item-info .aio-popup-snackebar-item-icon {
|
|
390
392
|
color: #00bcff;
|
|
391
393
|
}
|
|
392
394
|
|
|
393
|
-
.aio-popup-
|
|
395
|
+
.aio-popup-snackebar-item-container .aio-popup-snackebar-bar {
|
|
394
396
|
position: absolute;
|
|
395
397
|
left: 0;
|
|
396
|
-
bottom:
|
|
398
|
+
bottom: 0px;
|
|
397
399
|
width: 0%;
|
|
398
|
-
height:
|
|
400
|
+
height: 4px;
|
|
401
|
+
}
|
|
402
|
+
.aio-popup-snackebar-item-container.rtl .aio-popup-snackebar-bar {
|
|
403
|
+
left: unset;
|
|
404
|
+
right:0;
|
|
399
405
|
}
|
|
400
406
|
|
|
401
|
-
.aio-popup-
|
|
407
|
+
.aio-popup-snackebar-item-container.mounted .aio-popup-snackebar-bar {
|
|
402
408
|
width: 100%;
|
|
403
409
|
}
|
|
404
410
|
|
|
405
|
-
/* .aio-popup-
|
|
411
|
+
/* .aio-popup-snackebar-container.mounted .aio-popup-snackebar-bar{
|
|
406
412
|
width:50%;
|
|
407
413
|
} */
|
|
408
414
|
|
|
409
|
-
.aio-popup-
|
|
415
|
+
.aio-popup-snackebar-item-success .aio-popup-snackebar-bar {
|
|
410
416
|
background: #5ba427;
|
|
411
417
|
}
|
|
412
418
|
|
|
413
|
-
.aio-popup-
|
|
419
|
+
.aio-popup-snackebar-item-error .aio-popup-snackebar-bar {
|
|
414
420
|
background: #e83232;
|
|
415
421
|
}
|
|
416
422
|
|
|
417
|
-
.aio-popup-
|
|
423
|
+
.aio-popup-snackebar-item-warning .aio-popup-snackebar-bar {
|
|
418
424
|
background: #ffb300;
|
|
419
425
|
}
|
|
420
426
|
|
|
421
|
-
.aio-popup-
|
|
427
|
+
.aio-popup-snackebar-item-info .aio-popup-snackebar-bar {
|
|
422
428
|
background: #00bcff;
|
|
423
429
|
}
|
|
424
430
|
|
|
425
|
-
.aio-popup-
|
|
431
|
+
.aio-popup-snackebar-item-action {
|
|
426
432
|
color: dodgerblue;
|
|
427
433
|
border: none;
|
|
428
434
|
background: none;
|
|
@@ -430,4 +436,30 @@
|
|
|
430
436
|
|
|
431
437
|
.aio-popup-confirm .aio-popup-body{
|
|
432
438
|
padding:12px;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
.aio-popup-scroll::-webkit-scrollbar {
|
|
444
|
+
width: 10px !important;
|
|
445
|
+
height: 10px !important;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.aio-popup-scroll::-webkit-scrollbar-track {
|
|
449
|
+
background-color: transparent;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
.aio-popup-scroll::-webkit-scrollbar-thumb {
|
|
453
|
+
background-color: #cdd4e0;
|
|
454
|
+
border-radius: 20px;
|
|
455
|
+
border: 3px solid transparent;
|
|
456
|
+
background-clip: content-box;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.aio-popup-scroll::-webkit-scrollbar-thumb {
|
|
460
|
+
background-color: #b1b9ca;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
.aio-popup-scroll::-webkit-scrollbar-thumb:hover {
|
|
464
|
+
background-color: #6f7888;
|
|
433
465
|
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import './index.css';
|
|
3
|
+
export type AP_props = {
|
|
4
|
+
rtl?: boolean;
|
|
5
|
+
id?: string;
|
|
6
|
+
};
|
|
7
|
+
export type AP_position = 'fullscreen' | 'center' | 'popover' | 'left' | 'right' | 'top' | 'bottom';
|
|
8
|
+
export type AP_attrsKey = 'backdrop' | 'modal' | 'header' | 'body' | 'footer';
|
|
9
|
+
export type AP_header = ((p: {
|
|
10
|
+
close: () => void;
|
|
11
|
+
state: any;
|
|
12
|
+
setState: any;
|
|
13
|
+
}) => React.ReactNode) | {
|
|
14
|
+
title?: string;
|
|
15
|
+
subtitle?: string;
|
|
16
|
+
before?: React.ReactNode;
|
|
17
|
+
after?: React.ReactNode;
|
|
18
|
+
onClose?: boolean | ((p: {
|
|
19
|
+
state: any;
|
|
20
|
+
setState: (state: any) => void;
|
|
21
|
+
}) => void);
|
|
22
|
+
attrs?: any;
|
|
23
|
+
};
|
|
24
|
+
export type AP_body = (p: {
|
|
25
|
+
close: () => void;
|
|
26
|
+
state?: any;
|
|
27
|
+
setState?: (state: any) => void;
|
|
28
|
+
}) => React.ReactNode;
|
|
29
|
+
export type AP_footer = (p: {
|
|
30
|
+
state: any;
|
|
31
|
+
setState: (v: any) => void;
|
|
32
|
+
close: () => void;
|
|
33
|
+
}) => React.ReactNode;
|
|
34
|
+
type AP_setAttrs = (mode: AP_attrsKey) => any;
|
|
35
|
+
export type AP_modal = {
|
|
36
|
+
getTarget?: () => any;
|
|
37
|
+
pageSelector?: string;
|
|
38
|
+
limitTo?: string;
|
|
39
|
+
maxHeight?: number | 'string';
|
|
40
|
+
fixStyle?: (o: any, p: {
|
|
41
|
+
targetLimit: any;
|
|
42
|
+
pageLimit: any;
|
|
43
|
+
}) => any;
|
|
44
|
+
fitTo?: string;
|
|
45
|
+
rtl?: boolean;
|
|
46
|
+
id?: string;
|
|
47
|
+
onClose?: boolean | (() => void);
|
|
48
|
+
position?: AP_position;
|
|
49
|
+
header?: AP_header;
|
|
50
|
+
state?: any;
|
|
51
|
+
footer?: AP_footer;
|
|
52
|
+
body?: AP_body;
|
|
53
|
+
animate?: boolean;
|
|
54
|
+
fitHorizontal?: boolean;
|
|
55
|
+
setAttrs?: AP_setAttrs;
|
|
56
|
+
};
|
|
57
|
+
export type AP_alert = {
|
|
58
|
+
icon?: false | React.ReactNode;
|
|
59
|
+
position?: AP_position;
|
|
60
|
+
type: 'success' | 'error' | 'warning' | 'info';
|
|
61
|
+
text?: React.ReactNode;
|
|
62
|
+
subtext?: string;
|
|
63
|
+
time?: number;
|
|
64
|
+
className?: string;
|
|
65
|
+
closeText?: string;
|
|
66
|
+
animate?: boolean;
|
|
67
|
+
};
|
|
68
|
+
export type AP_snackebar = {
|
|
69
|
+
id?: string;
|
|
70
|
+
text: string;
|
|
71
|
+
subtext?: string;
|
|
72
|
+
icon?: React.ReactNode;
|
|
73
|
+
time?: number;
|
|
74
|
+
action?: {
|
|
75
|
+
text: string;
|
|
76
|
+
onClick: () => void;
|
|
77
|
+
};
|
|
78
|
+
type: 'success' | 'error' | 'warning' | 'info';
|
|
79
|
+
verticalAlign?: 'start' | 'end';
|
|
80
|
+
horizontalAlign?: 'start' | 'center' | 'end';
|
|
81
|
+
onClose?: false;
|
|
82
|
+
attrs?: any;
|
|
83
|
+
};
|
|
84
|
+
export type AP_confirm = {
|
|
85
|
+
title?: string;
|
|
86
|
+
subtitle?: string;
|
|
87
|
+
text?: React.ReactNode;
|
|
88
|
+
submitText?: string;
|
|
89
|
+
canselText?: string;
|
|
90
|
+
onSubmit?: () => Promise<boolean>;
|
|
91
|
+
onCansel?: () => void;
|
|
92
|
+
setAttrs?: AP_setAttrs;
|
|
93
|
+
};
|
|
94
|
+
export type AP_prompt = {
|
|
95
|
+
title?: string;
|
|
96
|
+
subtitle?: string;
|
|
97
|
+
text?: string;
|
|
98
|
+
submitText?: string;
|
|
99
|
+
canselText?: string;
|
|
100
|
+
onSubmit?: (text: string) => Promise<boolean>;
|
|
101
|
+
onCansel?: () => void;
|
|
102
|
+
setAttrs?: AP_setAttrs;
|
|
103
|
+
};
|
|
104
|
+
export type AP_Snackebar = {
|
|
105
|
+
getActions: (p: {
|
|
106
|
+
add: (item: AP_snackebar) => void;
|
|
107
|
+
}) => void;
|
|
108
|
+
rtl: boolean;
|
|
109
|
+
};
|
|
110
|
+
export type AP_SnackebarItem = {
|
|
111
|
+
item: AP_snackebar;
|
|
112
|
+
onRemove: (id: string) => void;
|
|
113
|
+
index: number;
|
|
114
|
+
rtl: boolean;
|
|
115
|
+
};
|
|
116
|
+
export default class AIOPopup {
|
|
117
|
+
rtl?: boolean;
|
|
118
|
+
render: () => React.ReactNode;
|
|
119
|
+
addModal: (p: AP_modal) => void;
|
|
120
|
+
addAlert: (p: AP_alert) => void;
|
|
121
|
+
removeModal: (arg?: string) => void;
|
|
122
|
+
addSnackebar: (p: AP_snackebar) => void;
|
|
123
|
+
getModals: () => AP_modal[];
|
|
124
|
+
addConfirm: (p: AP_confirm) => void;
|
|
125
|
+
addPrompt: (p: AP_prompt) => void;
|
|
126
|
+
popupId?: string;
|
|
127
|
+
popupsRef: React.RefObject<typeof Popups>;
|
|
128
|
+
constructor(obj?: AP_props);
|
|
129
|
+
}
|
|
130
|
+
type AP_Popups = {
|
|
131
|
+
ref: any;
|
|
132
|
+
rtl: boolean;
|
|
133
|
+
};
|
|
134
|
+
declare const Popups: FC<AP_Popups>;
|
|
135
|
+
export {};
|
package/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
function _defineProperty(t,e,o){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"==typeof e?e:String(e)}function _toPrimitive(t,e){if("object"!=typeof t||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var i=o.call(t,e||"default");if("object"!=typeof i)return i;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}import t,{Component as e,createRef as o,useEffect as i}from"react";import*as s from"react-dom/server";import{Icon as r}from"@mdi/react";import{mdiClose as a,mdiChevronRight as l,mdiChevronLeft as n}from"@mdi/js";import p from"react-virtual-dom";import d from"jquery";import"./index.css";import{jsx as h}from"react/jsx-runtime";import{Fragment as m}from"react/jsx-runtime";import{jsxs as c}from"react/jsx-runtime";export default class u{constructor(t={}){_defineProperty(this,"render",()=>c(m,{children:[h(Popups,{rtl:this.rtl,getActions:({addModal:t,removeModal:e,getModals:o})=>{this._addModal=t,this._removeModal=e,this._getModals=o}}),h(AIOSnackeBar,{rtl:this.rtl,getActions:({add:t})=>{this._addSnakebar=t}})]})),_defineProperty(this,"getModals",()=>this._getModals()),_defineProperty(this,"addModal",(t={},e=!0)=>{void 0===t.id&&(t.id="popup"+Math.round(1e6*Math.random())),this._addModal(t,e)}),_defineProperty(this,"addConfirm",t=>{let{title:e,subtitle:o,text:i,submitText:s="بله",canselText:r="خیر",onSubmit:a,onCansel:l=()=>{},attrs:n={}}=t,p="aio-popup-confirm";n.className&&(p+=" "+n.className);let d={position:"center",attrs:{...n,className:p},header:{title:e,subtitle:o},backdrop:{attrs:{className:"rsa-backdrop"}},body:{render:()=>i},footer:{buttons:[[r,{onClick:()=>{l(),this.removeModal()}}],[s,{onClick:async()=>{!1!==await a()&&this.removeModal()},className:"active"}]]}};this.addModal(d)}),_defineProperty(this,"addPrompt",t=>{let{title:e,subtitle:o,text:i,submitText:s="تایید",canselText:r="بستن",onSubmit:a,onCansel:l=()=>{},attrs:n={}}=t,p="aio-popup-prompt";n.className&&(p+=" "+n.className);let d={position:"center",attrs:{...n,className:p},state:{temp:""},header:{title:e,subtitle:o},backdrop:{attrs:{className:"rsa-backdrop"}},body:{render:({state:t,setState:e})=>h("textarea",{placeholder:i,value:t.temp,onChange:t=>e({temp:t.target.value})})},footer:{buttons:[[r,{onClick:()=>{l(),this.removeModal()}}],[s,({state:t,setState:e})=>({onClick:async({state:t})=>{!1!==await a(t.temp)?this.removeModal():e({temp:""})},disabled:!t.temp,className:"active"})]]}};this.addModal(d)}),_defineProperty(this,"removeModal",(t,e=!0)=>{this._removeModal&&this._removeModal(t,e)}),_defineProperty(this,"addAlert",(t={})=>{let{icon:e,type:o="",text:i="",subtext:s="",time:r=10,className:a,closeText:l="بستن"}=t;Alert({icon:e,type:o,text:i,subtext:s,time:r,className:a,closeText:l})}),_defineProperty(this,"addSnakebar",(t={})=>{let{text:e,index:o,type:i,subtext:s,action:r={},time:a=6,rtl:l,onClose:n}=t;this._addSnakebar({text:e,index:o,type:i,subtext:s,action:r,time:a,rtl:l,onClose:n})}),this.rtl=t.rtl}};class Popups extends e{constructor(t){super(t),this.dom=o();let{getActions:e=()=>{}}=t;this.state={modals:[]},e({removeModal:this.removeModal.bind(this),addModal:this.addModal.bind(this),getModals:()=>[...this.state.modals]})}change(t){let{onChange:e=()=>{}}=this.props;for(let o in t)this.state[o]=t[o];this.setState(t,()=>e({...this.state}))}addModal(t,e=!0){if("object"!=typeof t){console.error("aio-popup => addModal modal parameter to add is not an object");return}if(void 0===t.id){console.error("aio-popup => addModal missing modal id property");return}let{modals:o}=this.state,i=o.filter(({id:e})=>e!==t.id);i.push({...t,mounted:"popover"!==t.position&&!e}),this.change({modals:i})}async removeModal(t="last",e=!0){if("all"===t)this.change({modals:[]});else{let{modals:o}=this.state;if(!o.length)return;"last"===t&&(t=o[o.length-1].id),this.mount(t,!1),setTimeout(()=>{let{modals:e}=this.state,o=e.find(e=>e.id===t);o&&(o.onClose&&o.onClose(),this.change({modals:e.filter(e=>e.id!==t)}))},e?300:0)}}mount(t="last",e){try{let{modals:o}=this.state;"last"===t&&(t=o[o.length-1].id);let i=o.map(o=>o.id===t?{...o,mounted:e}:o);this.change({modals:i})}catch{return}}getModals(){let{modals:t}=this.state;return t.length?t.map((e,o)=>{let{popover:i,position:s,text:r,onSubmit:a,rtl:l=this.props.rtl,attrs:n={},backdrop:p,header:d,state:m,footer:c,closeType:u,body:_,id:$,mounted:f}=e;return h(Popup,{id:$,backdrop:p,footer:c,text:r,onSubmit:a,header:d,popover:i,state:m,position:s,rtl:l,attrs:n,closeType:u,body:_,index:o,isLast:o===t.length-1,mounted:f,onClose:()=>this.removeModal($),removeModal:this.removeModal.bind(this),onMount:()=>this.mount($,!0)},$)}):null}render(){return h(m,{children:this.getModals()})}}class Popup extends e{constructor(t){super(t),this.dom=o(),this.backdropDom=o(),this.state={popoverStyle:void 0,state:t.state}}async onClose(t){let{onClose:e}=this.props;e(t)}componentWillUnmount(){d(window).unbind("click",this.handleBackClick)}updatePopoverStyle(){let{position:t}=this.props;if("popover"===t){let e=this.getPopoverStyle();JSON.stringify(e)!==JSON.stringify(this.state.popoverStyle)&&this.setState({popoverStyle:e})}}componentDidMount(){let{popover:t={},position:e}=this.props;if(setTimeout(()=>{let{mounted:t,onMount:o}=this.props;this.setState({popoverStyle:"popover"===e?this.getPopoverStyle():{}}),t||o()},0),t.getTarget){this.dui="a"+Math.round(1e7*Math.random());t.getTarget().attr("data-uniq-id",this.dui)}d(window).unbind("click",this.handleBackClick),d(window).bind("click",d.proxy(this.handleBackClick,this))}handleBackClick(t){if(!this.dui)return;let{position:e="fullscreen"}=this.props,o=d(t.target);"popover"===e&&o.attr("data-uniq-id")!==this.dui&&!o.parents(`[data-uniq-id=${this.dui}]`).length&&this.onClose()}header_layout(){let{rtl:t,header:e}=this.props;if("object"!=typeof e)return!1;let{state:o}=this.state;return{html:h(ModalHeader,{rtl:t,header:e,handleClose:t=>this.onClose(t),state:o,setState:t=>this.setState({state:t})}),className:"of-visible"}}body_layout(){let{body:t={}}=this.props,{state:e}=this.state;return{flex:1,html:h(ModalBody,{body:t,state:e,setState:t=>this.setState({state:t}),handleClose:this.onClose.bind(this),updatePopoverStyle:()=>this.updatePopoverStyle()})}}footer_layout(){let{closeText:t,submitText:e,onSubmit:o,footer:i,type:s}=this.props,{state:r}=this.state,a=this.onClose.bind(this);return{html:h(ModalFooter,{closeText:t,submitText:e,onSubmit:o,footer:i,type:s,handleClose:a,state:r,setState:t=>this.setState({state:t})})}}getBackDropClassName(){let{rtl:t,position:e="fullscreen",backdrop:o,mounted:i}=this.props,s="aio-popup-backdrop";return o&&o.attrs&&o.attrs.className&&(s+=" "+o.attrs.className),s+=` aio-popup-position-${e}`,s+=t?" rtl":" ltr",i||(s+=" not-mounted"),s}backClick(t){if(this.isDown)return;t.stopPropagation();let e=d(t.target),{backdrop:o={}}=this.props;!1!==o.close&&e.hasClass("aio-popup-backdrop")&&this.onClose()}getPopoverStyle(){let{popover:t={},rtl:e,attrs:o={}}=this.props,{getTarget:i,pageSelector:s,fitHorizontal:r,fixStyle:a=t=>t}=t;if(!i)return{};let l=i();if(!l||!l.length)return{};let n=d(this.dom.current);return{...Align(n,l,{fixStyle:a,pageSelector:s,fitHorizontal:r,style:o.style,rtl:e}),position:"absolute"}}keyDown(t){let{isLast:e,removeModal:o}=this.props;if(e)27===t.keyCode&&o()}mouseUp(){setTimeout(()=>this.isDown=!1,0)}mouseDown(t){d(window).unbind("mouseup",this.mouseUp),d(window).bind("mouseup",d.proxy(this.mouseUp,this)),this.isDown=!0}render(){let{rtl:t,attrs:e={},backdrop:o={},mounted:i}=this.props,{popoverStyle:s}=this.state,r={...o?o.attrs:{},className:this.getBackDropClassName(),onClick:!1===o?void 0:t=>this.backClick(t)},a={...s,...e.style,flex:"none"},l="aio-popup"+(t?" rtl":" ltr")+(i?"":" not-mounted")+(e.className?" "+e.className:""),n="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown";return h("div",{...r,ref:this.backdropDom,onKeyDown:this.keyDown.bind(this),tabIndex:0,children:h(p,{layout:{attrs:{...e,ref:this.dom,style:void 0,className:void 0,"data-uniq-id":this.dui,[n]:this.mouseDown.bind(this)},className:l,style:a,column:[this.header_layout(),this.body_layout(),this.footer_layout()]}})})}}function ModalHeader({rtl:t,header:e,handleClose:o,state:i,setState:s}){if("object"!=typeof e)return null;let{title:d,subtitle:m,buttons:c=[],onClose:u,backButton:_,attrs:$={}}=e;function f(){u?u({state:i,setState:s}):o({state:i,setState:s})}let g="aio-popup-header"+($.className?" "+$.className:""),v=$.style;return h(p,{layout:{attrs:$,className:g,style:v,row:[function e(){if(!_||!1===u)return!1;let o,i;return t?(o=l,i={marginLeft:12}):(o=n,i={marginRight:12}),{html:h(r,{path:o,size:1}),align:"vh",onClick:()=>f(),style:i}}(),!!d&&(m?{flex:1,align:"v",column:[{html:d,className:"aio-popup-title"},{html:m,className:"aio-popup-subtitle"}]}:{flex:1,align:"v",html:d,className:"aio-popup-title"}),!!c.length&&{gap:6,align:"vh",row:()=>c.map(([t,e={}])=>{let{onClick:r=()=>{},className:a}=e,l={...e};return l.className="aio-popup-header-button"+(a?" "+a:""),l.onClick=()=>r({close:o,state:i,setState:s}),{html:h("button",{...l,children:t}),align:"vh"}})},!_&&!1!==u&&{html:h(r,{path:a,size:.8}),align:"vh",onClick:()=>f(),className:"aio-popup-header-close-button"}]}})}function ModalBody(t){let{handleClose:e,body:o,updatePopoverStyle:s,state:r,setState:a}=t,{render:l,attrs:n={}}=o,p="function"==typeof l?l({close:e,state:r,setState:a}):l;return i(()=>{s()},[p]),h("div",{...n,className:"aio-popup-body"+(n.className?" "+n.className:""),children:"function"==typeof l&&p})}function ModalFooter({footer:t,handleClose:e,state:o,setState:i}){if("object"!=typeof t)return null;let{attrs:s={},buttons:r=[]}=t,a;return h("div",{className:"aio-popup-footer"+(s.className?" "+s.className:""),style:s.style,children:r.length?r.map(([t,s={}])=>{let r="function"==typeof s?{...s({state:o,setState:i})}:{...s},{onClick:a=()=>{},className:l}=r;return r.className="aio-popup-footer-button"+(l?" "+l:""),r.onClick=()=>a({close:e,state:o,setState:i}),h("button",{...r,children:t})}):null})}function Alert(t={}){let{icon:e,type:o,text:i,subtext:r,time:a,className:l,closeText:n}=t,p={time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${p.time}%;"></div>`,updateBarRender(){d(`.aio-popup-alert-container.${p.id} .aio-popup-time`).html(p.getBarRender())},getRender:()=>`
|
|
3
|
-
<div class='aio-popup-alert-container ${p.id}${l?"aio-popup"+l:""}'>
|
|
1
|
+
import t,{Component as e,createRef as o,useEffect as i,useState as r,createContext as a,useContext as n,useRef as l,forwardRef as d,useImperativeHandle as s}from"react";import*as p from"react-dom/server";import{Icon as c}from"@mdi/react";import{mdiClose as u}from"@mdi/js";import _ from"jquery";import"./index.css";import{AddToAttrs as m}from"aio-utils";import{jsx as h}from"react/jsx-runtime";import{Fragment as $}from"react/jsx-runtime";import{jsxs as f}from"react/jsx-runtime";import{createElement as g}from"react";function _defineProperty(t,e,o){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"==typeof e?e:String(e)}function _toPrimitive(t,e){if("object"!=typeof t||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var i=o.call(t,e||"default");if("object"!=typeof i)return i;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}export default class v{constructor(t){_defineProperty(this,"rtl",void 0),_defineProperty(this,"render",void 0),_defineProperty(this,"addModal",void 0),_defineProperty(this,"addAlert",void 0),_defineProperty(this,"removeModal",void 0),_defineProperty(this,"addSnackebar",void 0),_defineProperty(this,"getModals",void 0),_defineProperty(this,"addConfirm",void 0),_defineProperty(this,"addPrompt",void 0),_defineProperty(this,"popupId",void 0),_defineProperty(this,"popupsRef",void 0);let{rtl:e=!1}=t||{};this.rtl=e,this.addSnackebar=()=>{},this.popupsRef=o(),this.getModals=()=>{let t=this.popupsRef.current;return null===t?[]:t.getModals()||[]},this.addModal=t=>{let e=this.popupsRef.current;null!==e&&e.addModal(t)},this.removeModal=t=>{let e=this.popupsRef.current;null!==e&&e.removeModal(t)},this.render=()=>{let t={rtl:e,getActions:({add:t})=>this.addSnackebar=t};return f($,{children:[h(Popups,{rtl:e,ref:this.popupsRef}),h(Snackebar,{...t})]})},this.addAlert=t=>Alert(t),this.addConfirm=t=>{let{title:e,subtitle:o,text:i,submitText:r="Yes",canselText:a="No",onSubmit:n,onCansel:l=()=>{},setAttrs:d=()=>({})}=t,s={position:"center",setAttrs(t){let e=d(t);return"modal"===t?m(e,{className:"aio-popup-confirm"}):e},header:{title:e,subtitle:o},body:()=>i,footer:()=>f($,{children:[h("button",{type:"button",onClick:()=>{l(),this.removeModal()},children:a}),h("button",{type:"button",className:"active",onClick:async()=>{if(n)!1!==await n()&&this.removeModal()},children:r})]})};this.addModal(s)},this.addPrompt=t=>{let{title:e,subtitle:o,text:i,submitText:r="تایید",canselText:a="بستن",onSubmit:n,onCansel:l=()=>{},setAttrs:d=()=>({})}=t,s={position:"center",setAttrs(t){let e=d(t);return"modal"===t?m(e,{className:"aio-popup-prompt"}):e},state:{temp:""},header:{title:e,subtitle:o},body:({state:t,setState:e})=>h("textarea",{placeholder:i,value:t.temp,onChange(t){e&&e({temp:t.target.value})}}),footer:({state:t,setState:e})=>f($,{children:[h("button",{type:"button",onClick:()=>{l(),this.removeModal()},children:a}),h("button",{type:"button",className:"active",onClick:async()=>{if(n)!1!==await n(t.temp)?this.removeModal():e({temp:""})},disabled:!t.temp,children:r})]})};this.addModal(s)}}};let Popups=d((t,e)=>{let[o,i]=r([]),a=l(o);a.current=o;let{rtl:n}=t;function d(t){void 0===t.id&&(t.id="popup"+Math.round(1e6*Math.random()));let e=t;i(o=>[...o.filter(({id:e})=>e!==t.id),e])}async function p(t="last"){if("all"===t){i([]);return}if(!a.current.length)return;"last"===t&&(t=a.current[a.current.length-1].id);let e=a.current.find(e=>e.id===t);e&&(_(`[data-id=${t}]`).addClass("not-mounted"),setTimeout(()=>{"function"==typeof e.onClose&&e.onClose(),i(e=>e.filter(e=>e.id!==t))},300))}function c(){return a.current.map((t,e)=>h(Popup,{modal:t,rtl:n,isLast:e===a.current.length-1,onClose:()=>p(t.id)},t.id))}s(e,()=>({addModal:d,removeModal:p,getModals:()=>a.current}));let u=c();return u.length?h($,{children:u}):null}),CTX=a({});function Popup(t){let{modal:e,rtl:a,onClose:n,isLast:d}=t,{setAttrs:s=()=>({}),id:p,position:c="fullscreen",body:u,getTarget:$,maxHeight:g,fixStyle:v=t=>t,fitTo:b}=e,[y]=r({dom:o(),backdropDom:o(),dui:void 0,isDown:!1}),[k,C]=r({}),[M,w]=r(e.state),L=s("modal")||{},x=s("backdrop")||{},P=l(!1);async function N(){n()}function A(t){if(!y.dui)return;let e=_(t.target);"popover"===c&&e.attr("data-id")!==y.dui&&!e.parents(`[data-id=${y.dui}]`).length&&N()}i(()=>()=>{_(window).unbind("click",A)}),i(()=>{let t="popover"===c?function t(){if(!$)return{};let o=$();if(!o||!o.length)return{};let i={dom:_(y.dom.current),target:o,fitHorizontal:e.fitHorizontal,fixStyle:v,pageSelector:e.pageSelector,limitTo:e.limitTo,fitTo:b,attrs:L,rtl:a},r={...Align(i),position:"absolute"};return g&&(r.maxHeight=g),r}():{};if(console.log("updatedStyle.top",t.top),C(t),$){y.dui="a"+Math.round(1e7*Math.random());$().attr("data-id",y.dui)}setTimeout(()=>{let t=_(y.dom.current);t.removeClass("not-mounted"),_(y.backdropDom.current).removeClass("not-mounted"),t.focus()},0),_(window).unbind("click",A),_(window).bind("click",A)},[]);function H(t){if(d)27===t.keyCode&&n()}function S(){setTimeout(()=>y.isDown=!1,0)}let D,R,T,B;return h(CTX.Provider,{value:{close:N,state:M,setState:w},children:h("div",{...(D="aio-popup-backdrop",D+=` aio-popup-position-${c}`,D+=a?" rtl":" ltr",P&&(D+=" not-mounted"),m(x,{className:D,attrs:{ref:y.backdropDom,onKeyDown:H,tabIndex:0,"data-id":p,onClick:x.onClick?x.onClick:function t(e){if(!y.isDown){e.stopPropagation();_(e.target).hasClass("aio-popup-backdrop")&&N()}}}})),children:f("div",{...(R={...k,...L.style},T="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown",{...L,ref:y.dom,"data-id":e.id,tabIndex:0,onKeyDown:H,[T]:function t(e){_(window).unbind("mouseup",S),_(window).bind("mouseup",S),y.isDown=!0},className:(B="aio-popup",B+=a?" rtl":" ltr",P&&(B+=" not-mounted"),L.className&&(B+=" "+L.className),B),style:{...R}}),children:[!!e.header&&h(ModalHeader,{modal:e}),h(ModalBody,{modal:e}),!!e.footer&&h("div",{...m(s("footer"),{className:"aio-popup-footer"}),children:e.footer({state:M,setState:w,close:N})})]})})})}let ModalHeader=t=>{let e=n(CTX),{modal:o}=t,{state:i,setState:r}=e,{setAttrs:a=()=>({})}=o,l=a("modal")||{};if("function"==typeof o.header)return o.header({close:e.close,state:i,setState:r});if("object"!=typeof o.header)return null;let d="aio-popup-header",{title:s,subtitle:p,onClose:_,before:$,after:g}=o.header;function v(t){t.stopPropagation(),t.preventDefault(),"function"==typeof _?_({state:i,setState:r}):e.close()}function b(){return p?f("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",flex:1},children:[h("div",{className:`${d}-title`,children:s}),h("div",{className:`${d}-subtitle`,children:p})]}):h("div",{className:`${d}-title`,style:{display:"flex",alignItems:"center",flex:1},children:s})}return f("div",{...m(l,{className:d}),children:[void 0!==$&&h("div",{className:`${d}-before`,onClick:t=>v(t),children:$}),!!s&&b(),void 0!==g&&h("div",{className:`${d}-after`,onClick:t=>v(t),children:g}),!1!==_&&h("div",{className:`${d}-close-button`,onClick:t=>v(t),children:h(c,{path:u,size:.8})})]})},ModalBody=t=>{let{state:e,setState:o,close:i}=n(CTX),{modal:r}=t,{body:a=()=>null,setAttrs:l=()=>({})}=r,d=l("body")||{},s=a({close:i,state:e,setState:o});return s&&null!==s?h("div",{...m(d,{className:"aio-popup-body aio-popup-scroll"}),children:s}):null};function Alert(t){let{icon:e,type:o="",text:i="",subtext:r="",time:a=10,className:n,closeText:l="بستن",position:d="center"}=t,s={id:"",time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${s.time}%;"></div>`,updateBarRender(){_(`.aio-popup-alert-container.${s.id} .aio-popup-time`).html(s.getBarRender())},getRender:()=>`
|
|
2
|
+
<div class='aio-popup-alert-container not-mounted ${s.id} aio-popup-alert-container-${d}'>
|
|
4
3
|
<div class='aio-popup-alert aio-popup-alert-${o}'>
|
|
5
|
-
<div class='aio-popup-alert-header'>${
|
|
6
|
-
<div class='aio-popup-alert-body'>
|
|
7
|
-
<div class='aio-popup-alert-text'>${
|
|
4
|
+
<div class='aio-popup-alert-header'>${s.getIcon()}</div>
|
|
5
|
+
<div class='aio-popup-alert-body aio-popup-scroll'>
|
|
6
|
+
<div class='aio-popup-alert-text'>${p.renderToStaticMarkup(i)}</div>
|
|
8
7
|
<div class='aio-popup-alert-subtext'>${r}</div>
|
|
9
8
|
</div>
|
|
10
9
|
<div class='aio-popup-alert-footer'>
|
|
11
|
-
<button class='aio-popup-alert-close ${
|
|
10
|
+
<button class='aio-popup-alert-close ${s.id}'>${l}</button>
|
|
12
11
|
</div>
|
|
13
12
|
<div class='aio-popup-time'></div>
|
|
14
|
-
</div>
|
|
13
|
+
</div>
|
|
15
14
|
</div>
|
|
16
|
-
`,close(){
|
|
15
|
+
`,close(){s.toggleClass(!1),setTimeout(()=>_("."+s.id).remove(),200)},getIcon:()=>!1===e?"":e||({error:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg>',warning:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12,2L1,21H23M12,6L19.53,19H4.47M11,10V14H13V10M11,16V18H13V16"></path></svg>',info:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"></path></svg>',success:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"></path></svg>'})[o]||"",startTimer(){setTimeout(()=>{if(s.time>=100){s.time=100,s.close();return}s.time+=2,s.updateBarRender(),s.startTimer()},a/50*1e3)},toggleClass(t){let e=_(`.${s.id}`);t?setTimeout(()=>e.removeClass("not-mounted"),0):e.addClass("not-mounted")},render(){_("body").append(s.getRender()),_("button."+s.id).off("click",s.close),_("button."+s.id).on("click",s.close),s.toggleClass(!0)}};s.id=s.getId(),s.render(),a&&s.startTimer()}class Snackebar extends e{constructor(t){super(t),this.state={items:[]},t.getActions({add:this.add.bind(this)})}add(t){let{items:e}=this.state,o=[...e,{...t,id:"a"+Math.round(1e9*Math.random())}];this.setState({items:o})}remove(t){let{items:e}=this.state,o=e.filter((e,o)=>e.id!==t);this.setState({items:o})}render(){let{items:t}=this.state,{rtl:e}=this.props;return h($,{children:t.map((t,o)=>g(SnackebarItem,{rtl:e,item:t,index:o,onRemove:t=>this.remove(t),key:t.id}))})}}function SnackebarItem(t){var e;let{item:o,onRemove:a,index:n,rtl:l}=t,{time:d=8,id:s,text:p,type:c,subtext:u,action:m,onClose:$,verticalAlign:g="end",horizontalAlign:v="center",icon:b,attrs:y={}}=o;"start"!==g&&"end"!==g&&(g="end",console.error('aio-popup error => snackebar item .verticalAlign should be "start" or "end"')),"start"!==v&&"end"!==v&&"center"!==v&&(v="center",console.error('aio-popup error => snackebar item .horizontalAlign should be "start" or "end" or "center"'));let[k,C]=r(!1);function M(){C(!1),setTimeout(()=>{a(s)},200)}i(()=>{setTimeout(()=>C(!0),0),setTimeout(()=>M(),1e3*d)},[]);let w,L,x,P;return w="aio-popup-snackebar-item-container",w+=` aio-popup-snackebar-item-container-horizontal-align-${v}`,k&&(w+=" mounted"),l&&(w+=" rtl"),L=function t(e){let o=_(".aio-popup-snackebar-item-container"),i={start:12,end:12};for(let r=0;r<e;r++){let a=o.eq(r),n=a.height()+6,l=a.attr("data-vertical-align");i[l]+=n}return{["start"===g?"top":"bottom"]:i[g]}}(n),x={"data-vertical-align":g,className:w,style:L,onClick:!1===$?void 0:()=>M()},h("div",{...x,children:(P="aio-popup-snackebar-item",P+=` aio-popup-snackebar-item-${c}`,y.className&&(P+=` ${y.className}`),f("div",{...{...y,className:P,style:y.style},children:[h("div",{className:"aio-popup-snackebar-item-icon",children:b||("error"===(e=c)||"warning"===e||"info"===e?h("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:h("path",{d:"M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z",style:{fill:"currentcolor"}})}):h("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:h("path",{d:"M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z",style:{fill:"currentcolor"}})}))})," ",f("div",{className:"aio-popup-snackebar-item-text",children:[h("div",{className:"aio-popup-snackebar-item-uptext",children:p}),!!u&&h("div",{className:"aio-popup-snackebar-item-subtext",children:u})]})," ",m&&m.text?h("button",{className:"aio-popup-snackebar-item-action",onClick(t){t.stopPropagation(),m.onClick(),M()},children:m.text}):null," ",h("div",{className:"aio-popup-snackebar-bar",style:{transition:`${d}s linear`}})," "]}))})}function Align(t){let{dom:e,target:o,fitHorizontal:i,fixStyle:r=t=>t,attrs:a={},fitTo:n,pageSelector:l,rtl:d,limitTo:s}=t,p={getDomLimit(t,e){if(n&&"popover"===e){let o=t.parents(n);if(o.length){let{left:i,top:r}=o.offset(),a=o.width(),d=o.height();return{left:i,top:r,right:i+a,bottom:r+d,width:a,height:d}}}let s=t.offset(),p=s.left-window.pageXOffset,c=s.top-window.pageYOffset;if(l&&"page"!==e){let u=_(l);try{let{left:m,top:h}=u.offset()||{left:0,top:0};p-=m,c-=h}catch{}}let $=t.outerWidth(),f=t.outerHeight(),g=p+$,v=c+f;return{left:p,top:c,right:g,bottom:v,width:$,height:f}},getPageLimit(){let t=l?_(l):void 0;t=Array.isArray(t)&&0===t.length?void 0:t;let e=window.innerWidth,o=window.innerHeight,i=t?p.getDomLimit(t,"page"):{left:0,top:0,right:e,bottom:o};return i.left<0&&(i.left=0),i.right>e&&(i.right=e),i.top<0&&(i.top=0),i.bottom>o&&(i.bottom=o),i},getRelatedToLmit(){if(!s)return;let t=e.parents(s);if(!t.length)return;let o=t.offset(),i=o.left-window.pageXOffset,r=o.top-window.pageYOffset,a=t.outerWidth(),n=t.outerHeight();return{left:i,top:r,right:i+a,bottom:r+n,width:a,height:n}},align(){let t=p.getPageLimit(),l=p.getDomLimit(o,"target"),s=p.getDomLimit(e,"popover"),c;if(!n){if(s.top=l.bottom,s.bottom=s.top+s.height,i)s.width=l.width,s.left=l.left,s.right=l.left+l.width;else{let u=p.getRelatedToLmit()||t;d?(s.right=l.right,s.left=s.right-s.width,s.left<u.left&&(s.left=u.left)):(s.left=l.left,s.right=s.left+s.width,s.right>u.right&&(s.left=u.right-s.width))}s.bottom>t.bottom?s.height>l.top-t.top?s.top=t.bottom-s.height:s.top=l.top-s.height:s.top=l.bottom,s.height>t.bottom-t.top&&(s.top=6,s.bottom=void 0,s.height=t.bottom-t.top-12,c="auto")}let _;return r({left:s.left,top:s.top,width:s.width,height:n?s.height:void 0,overflowY:c,...a.style},{targetLimit:l,pageLimit:t})}};return p.align()}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-popup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "handle all types of popup and modals in react",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
|
+
"types":"index.d.ts",
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
11
12
|
"url": "git+https://github.com/mohammadFeiz/aio-popup.git"
|
|
@@ -13,8 +14,7 @@
|
|
|
13
14
|
"dependencies": {
|
|
14
15
|
"@mdi/js": "^7.0.96",
|
|
15
16
|
"@mdi/react": "^1.6.1",
|
|
16
|
-
"jquery": "^3.6.1"
|
|
17
|
-
"react-virtual-dom": "latest"
|
|
17
|
+
"jquery": "^3.6.1"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"popup",
|