forked from pnp/sp-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinksWebPart.ts
146 lines (135 loc) · 4.88 KB
/
LinksWebPart.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration
} from '@microsoft/sp-webpart-base';
import * as strings from 'LinksWebPartStrings';
import Links from './components/Links';
import { ILinksProps } from './components/ILinksProps';
import { ILink, LinkTarget } from './components/ILink';
export interface ILinksWebPartProps {
collectionData: ILink[];
groupData: any[];
title: string;
}
export default class LinksWebPart extends BaseClientSideWebPart<ILinksWebPartProps> {
private propertyFieldCollectionData;
private customCollectionFieldType;
public render(): void {
const element: React.ReactElement<ILinksProps> = React.createElement(
Links,
{
collectionData: this.properties.collectionData,
title: this.properties.title,
displayMode: this.displayMode,
fUpdateProperty: (value: string) => {
this.properties.title = value;
},
fPropertyPaneOpen: this.context.propertyPane.open
}
);
ReactDom.render(element, this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
//executes only before property pane is loaded.
protected async loadPropertyPaneResources(): Promise<void> {
// import additional controls/components
const { PropertyFieldCollectionData, CustomCollectionFieldType } = await import (
/* webpackChunkName: 'pnp-propcontrols-colldata' */
'@pnp/spfx-property-controls/lib/PropertyFieldCollectionData'
);
this.propertyFieldCollectionData = PropertyFieldCollectionData;
this.customCollectionFieldType = CustomCollectionFieldType;
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
let groups = [];
if (this.properties.groupData && this.properties.groupData.length > 0) {
groups = this.properties.groupData.map((group: any) => ({ key: group.title, text: group.title }));
}
return {
pages: [
{
groups: [
{
groupFields: [
this.propertyFieldCollectionData("groupData", {
key: "groupData",
label: strings.groupDataLabel,
panelHeader: strings.groupPanelHeader,
manageBtnLabel: strings.manageGroupBtn,
value: this.properties.groupData,
fields: [
{
id: "title",
title: strings.titleField,
type: this.customCollectionFieldType.string,
required: true
}
]
}),
this.propertyFieldCollectionData("collectionData", {
key: "collectionData",
label: strings.linkDataLabel,
panelHeader: strings.linkPanelHeader,
panelDescription: `${strings.iconInformation} https://developer.microsoft.com/en-us/fabric#/styles/icons`,
manageBtnLabel: strings.manageLinksBtn,
value: this.properties.collectionData,
fields: [
{
id: "title",
title: strings.titleField,
type: this.customCollectionFieldType.string,
required: true
},
{
id: "url",
title: strings.urlField,
type: this.customCollectionFieldType.string,
required: true
},
{
id: "icon",
title: strings.iconField,
type: this.customCollectionFieldType.fabricIcon
},
{
id: "group",
title: strings.groupField,
type: this.customCollectionFieldType.dropdown,
options: [
{
key: null,
text: ""
},
...groups
]
},
{
id: "target",
title: strings.targetField,
type: this.customCollectionFieldType.dropdown,
options: [
{
key: LinkTarget.parent,
text: strings.targetCurrent
},
{
key: LinkTarget.blank,
text: strings.targetNew
}
]
}
]
})
]
}
]
}
]
};
}
}