@@ -2,7 +2,7 @@ import React, { useEffect, useState, useImperativeHandle, forwardRef } from 'rea
2
2
3
3
import './AnimatedModal.styles.scss' ;
4
4
5
- import { ModalAnimation , Sketch , Unfold } from './animations ' ;
5
+ import { ModalAnimation } from './AnimatedModal.enums ' ;
6
6
7
7
/**
8
8
* Animated Modal's props.
@@ -13,70 +13,34 @@ import { ModalAnimation, Sketch, Unfold } from './animations';
13
13
* @property {boolean } [closeOnBackgroundClick] Close modal on background click?
14
14
*/
15
15
interface IAnimatedModalProps {
16
- /**
17
- * Open Modal on startup.
18
- * @param {boolean } [startOpen] Open Modal on startup?
19
- * @default false
20
- */
21
- startOpen ?: boolean ;
22
-
23
- /**
24
- * Modal animation.
25
- * @param {ModalAnimation } animation Modal animation
26
- * @default new Unfold()
27
- */
16
+ isOpen ?: boolean ;
28
17
animation : ModalAnimation ;
29
-
30
- /**
31
- * Modal's children.
32
- * @param {React.ReactNode } [children] Modal's children
33
- */
34
18
children ?: React . ReactNode ;
35
-
36
- /**
37
- * Close modal on background click.
38
- * @param {boolean } [closeOnBackgroundClick] Close modal on background click?
39
- * @default true
40
- */
41
19
closeOnBackgroundClick ?: boolean ;
42
20
}
43
21
44
22
/**
45
23
* Animated Modal's object.
46
24
* @type AnimatedModalObject
47
- * @member {() => void} OpenModal Open modal
48
- * @member {() => void} CloseModal Close modal
49
- * @member {() => boolean} IsModalOpen Is modal open?
25
+ * @property {() => void } OpenModal Open modal
26
+ * @property {() => void } CloseModal Close modal
27
+ * @property {() => boolean } IsModalOpen Is modal open?
50
28
*/
51
29
export type AnimatedModalObject = {
52
- /**
53
- * Open modal.
54
- * @param {string } [animation] Modal animation
55
- * @returns {void } void
56
- */
57
30
// eslint-disable-next-line no-unused-vars
58
- OpenModal : ( animation ?: string ) => void ;
59
-
60
- /**
61
- * Close modal with open modal animation.
62
- * @returns {void } void
63
- */
31
+ OpenModal : ( modalAnimation ?: ModalAnimation ) => void ;
64
32
CloseModal : ( ) => void ;
65
-
66
- /**
67
- * Check if modal is open.
68
- * @returns {boolean } is modal open?
69
- */
70
33
IsModalOpen : ( ) => boolean ;
71
34
} ;
72
35
73
36
/**
74
37
* Animated Modal.
38
+ *
75
39
* @param {IAnimatedModalProps } props Animated modal's props
76
40
* @param {React.Ref<AnimatedModalObject> } ref Animated modal's ref
77
41
* @returns AnimatedModal.
78
42
*/
79
- export const AnimatedModal = forwardRef (
43
+ const AnimatedModal = forwardRef (
80
44
( props : IAnimatedModalProps , ref : React . Ref < AnimatedModalObject > ) => {
81
45
// State
82
46
const [ modalClass , setModalClass ] = useState ( '' ) ;
@@ -96,12 +60,12 @@ export const AnimatedModal = forwardRef(
96
60
97
61
/**
98
62
* Open modal.
99
- * @param {string } animation Modal animation
63
+ * @param {ModalAnimation } modalAnimation Modal animation
100
64
* @returns {void }
101
65
*/
102
- function openModal ( animation ?: string ) : void {
103
- if ( animation ) setModalClass ( animation ) ;
104
- else setModalClass ( props . animation . getAnimationName ( ) ) ;
66
+ function openModal ( modalAnimation ?: ModalAnimation ) : void {
67
+ if ( modalAnimation ) setModalClass ( modalAnimation ) ;
68
+ else setModalClass ( props . animation ) ;
105
69
106
70
document . body . classList . add ( 'modal-active' ) ;
107
71
}
@@ -151,11 +115,11 @@ export const AnimatedModal = forwardRef(
151
115
}
152
116
153
117
useEffect ( ( ) => {
154
- if ( props . startOpen ) {
155
- setModalClass ( props . animation . getAnimationName ( ) ) ;
118
+ if ( props . isOpen ) {
119
+ setModalClass ( props . animation ) ;
156
120
document . body . classList . add ( 'modal-active' ) ;
157
121
}
158
- } , [ props . startOpen ] ) ;
122
+ } , [ props . isOpen ] ) ;
159
123
160
124
/**
161
125
* Default modal.
@@ -175,28 +139,20 @@ export const AnimatedModal = forwardRef(
175
139
) ;
176
140
}
177
141
178
- function sketchSVG ( ) : React . ReactElement {
179
- return (
180
- < svg
181
- id = "modal-sketch-svg"
182
- xmlns = "http://www.w3.org/2000/svg"
183
- width = "100%"
184
- height = "100%"
185
- preserveAspectRatio = "none" >
186
- < rect x = "0" y = "0" fill = "none" width = "226" height = "162" rx = "3" ry = "3" > </ rect >
187
- </ svg >
188
- ) ;
189
- }
190
-
191
- console . log ( modalClass ) ;
192
-
193
142
return (
194
143
< div id = "animated-modal-container" className = { modalClass } >
195
144
< div
196
145
id = "animated-modal-background"
197
146
onClick = { props . closeOnBackgroundClick ? onBackgroundClick : undefined } >
198
147
< div id = "animated-modal" >
199
- { modalClass . includes ( Sketch . animationName ) ? sketchSVG ( ) : undefined }
148
+ < svg
149
+ id = "modal-sketch-svg"
150
+ xmlns = "http://www.w3.org/2000/svg"
151
+ width = "100%"
152
+ height = "100%"
153
+ preserveAspectRatio = "none" >
154
+ < rect x = "0" y = "0" fill = "none" width = "226" height = "162" rx = "3" ry = "3" > </ rect >
155
+ </ svg >
200
156
< div id = "modal-content" > { props . children ? props . children : defaultModal ( ) } </ div >
201
157
</ div >
202
158
</ div >
@@ -210,7 +166,9 @@ AnimatedModal.displayName = 'AnimatedModal';
210
166
211
167
// Set default props
212
168
AnimatedModal . defaultProps = {
213
- startOpen : false ,
214
- animation : new Unfold ( ) ,
169
+ isOpen : false ,
170
+ animation : ModalAnimation . Unfold ,
215
171
closeOnBackgroundClick : true
216
172
} ;
173
+
174
+ export default AnimatedModal ;
0 commit comments