dce-reactkit 3.0.19 → 3.0.22
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/dist/cjs/index.js +24 -159
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +25 -160
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Modal.tsx +16 -167
package/src/components/Modal.tsx
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Import React
|
|
7
|
-
import React
|
|
8
|
-
|
|
9
|
-
// Import other components
|
|
10
|
-
import waitMs from '../helpers/waitMs';
|
|
7
|
+
import React from 'react';
|
|
11
8
|
|
|
12
9
|
// Import types
|
|
13
10
|
import Variant from '../types/Variant';
|
|
@@ -135,23 +132,6 @@ const style = `
|
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
|
|
138
|
-
.Modal-fading-out {
|
|
139
|
-
animation-name: Modal-fading-out;
|
|
140
|
-
animation-duration: ${MS_TO_ANIMATE}ms;
|
|
141
|
-
animation-iteration-count: 1;
|
|
142
|
-
animation-fill-mode: both;
|
|
143
|
-
animation-timing-function: ease-in;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
@keyframes Modal-fading-out {
|
|
147
|
-
0% {
|
|
148
|
-
opacity: 1;
|
|
149
|
-
}
|
|
150
|
-
100% {
|
|
151
|
-
opacity: 0;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
135
|
.Modal-animating-in {
|
|
156
136
|
animation-name: Modal-animating-in;
|
|
157
137
|
animation-duration: ${MS_TO_ANIMATE}ms;
|
|
@@ -170,48 +150,6 @@ const style = `
|
|
|
170
150
|
opacity: 1;
|
|
171
151
|
}
|
|
172
152
|
}
|
|
173
|
-
|
|
174
|
-
.Modal-animating-pop {
|
|
175
|
-
animation-name: Modal-animating-pop;
|
|
176
|
-
animation-duration: ${MS_TO_ANIMATE}ms;
|
|
177
|
-
animation-iteration-count: 1;
|
|
178
|
-
animation-fill-mode: both;
|
|
179
|
-
animation-timing-function: ease-in-out;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
@keyframes Modal-animating-pop {
|
|
183
|
-
0% {
|
|
184
|
-
transform: scale(1);
|
|
185
|
-
opacity: 1;
|
|
186
|
-
}
|
|
187
|
-
50% {
|
|
188
|
-
transform: scale(1.05);
|
|
189
|
-
opacity: 0.9;
|
|
190
|
-
}
|
|
191
|
-
100% {
|
|
192
|
-
transform: scale(1);
|
|
193
|
-
opacity: 1;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
.Modal-animating-out {
|
|
198
|
-
animation-name: Modal-animating-out;
|
|
199
|
-
animation-duration: ${MS_TO_ANIMATE}ms;
|
|
200
|
-
animation-iteration-count: 1;
|
|
201
|
-
animation-fill-mode: both;
|
|
202
|
-
animation-timing-function: ease-in;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
@keyframes Modal-animating-out {
|
|
206
|
-
0% {
|
|
207
|
-
transform: scale(1) translate(0, 0);
|
|
208
|
-
opacity: 1;
|
|
209
|
-
}
|
|
210
|
-
100% {
|
|
211
|
-
transform: scale(1.05) translate(0, -1.5rem);
|
|
212
|
-
opacity: 0;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
153
|
`;
|
|
216
154
|
|
|
217
155
|
/*------------------------------------------------------------------------*/
|
|
@@ -296,77 +234,6 @@ const Modal: React.FC<Props> = (props) => {
|
|
|
296
234
|
onTopOfOtherModals,
|
|
297
235
|
} = props;
|
|
298
236
|
|
|
299
|
-
/* -------------- State ------------- */
|
|
300
|
-
|
|
301
|
-
// If true, the modal is shown
|
|
302
|
-
const [visible, setVisible] = useState(false);
|
|
303
|
-
|
|
304
|
-
// True if animation is in use
|
|
305
|
-
const [animatingIn, setAnimatingIn] = useState(true);
|
|
306
|
-
const [animatingPop, setAnimatingPop] = useState(false);
|
|
307
|
-
const [animatingOut, setAnimatingOut] = useState(false);
|
|
308
|
-
|
|
309
|
-
/*------------------------------------------------------------------------*/
|
|
310
|
-
/* Lifecycle Functions */
|
|
311
|
-
/*------------------------------------------------------------------------*/
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Mount
|
|
315
|
-
* @author Gabe Abrams
|
|
316
|
-
*/
|
|
317
|
-
useEffect(
|
|
318
|
-
() => {
|
|
319
|
-
(async () => {
|
|
320
|
-
// Set defaults
|
|
321
|
-
setVisible(false);
|
|
322
|
-
setAnimatingIn(true);
|
|
323
|
-
setAnimatingPop(false);
|
|
324
|
-
setAnimatingOut(false);
|
|
325
|
-
// Wait for animation
|
|
326
|
-
await waitMs(MS_TO_ANIMATE);
|
|
327
|
-
// Update to state after animated in
|
|
328
|
-
setVisible(true);
|
|
329
|
-
setAnimatingIn(false);
|
|
330
|
-
})();
|
|
331
|
-
},
|
|
332
|
-
[],
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
/*------------------------------------------------------------------------*/
|
|
336
|
-
/* Component Functions */
|
|
337
|
-
/*------------------------------------------------------------------------*/
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Handles the closing of the modal
|
|
341
|
-
* @author Gabe Abrams
|
|
342
|
-
* @param ModalButtonType the button that was clicked when closing the
|
|
343
|
-
* modal
|
|
344
|
-
*/
|
|
345
|
-
const handleClose = async (ModalButtonType: ModalButtonType) => {
|
|
346
|
-
// Don't close if no handler
|
|
347
|
-
if (!onClose) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// Don't close if animating in
|
|
352
|
-
if (animatingIn) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// Don't close if already closed
|
|
357
|
-
if (!visible) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// Update the state
|
|
362
|
-
setVisible(false);
|
|
363
|
-
setAnimatingOut(true);
|
|
364
|
-
|
|
365
|
-
// Call the handler after the modal has animated out
|
|
366
|
-
await waitMs(MS_TO_ANIMATE);
|
|
367
|
-
onClose(ModalButtonType);
|
|
368
|
-
};
|
|
369
|
-
|
|
370
237
|
/*------------------------------------------------------------------------*/
|
|
371
238
|
/* Render */
|
|
372
239
|
/*------------------------------------------------------------------------*/
|
|
@@ -379,19 +246,19 @@ const Modal: React.FC<Props> = (props) => {
|
|
|
379
246
|
const ModalButtonTypes: ModalButtonType[] = modalTypeToModalButtonTypes[type] ?? [];
|
|
380
247
|
|
|
381
248
|
// Create buttons
|
|
382
|
-
const buttons = ModalButtonTypes.map((
|
|
249
|
+
const buttons = ModalButtonTypes.map((buttonType: ModalButtonType, i) => {
|
|
383
250
|
// Get default style
|
|
384
251
|
let {
|
|
385
252
|
label,
|
|
386
253
|
variant,
|
|
387
|
-
} = ModalButtonTypeToLabelAndVariant[
|
|
254
|
+
} = ModalButtonTypeToLabelAndVariant[buttonType];
|
|
388
255
|
|
|
389
256
|
// Override with customizations
|
|
390
|
-
const newLabel = props[`${
|
|
257
|
+
const newLabel = props[`${buttonType}Label`];
|
|
391
258
|
if (newLabel) {
|
|
392
259
|
label = newLabel;
|
|
393
260
|
}
|
|
394
|
-
const newVariant = props[`${
|
|
261
|
+
const newVariant = props[`${buttonType}Variant`];
|
|
395
262
|
if (newVariant) {
|
|
396
263
|
variant = newVariant;
|
|
397
264
|
}
|
|
@@ -402,11 +269,13 @@ const Modal: React.FC<Props> = (props) => {
|
|
|
402
269
|
// Create the button
|
|
403
270
|
return (
|
|
404
271
|
<button
|
|
405
|
-
key={
|
|
272
|
+
key={buttonType}
|
|
406
273
|
type="button"
|
|
407
|
-
className={`Modal-${
|
|
274
|
+
className={`Modal-${buttonType}-button btn btn-${variant} ${last ? '' : 'me-1'}`}
|
|
408
275
|
onClick={() => {
|
|
409
|
-
|
|
276
|
+
if (onClose) {
|
|
277
|
+
onClose(buttonType);
|
|
278
|
+
}
|
|
410
279
|
}}
|
|
411
280
|
>
|
|
412
281
|
{label}
|
|
@@ -425,23 +294,10 @@ const Modal: React.FC<Props> = (props) => {
|
|
|
425
294
|
: undefined
|
|
426
295
|
);
|
|
427
296
|
|
|
428
|
-
// Choose an animation
|
|
429
|
-
let animationClass = '';
|
|
430
|
-
let backdropAnimationClass = '';
|
|
431
|
-
if (animatingIn) {
|
|
432
|
-
animationClass = 'Modal-animating-in';
|
|
433
|
-
backdropAnimationClass = 'Modal-fading-in';
|
|
434
|
-
} else if (animatingOut) {
|
|
435
|
-
animationClass = 'Modal-animating-out';
|
|
436
|
-
backdropAnimationClass = 'Modal-fading-out';
|
|
437
|
-
} else if (animatingPop) {
|
|
438
|
-
animationClass = 'Modal-animating-pop';
|
|
439
|
-
}
|
|
440
|
-
|
|
441
297
|
// Render the modal
|
|
442
298
|
return (
|
|
443
299
|
<div
|
|
444
|
-
className=
|
|
300
|
+
className="modal show modal-dialog-scrollable modal-dialog-centered"
|
|
445
301
|
tabIndex={-1}
|
|
446
302
|
style={{
|
|
447
303
|
zIndex: (
|
|
@@ -457,29 +313,22 @@ const Modal: React.FC<Props> = (props) => {
|
|
|
457
313
|
>
|
|
458
314
|
<style>{style}</style>
|
|
459
315
|
<div
|
|
460
|
-
className=
|
|
316
|
+
className="Modal-backdrop Modal-fading-in"
|
|
461
317
|
style={{
|
|
462
318
|
zIndex: 5000000003,
|
|
463
319
|
}}
|
|
464
320
|
onClick={async () => {
|
|
465
321
|
// Skip if exit via backdrop not allowed
|
|
466
322
|
if (dontAllowBackdropExit || !onClose) {
|
|
467
|
-
// Show pop animation
|
|
468
|
-
if (!animatingPop) {
|
|
469
|
-
setAnimatingPop(true);
|
|
470
|
-
|
|
471
|
-
// Wait then stop pop animation
|
|
472
|
-
await waitMs(MS_TO_ANIMATE);
|
|
473
|
-
setAnimatingPop(false);
|
|
474
|
-
}
|
|
475
323
|
return;
|
|
476
324
|
}
|
|
325
|
+
|
|
477
326
|
// Handle close
|
|
478
|
-
|
|
327
|
+
onClose(ModalButtonType.Cancel);
|
|
479
328
|
}}
|
|
480
329
|
/>
|
|
481
330
|
<div
|
|
482
|
-
className={`modal-dialog modal-${size}
|
|
331
|
+
className={`modal-dialog modal-${size} Modal-animating-in`}
|
|
483
332
|
style={{
|
|
484
333
|
zIndex: 5000000002,
|
|
485
334
|
}}
|
|
@@ -502,7 +351,7 @@ const Modal: React.FC<Props> = (props) => {
|
|
|
502
351
|
aria-label="Close"
|
|
503
352
|
onClick={() => {
|
|
504
353
|
// Handle close
|
|
505
|
-
|
|
354
|
+
onClose(ModalButtonType.Cancel);
|
|
506
355
|
}}
|
|
507
356
|
/>
|
|
508
357
|
)}
|