You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/spfx/extensions/guidance/using-custom-dialogs-with-spfx.md
+57-51Lines changed: 57 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,24 @@
1
1
# Using Custom Dialogs with SharePoint Framework Extensions
2
2
3
-
Custom dialogs are available from `@microsoft/sp-dialog`package and can be used within the context of SharePoint Framework Extensions or client-side web parts.
3
+
Custom dialogs are available from the **@microsoft/sp-dialog**package and can be used within the context of SharePoint Framework Extensions or client-side web parts.
4
4
5
-
This tutorial demonstrates creation of a custom dialog and using that in the context of ListView Command Set extension.
5
+
This tutorial demonstrates the creation of a custom dialog and using it within the context of a ListView Command Set extension.
6
6
7
-
> Notice that the SharePoint Framework dialog is currently in preview status and we are looking to collect feedback before it's officially released. Please provide us feedback by using the [sp-dev-docs repository Issue list](https://github.com/SharePoint/sp-dev-docs/issues).
7
+
> The SharePoint Framework dialog is currently in preview status and we are looking to collect feedback before it's officially released. Please provide feedback by using the [sp-dev-docs repository Issue list](https://github.com/SharePoint/sp-dev-docs/issues).
8
8
9
-
> Notice that debugging Custom ListView Sets in the SharePoint Online is currently only available from modern list experience in classic team sites hosted on dev tenant.
9
+
> Please note that debugging Custom ListView Command Sets in SharePoint Online is currently only available from the modern list experience within classic team sites hosted in a **developer tenant**.
10
10
11
-
> End result of this tutorial is also available as source code at https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/react-command-dialog.
11
+
> The end result of this tutorial is available as source code at https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/react-command-dialog.
12
12
13
13
## Setup your Environment
14
14
15
-
Before you can complete this guide you will need to ensure you have [setup your environment](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment) for development
16
-
using SharePoint Framework and that you are using latest SharePoint Framework Yeoman templates.
15
+
Before you can complete this guide, you will need to ensure you have [setup your environment](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment) for development
16
+
using the SharePoint Framework (SPFx) and that you are using the latest SharePoint Framework Yeoman templates.
17
17
18
-
> You can update your SharePoint Framework Yeoman templates by running following command `npm install -g @microsoft/generator-sharepoint`.
18
+
> You can update your SharePoint Framework Yeoman templates by running the following command:
19
+
> ```sh
20
+
> npm install -g @microsoft/generator-sharepoint`
21
+
>```
19
22
20
23
## Create a New Project
21
24
@@ -25,13 +28,13 @@ Start by creating a new folder for the project using your console of choice:
25
28
md dialog-cmd
26
29
```
27
30
28
-
And enter that folder
31
+
Then enter that folder:
29
32
30
33
```sh
31
34
cd dialog-cmd
32
35
```
33
36
34
-
The run the Yeoman generator for SharePoint Framework
37
+
Then run the Yeoman generator forthe SharePoint Framework:
35
38
36
39
```sh
37
40
yo @microsoft/sharepoint
@@ -45,30 +48,30 @@ When prompted:
45
48
46
49
The next set of prompts will ask for specific information about your extension:
47
50
48
-
*Accept the default value of **DialogDemo** as your extension name and press **Enter**.
51
+
*Use the value of **DialogDemo** as your extension name and press **Enter**.
49
52
* Accept the default value of **DialogDemo description** as your extension description and press **Enter**.
50
53
51
54

52
55
53
-
At this point, Yeoman will install the required dependencies and scaffold the solution files along with the *HelloWorld* extension. This might take a few minutes.
56
+
At this point, Yeoman will install the required dependencies and scaffold the solution files along with the *DialogDemo* extension. This might take a few minutes.
54
57
55
58
When the scaffold is complete, you should see the following message indicating a successful scaffold:
For information about troubleshooting any errors, see [Known issues](../basics/known-issues).
62
+
>For information about troubleshooting any errors, see [Known issues](../basics/known-issues).
60
63
61
-
Once the scaffolding completes, open your project folder in your code editor. This article uses Visual Studio Code in the steps and screenshots but you can use any editor you prefer.
64
+
Once the scaffolding completes, open your project folder in your code editor. This article uses Visual Studio Code in the steps and screenshots, but you can use any editor you prefer. To open the folder in Visual Studio Code use the following commandin the console:
62
65
63
-
```
66
+
```sh
64
67
code .
65
68
```
66
69
67
70

68
71
69
-
## Modify extension manifest based on requirements
72
+
## Modify the Extension Manifest
70
73
71
-
In the extension manifest, configure extension to have only one button. In the code editor, open the **./src/extensions/dialogDemo/DialogDemoCommandSet.manifest.json** file. Replace the commands section with the following JSON:
74
+
In the extension manifest, configure the extension to have only one button. In the code editor, open the **./src/extensions/dialogDemo/DialogDemoCommandSet.manifest.json** file. Replace the commands section with the following JSON:
72
75
73
76
```json
74
77
{
@@ -80,26 +83,26 @@ In the extension manifest, configure extension to have only one button. In the c
80
83
}
81
84
}
82
85
}
83
-
84
86
```
85
87
86
-
## Adding sp-dialog package to solution
87
-
Return to the console and execute the following command to include the dialog API in our solution.
88
+
## Adding the sp-dialog Package to the Solution
88
89
89
-
```
90
+
Return to the console and execute the following command to include the dialog API in your solution:
91
+
92
+
```sh
90
93
npm install @microsoft/sp-dialog --save
91
94
```
92
95
93
-
Since we are using the `--save` option, this dependency will be added to *package.json* file and would be automatically installed when `npm install` command is executed.
96
+
Since we are using the `--save` option, this dependency will be added to the **package.json** file. This will ensure that it will be automatically installed when the `npm install`command is executed (this is important when restoring or cloning your project elsewhere).
94
97
95
98
Return to Visual Studio Code (or your preferred editor).
96
99
97
-
## Creating your custom dialog
98
-
Create a new file called **ColorPickerDialog.tsx**to**./src/extensions/dialogDemo/** folder.
100
+
## Creating a Custom Dialog
101
+
Create a new file called **ColorPickerDialog.tsx**in the**./src/extensions/dialogDemo/** folder.
99
102
100
-
Add following import statements on the start of the newly created file. We are creating our custom dialog using Office UI Fabric React components, so the implementation will be in React.
103
+
Add the following import statements at the top of the newly created file. We are creating our custom dialog using the [Office UI Fabric React components](https://dev.office.com/fabric#/components), so the implementation will be in React.
101
104
102
-
> Notice that currently DialogContent component is coming from `@microsoft/sp-dialog`, but will be included in Office UI Fabric React components soon, like mentioned in the code comments.
105
+
>Currently the `DialogContent` component is coming from `@microsoft/sp-dialog`, but will be included as part of the Office UI Fabric React components soon, as mentioned in the code comments below.
103
106
104
107
```ts
105
108
import * as React from 'react';
@@ -118,7 +121,7 @@ import {
118
121
import { DialogContent } from '@microsoft/sp-dialog';
119
122
```
120
123
121
-
Add following interface definition just below the import statements. This wil be used to bypass needed information and functions between the ListView Command Set extension and custom dialog.
124
+
Add the following interface definition just below the import statements. This wil be used to pass information and functions between your ListView Command Set extension and your custom dialog.
Add following class just below the interface definition. This React class is responsible for rendering the UI experiences inside of the custom dialog. Notice that we use the Office UI Fabric React components for actual rendering and just bypass the needed properties.
135
+
Add the following class just below the interface definition. This React class is responsible for rendering the UI experiences inside of the custom dialog. Notice that we use the Office UI Fabric React components for actual rendering and just pass the needed properties.
133
136
134
137
```ts
135
138
class ColorPickerDialogContent extends React.Component<IColorPickerDialogContentProps, {}> {
@@ -162,7 +165,7 @@ class ColorPickerDialogContent extends React.Component<IColorPickerDialogContent
162
165
}
163
166
}
164
167
```
165
-
Add following class definition for our custom dialog under the just added class code. This one is the actual custom dialog, which will be called from the button click and which is inherited from the **BaseDialog**.
168
+
Add the following class definition for our custom dialog under the just added `ColorPickerDialogContent` class. This is the actual custom dialog which will be called from the ListView Command Set button click and is inherited from the `BaseDialog`.
166
169
167
170
```ts
168
171
export default class ColorPickerDialog extends BaseDialog {
To associate the custom dialog button to custom ListView Command Set, the code to initiate the dialog has to be added for the button click operation.
198
+
## Associating the Custom Dialog with the ListView Command Set Button Click
199
+
To associate the custom dialog with your custom ListView Command Set, the code to initiate the dialog has to be added within the button click operation.
197
200
198
-
In the code editor, open the **DialogDemoCommandSet.ts** file from **./src/extensions/dialogDemo/** folder.
201
+
In the code editor, open the **DialogDemoCommandSet.ts** file from the**./src/extensions/dialogDemo/** folder.
199
202
200
-
Add following import statements under the existing **strings** import. These are for using the just created custom dialog in the context of ListView Command Set.
203
+
Add the following import statements under the existing **strings** import. These are forusing the just created custom dialogin the context of your ListView Command Set.
201
204
202
205
```ts
203
206
import { Dialog } from '@microsoft/sp-dialog';
204
207
import ColorPickerDialog from './ColorPickerDialog';
205
208
```
206
209
207
-
Add following **_colorCode** variable definition above **onInit** function in the **DialogDemoCommandSet** class. This is used to store teh color picker dialog result.
210
+
Add the following `_colorCode` variable definition above the `onInit`functionin the `DialogDemoCommandSet` class. This is used to store the color picker dialog result.
208
211
209
212
```ts
210
213
private _colorCode: string;
211
214
```
212
215
213
-
Update the **onExecute** function as follows. In this code we are doing following steps
216
+
Update the `onExecute`functionas follows. In this code we are doing the following:
214
217
215
-
* Initiate custom dialog
216
-
*Bypass message for the dialog, which will be used as title
217
-
*Bypass color code for the dialog with default value, if not yet set
218
-
* Show the custom dialog
219
-
* Receive and store return value from the dialog
220
-
* Show received value in out-of-the-box dialog using `Dialog.alert()` function
218
+
* Initiate our custom dialog
219
+
*Pass a message for the dialog, which will be used as the title
220
+
*Pass a color code for the dialog with a default value, if not yet set
221
+
* Show our custom dialog
222
+
* Receive and store the return value from the dialog
223
+
* Show the received value inan out-of-the-box dialog using the`Dialog.alert()` function
221
224
222
225
```ts
223
226
@override
@@ -239,24 +242,27 @@ Update the **onExecute** function as follows. In this code we are doing followin
239
242
}
240
243
```
241
244
242
-
## Testing custom dialog in your tenant
243
-
Move to **DialogDemoCommandSet.manifest.json** file in **./src/extensions/dialogDemo/** folder and copy **id** value, which will be used in the debug query parameter.
245
+
## Testing the Custom Dialog in your Tenant
244
246
245
-
Move to console side and execute following command. We use `--nobrowser` option, since local workbench cannot be currently used for debugging, so there's no reason to start that.
247
+
Open the **DialogDemoCommandSet.manifest.json** file in**./src/extensions/dialogDemo/** folder and copy the **id** value, which will be used in the debug query parameter.
248
+
249
+
Return to the console and execute the following command:
246
250
247
251
```sh
248
252
gulp serve --nobrowser
249
253
```
250
254
251
-
This will start bundling and will serve the resulting manifest from `localhost` address.
255
+
Notice that we used the `--nobrowser` option, since there's no value in launching the local workbench since you currently cannot debug extensions locally.
256
+
257
+
This will start the bundling of your solution and will serve the resulting manifest from the `localhost` address.
252
258
253
259

254
260
255
-
To test your extension, navigate to a site in your SharePoint Online tenant.
261
+
To test your extension, navigate to a site in your SharePoint Online developer tenant.
256
262
257
-
Move to an existing custom list in the site with some items or create a new list and add few items to it for testing purposes.
263
+
Navigate to an existing custom list within the site with some items or create a new list and add a few items to it for testing purposes.
258
264
259
-
Append the following query string parameters to the URL. Notice that you will need to update the **id** to match your own extension identifier available from the **DialogDemoCommandSet.manifest.json** file:
265
+
Append the following query string parameters to the URL. Notice that you will need to update the **id** to match your own extension identifier as listed in the **DialogDemoCommandSet.manifest.json** file:
Choose a color in the *Color Picker* and click **OK** to test how the code is returning selected value back to caller, which is then shown using out-of-the-box alert dialog.
283
+
Choose a color in the *Color Picker* and click **OK** to test how the code is returning the selected value back to the caller. The selection is then shown using the out-of-the-box alert dialog.
0 commit comments