@@ -30,6 +30,13 @@ import { AnimatedDialog } from "@pnp/spfx-controls-react/lib/AnimatedDialog";
30
30
The code below adds a dialog with an entrance animation of ` bounceIn ` and exit animation of ` zoomOut ` . (These are the default animations)
31
31
32
32
``` TypeScript
33
+ // Initial state
34
+ this .state = {
35
+ showAnimatedDialog: false
36
+ }
37
+ ...
38
+ ...
39
+ // Properties of the dialog
33
40
const animatedDialogContentProps: IDialogContentProps = {
34
41
type: DialogType .normal ,
35
42
title: ' Animated Dialog' ,
@@ -41,6 +48,9 @@ const animatedModalProps: IModalProps = {
41
48
};
42
49
...
43
50
...
51
+ // Add a control (like a button) that changes the state showAnimatedDialog to true
52
+
53
+ // Render the animated dialog
44
54
< AnimatedDialog
45
55
hidden = {!this.state.showAnimatedDialog }
46
56
onDismiss = {() => { this .setState ({ showAnimatedDialog: false }); }}
@@ -62,6 +72,13 @@ const animatedModalProps: IModalProps = {
62
72
The code below adds adds a dialog with an entrance animation of ` fadeInDown ` and exit animation of ` fadeInDown ` .
63
73
64
74
``` TypeScript
75
+ // Initial state
76
+ this .state = {
77
+ showAnimatedDialog: false
78
+ }
79
+ ...
80
+ ...
81
+ // Properties of the dialog
65
82
const animatedDialogContentProps: IDialogContentProps = {
66
83
type: DialogType .normal ,
67
84
title: ' Animated Dialog' ,
@@ -73,6 +90,9 @@ const animatedModalProps: IModalProps = {
73
90
};
74
91
...
75
92
...
93
+ // Add a control (like a button) that changes the state showAnimatedDialog to true
94
+
95
+ // Render the animated dialog
76
96
< AnimatedDialog
77
97
hidden = {!this.state.showAnimatedDialog }
78
98
onDismiss = {() => { this .setState ({ showAnimatedDialog: false }); }}
@@ -103,10 +123,23 @@ The code below does the following:
103
123
- onError: The function that gets executed when the ` onOkClick ` function fails.
104
124
105
125
``` TypeScript
126
+ // Initial state
127
+ this .state = {
128
+ showCustomisedAnimatedDialog: false ,
129
+ showSuccessDialog: false ,
130
+ showErrorDialog: false
131
+ }
132
+ ...
133
+ ...
106
134
const animatedDialogContentProps: IDialogContentProps = {
107
135
type: DialogType .normal ,
108
136
title: ' Animated Dialog with icon'
109
- };
137
+ };
138
+
139
+ const successDialogContentProps: IDialogContentProps = {
140
+ type: DialogType .normal ,
141
+ title: ' Good answer!'
142
+ };
110
143
111
144
const animatedModalProps: IModalProps = {
112
145
isDarkOverlay: true ,
@@ -119,6 +152,9 @@ const timeout = (ms: number): Promise<void> => {
119
152
};
120
153
...
121
154
...
155
+ // Add a control (like a button) that changes the state showAnimatedDialog to true
156
+
157
+ // Render the animated dialog
122
158
< AnimatedDialog
123
159
hidden = {!this.state.showCustomisedAnimatedDialog }
124
160
onDismiss = {() => { this .setState ({ showCustomisedAnimatedDialog: false }); }}
@@ -142,13 +178,14 @@ const timeout = (ms: number): Promise<void> => {
142
178
< / div >
143
179
< / AnimatedDialog >
144
180
145
- // Success dialog
181
+ // Render success animated dialog which will appear after the execution
182
+ // of onSuccess function in the above animated dialog
146
183
147
184
< AnimatedDialog
148
185
hidden = {!this.state.showSuccessDialog }
149
186
onDismiss = {() => { this .setState ({ showSuccessDialog: false }); }}
150
187
dialogContentProps = {successDialogContentProps }
151
- modalProps = {customizedAnimatedModalProps }
188
+ modalProps = {animatedModalProps }
152
189
iconName = ' CompletedSolid'
153
190
>
154
191
< div className = {styles.dialogContent }> <span >Thank you .< / span></ div >
@@ -168,22 +205,34 @@ const timeout = (ms: number): Promise<void> => {
168
205
If the dialog content and footer buttons need to be controlled by our code and not the animated dialog control then the code below can be used
169
206
170
207
` ` ` TypeScript
208
+ // Initial state
209
+ this .state = {
210
+ showCustomisedAnimatedDialog: false ,
211
+ showSuccessDialog: false ,
212
+ showErrorDialog: false ,
213
+ showLoading: false
214
+ }
215
+ ...
216
+ ...
171
217
const animatedDialogContentProps : IDialogContentProps = {
172
218
type: DialogType .normal ,
173
219
title: ' Custom content and footer'
174
- };
220
+ };
221
+
222
+ const successDialogContentProps: IDialogContentProps = {
223
+ type: DialogType .normal ,
224
+ title: ' Good answer!'
225
+ };
175
226
176
227
const animatedModalProps: IModalProps = {
177
228
isDarkOverlay: true ,
178
229
containerClassName: ` ${styles .dialogContainer } `
179
230
};
180
-
181
- // The operation that does something - e.g. update data
182
- const timeout = (ms : number ): Promise <void > => {
183
- return new Promise ((resolve , reject ) => setTimeout (reject , ms ));
184
- };
185
231
...
186
232
...
233
+ // Add a control (like a button) that changes the state showAnimatedDialog to true
234
+
235
+ // Render the animated dialog
187
236
< AnimatedDialog
188
237
hidden = {!this.state.showCustomisedAnimatedDialog }
189
238
onDismiss = {() => { this .setState ({ showCustomisedAnimatedDialog: false }); }}
@@ -192,38 +241,38 @@ const timeout = (ms: number): Promise<void> => {
192
241
iconName = ' UnknownSolid' >
193
242
194
243
< div className = {styles.dialogContent }>
195
- <span >Do you like the animated dialog ? </span >
244
+ <span >Do you like the animated dialog ? </span >
196
245
< / div >
197
246
198
247
< div className = {styles.dialogFooter }>
199
- < PrimaryButton
200
- onClick = {() => {
248
+ < PrimaryButton
249
+ onClick = {() => {
250
+ this .setState ({ showLoading: true });
251
+ setTimeout (() => {
201
252
this .setState ({ showLoading: true });
202
- setTimeout (() => {
203
- this .setState ({ showLoading: true });
204
- this .setState ({ showCustomisedAnimatedDialog: false });
205
- this .setState ({ showSuccessDialog: true });
206
- }, 1500 );
207
- }}
208
- disabled = {this.state.showLoading } text = {!this.state.showLoading && " Yeah!" }>
209
- {this.state.showLoading && <Spinner size = {SpinnerSize.medium } / > }
210
- < / PrimaryButton >
211
-
212
- < DefaultButton
213
- onClick = {this.setState({ showCustomisedAnimatedDialog : false });}
214
- text = " Nope"
215
- disabled = {this.state.showLoading } / >
253
+ this .setState ({ showCustomisedAnimatedDialog: false });
254
+ this .setState ({ showSuccessDialog: true });
255
+ }, 1500 );
256
+ }}
257
+ disabled = {this.state.showLoading } text = {!this.state.showLoading && " Yeah!" }>
258
+ {this.state.showLoading && <Spinner size = {SpinnerSize.medium } / > }
259
+ < / PrimaryButton >
260
+
261
+ < DefaultButton
262
+ onClick = {() => this.setState({ showCustomisedAnimatedDialog : false })}
263
+ text = " Nope"
264
+ disabled = {this.state.showLoading } / >
216
265
< / div >
217
-
218
266
< / AnimatedDialog >
219
267
220
- // Success dialog
268
+ // Render success animated dialog which will appear after the execution
269
+ // of the onClick function of the Button in the above animated dialog
221
270
222
271
< AnimatedDialog
223
272
hidden = {!this.state.showSuccessDialog }
224
273
onDismiss = {() => { this .setState ({ showSuccessDialog: false }); }}
225
274
dialogContentProps = {successDialogContentProps }
226
- modalProps = {customizedAnimatedModalProps }
275
+ modalProps = {animatedModalProps }
227
276
iconName = ' CompletedSolid' >
228
277
< div className = {styles.dialogContent }> <span >Thank you .< / span></ div >
229
278
< div className = {styles.resultDialogFooter }>
0 commit comments