Skip to content

Commit a95125e

Browse files
authored
Merge pull request #833 from anoopt/animated-dialog
Minor updates to documentation
2 parents 4aa5f7d + ef7a88b commit a95125e

File tree

1 file changed

+78
-29
lines changed

1 file changed

+78
-29
lines changed

docs/documentation/docs/controls/AnimatedDialog.md

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ import { AnimatedDialog } from "@pnp/spfx-controls-react/lib/AnimatedDialog";
3030
The code below adds a dialog with an entrance animation of `bounceIn` and exit animation of `zoomOut`. (These are the default animations)
3131

3232
```TypeScript
33+
// Initial state
34+
this.state = {
35+
showAnimatedDialog: false
36+
}
37+
...
38+
...
39+
// Properties of the dialog
3340
const animatedDialogContentProps: IDialogContentProps = {
3441
type: DialogType.normal,
3542
title: 'Animated Dialog',
@@ -41,6 +48,9 @@ const animatedModalProps: IModalProps = {
4148
};
4249
...
4350
...
51+
// Add a control (like a button) that changes the state showAnimatedDialog to true
52+
53+
//Render the animated dialog
4454
<AnimatedDialog
4555
hidden={!this.state.showAnimatedDialog}
4656
onDismiss={() => { this.setState({ showAnimatedDialog: false }); }}
@@ -62,6 +72,13 @@ const animatedModalProps: IModalProps = {
6272
The code below adds adds a dialog with an entrance animation of `fadeInDown` and exit animation of `fadeInDown`.
6373

6474
```TypeScript
75+
// Initial state
76+
this.state = {
77+
showAnimatedDialog: false
78+
}
79+
...
80+
...
81+
// Properties of the dialog
6582
const animatedDialogContentProps: IDialogContentProps = {
6683
type: DialogType.normal,
6784
title: 'Animated Dialog',
@@ -73,6 +90,9 @@ const animatedModalProps: IModalProps = {
7390
};
7491
...
7592
...
93+
// Add a control (like a button) that changes the state showAnimatedDialog to true
94+
95+
//Render the animated dialog
7696
<AnimatedDialog
7797
hidden={!this.state.showAnimatedDialog}
7898
onDismiss={() => { this.setState({ showAnimatedDialog: false }); }}
@@ -103,10 +123,23 @@ The code below does the following:
103123
- onError: The function that gets executed when the `onOkClick` function fails.
104124

105125
```TypeScript
126+
// Initial state
127+
this.state = {
128+
showCustomisedAnimatedDialog: false,
129+
showSuccessDialog: false,
130+
showErrorDialog: false
131+
}
132+
...
133+
...
106134
const animatedDialogContentProps: IDialogContentProps = {
107135
type: DialogType.normal,
108136
title: 'Animated Dialog with icon'
109-
};
137+
};
138+
139+
const successDialogContentProps: IDialogContentProps = {
140+
type: DialogType.normal,
141+
title: 'Good answer!'
142+
};
110143

111144
const animatedModalProps: IModalProps = {
112145
isDarkOverlay: true,
@@ -119,6 +152,9 @@ const timeout = (ms: number): Promise<void> => {
119152
};
120153
...
121154
...
155+
// Add a control (like a button) that changes the state showAnimatedDialog to true
156+
157+
//Render the animated dialog
122158
<AnimatedDialog
123159
hidden={!this.state.showCustomisedAnimatedDialog}
124160
onDismiss={() => { this.setState({ showCustomisedAnimatedDialog: false }); }}
@@ -142,13 +178,14 @@ const timeout = (ms: number): Promise<void> => {
142178
</div>
143179
</AnimatedDialog>
144180

145-
// Success dialog
181+
// Render success animated dialog which will appear after the execution
182+
// of onSuccess function in the above animated dialog
146183

147184
<AnimatedDialog
148185
hidden={!this.state.showSuccessDialog}
149186
onDismiss={() => { this.setState({ showSuccessDialog: false }); }}
150187
dialogContentProps={successDialogContentProps}
151-
modalProps={customizedAnimatedModalProps}
188+
modalProps={animatedModalProps}
152189
iconName='CompletedSolid'
153190
>
154191
<div className={styles.dialogContent}><span>Thank you.</span></div>
@@ -168,22 +205,34 @@ const timeout = (ms: number): Promise<void> => {
168205
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
169206
170207
```TypeScript
208+
// Initial state
209+
this.state = {
210+
showCustomisedAnimatedDialog: false,
211+
showSuccessDialog: false,
212+
showErrorDialog: false,
213+
showLoading: false
214+
}
215+
...
216+
...
171217
const animatedDialogContentProps: IDialogContentProps = {
172218
type: DialogType.normal,
173219
title: 'Custom content and footer'
174-
};
220+
};
221+
222+
const successDialogContentProps: IDialogContentProps = {
223+
type: DialogType.normal,
224+
title: 'Good answer!'
225+
};
175226

176227
const animatedModalProps: IModalProps = {
177228
isDarkOverlay: true,
178229
containerClassName: `${styles.dialogContainer}`
179230
};
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-
};
185231
...
186232
...
233+
// Add a control (like a button) that changes the state showAnimatedDialog to true
234+
235+
//Render the animated dialog
187236
<AnimatedDialog
188237
hidden={!this.state.showCustomisedAnimatedDialog}
189238
onDismiss={() => { this.setState({ showCustomisedAnimatedDialog: false }); }}
@@ -192,38 +241,38 @@ const timeout = (ms: number): Promise<void> => {
192241
iconName='UnknownSolid'>
193242

194243
<div className={styles.dialogContent}>
195-
<span>Do you like the animated dialog?</span>
244+
<span>Do you like the animated dialog?</span>
196245
</div>
197246

198247
<div className={styles.dialogFooter}>
199-
<PrimaryButton
200-
onClick={() => {
248+
<PrimaryButton
249+
onClick={() => {
250+
this.setState({ showLoading: true });
251+
setTimeout(() => {
201252
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} />
216265
</div>
217-
218266
</AnimatedDialog>
219267

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
221270

222271
<AnimatedDialog
223272
hidden={!this.state.showSuccessDialog}
224273
onDismiss={() => { this.setState({ showSuccessDialog: false }); }}
225274
dialogContentProps={successDialogContentProps}
226-
modalProps={customizedAnimatedModalProps}
275+
modalProps={animatedModalProps}
227276
iconName='CompletedSolid'>
228277
<div className={styles.dialogContent}><span>Thank you.</span></div>
229278
<div className={styles.resultDialogFooter}>

0 commit comments

Comments
 (0)