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: packages/mgt-components/README.md
+7-36Lines changed: 7 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,71 +89,42 @@ The earlier example can be updated to use the disambiguation feature as follows:
89
89
90
90
> Note: the `import` of `mgt-components` must use a dynamic import to ensure that the disambiguation is applied before the components are imported.
91
91
92
-
To simplify this pattern when developing SharePoint Framework web parts we have provided helper utilities in the [`mgt-spfx-utils`](https://github.com/microsoftgraph/microsoft-graph-toolkit/tree/main/packages/mgt-spfx-utils) package. Example usages are provided below.
92
+
When developing SharePoint Framework web parts the pattern for using disambiguation is based on whether or not the MGT React wrapper library is being used. If you are using React then the helper utility in the [`mgt-spfx-utils`](https://github.com/microsoftgraph/microsoft-graph-toolkit/tree/main/packages/mgt-spfx-utils) package should be used. SharePoint Framework web part example usages are provided below.
93
93
94
94
### Usage in a SharePoint web part with no framework
95
95
96
-
The `importMgtComponentsLibrary` helper function wraps a dynamic import of the `@microsoft/mgt-components` library.
96
+
A dynamic import of the `@microsoft/mgt-components` library is used after configuring the disambiguation.
97
97
98
-
A more complete example is available in the [No Framework Web Part Sample](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/main/samples/sp-mgt/src/webparts/helloWorld/HelloWorldWebPart.ts).
98
+
This example is sourced from the [No Framework Web Part Sample](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/main/samples/sp-mgt/src/webparts/helloWorld/HelloWorldWebPart.ts).
99
99
100
100
```ts
101
101
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
102
102
import { Providers } from '@microsoft/mgt-element';
103
103
import { SharePointProvider } from '@microsoft/mgt-sharepoint-provider';
104
104
import { customElementHelper } from '@microsoft/mgt-element/dist/es6/components/customElementHelper';
105
-
import { importMgtComponentsLibrary } from '@microsoft/mgt-spfx-utils';
106
105
107
106
export default class MgtWebPart extends BaseClientSideWebPart<Record<string, unknown>> {
108
-
private _hasImportedMgtScripts = false;
109
-
private _errorMessage = '';
110
107
111
108
protected onInit(): Promise<void> {
109
+
customElementHelper.withDisambiguation('foo');
112
110
if (!Providers.globalProvider) {
113
111
Providers.globalProvider = new SharePointProvider(this.context);
The `lazyLoadComponent` helper function leverages `React.lazy` and `React.Suspense` to asynchronously load the components which have a direct dependency on `@microsoft/mgt-react` from the top level web part component.
127
+
The `lazyLoadComponent` helper function from [`mgt-spfx-utils`](https://github.com/microsoftgraph/microsoft-graph-toolkit/tree/main/packages/mgt-spfx-utils) leverages `React.lazy` and `React.Suspense` to asynchronously load the components which have a direct dependency on `@microsoft/mgt-react` from the top level web part component.
157
128
158
129
A complete example is available in the [React SharePoint Web Part Sample](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/main/samples/sp-webpart/src/webparts/mgtDemo/MgtDemoWebPart.ts).
Copy file name to clipboardExpand all lines: packages/mgt-spfx-utils/README.md
+5-46Lines changed: 5 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,19 +8,7 @@ Helper functions to simplify lazy loading of Microsoft Graph Toolkit components
8
8
9
9
## Installation
10
10
11
-
To lazy load Microsoft Graph Toolkit components from the library, add the `@microsoft/mgt-spfx-utils` package as a dependency to your SharePoint Framework project. If you use React, also add the `@microsoft/mgt-react` package:
12
-
13
-
```bash
14
-
npm install @microsoft/mgt-spfx-utils
15
-
```
16
-
17
-
or
18
-
19
-
```bash
20
-
yarn add @microsoft/mgt-spfx-utils
21
-
```
22
-
23
-
or when using React:
11
+
To lazy load Microsoft Graph Toolkit components in a React web part add both the `@microsoft/mgt-spfx-utils` and `@microsoft/mgt-react` packages as dependencies to your SharePoint Framework project:
@@ -38,11 +26,11 @@ Disambiguation is intended to provide developers with a mechanism to use a speci
38
26
39
27
By disambiguating tag names of Microsoft Graph Toolkit components, you can use your own version of MGT rather than using the centrally deployed `@microsoft/mgt-spfx` package. This allows you to avoid colliding with SharePoint Framework components built by other developers. When disambiguating tag names, MGT is included in the generated SPFx bundle, increasing its size. It is strongly recommended that you use a disambiguation value unique to your organization and solution to avoid collisions with other solutions, e.g. `contoso-hr-extensions`.
40
28
41
-
> **Important:** Since a given web component tag can only be registered once these approaches**must** be used along with the `customElementHelper.withDisambiguation('foo')` approach as this allows developers to create disambiguated tag names.
29
+
> **Important:** Since a given web component tag can only be registered once this approach**must** be used along with the `customElementHelper.withDisambiguation('foo')` as this allows developers to create disambiguated tag names.
42
30
43
31
### When using no framework web parts
44
32
45
-
When building SharePoint Framework web parts without a JavaScript framework the `@microsoft/mgt-components` library must be asynchronously loaded after configuring the disambiguation setting. The `importMgtComponentsLibrary`helper function wraps this functionality. Once the `@microsoft/mgt-components` library is loaded you can load components directly in your web part.
33
+
When building SharePoint Framework web parts without a JavaScript framework the `@microsoft/mgt-components` library must be asynchronously loaded after configuring the disambiguation setting. No helper library is necessary as dynamic imports are sufficient. After the browser has loaded the `@microsoft/mgt-components` library any tags which had already been rendered to the DOM without an existing custom element registration will automatically have the loaded custom behavior attached to them.
46
34
47
35
Below is a minimal example web part that demonstrates how to use MGT with disambiguation in SharePoint Framework Web parts. A more complete example is available in the [No Framework Web Part Sample](https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/main/samples/sp-mgt/src/webparts/helloWorld/HelloWorldWebPart.ts).
48
36
@@ -51,53 +39,24 @@ import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
0 commit comments