forked from pnp/sp-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TilesWebPart.ts
130 lines (121 loc) · 4.47 KB
/
TilesWebPart.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
import * as React from 'react';
import * as ReactDom from 'react-dom';
import * as strings from 'TilesWebPartStrings';
import { Version } from '@microsoft/sp-core-library';
import { BaseClientSideWebPart, IPropertyPaneConfiguration } from '@microsoft/sp-webpart-base';
import { Tiles, ITilesProps, ITileInfo, LinkTarget } from './components';
export interface ITilesWebPartProps {
collectionData: ITileInfo[];
tileHeight: number;
title: string;
}
export default class TilesWebPart extends BaseClientSideWebPart<ITilesWebPartProps> {
private propertyFieldNumber;
private propertyFieldCollectionData;
private customCollectionFieldType;
public render(): void {
const element: React.ReactElement<ITilesProps> = React.createElement(
Tiles,
{
title: this.properties.title,
tileHeight: this.properties.tileHeight,
collectionData: this.properties.collectionData,
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 { PropertyFieldNumber } = await import (
/* webpackChunkName: 'pnp-propcontrols-number' */
'@pnp/spfx-property-controls/lib/propertyFields/number'
);
const { PropertyFieldCollectionData, CustomCollectionFieldType } = await import (
/* webpackChunkName: 'pnp-propcontrols-colldata' */
'@pnp/spfx-property-controls/lib/PropertyFieldCollectionData'
);
this.propertyFieldNumber = PropertyFieldNumber;
this.propertyFieldCollectionData = PropertyFieldCollectionData;
this.customCollectionFieldType = CustomCollectionFieldType;
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupFields: [
this.propertyFieldCollectionData("collectionData", {
key: "collectionData",
label: strings.tilesDataLabel,
panelHeader: strings.tilesPanelHeader,
panelDescription: `${strings.iconInformation} https://developer.microsoft.com/en-us/fabric#/styles/icons`,
manageBtnLabel: strings.tilesManageBtn,
value: this.properties.collectionData,
fields: [
{
id: "title",
title: strings.titleField,
type: this.customCollectionFieldType.string,
required: true
},
{
id: "description",
title: strings.descriptionField,
type: this.customCollectionFieldType.string,
required: false
},
{
id: "url",
title: strings.urlField,
type: this.customCollectionFieldType.string,
required: true
},
{
id: "icon",
title: strings.iconField,
type: this.customCollectionFieldType.fabricIcon,
required: true
},
{
id: "target",
title: strings.targetField,
type: this.customCollectionFieldType.dropdown,
options: [
{
key: LinkTarget.parent,
text: strings.targetCurrent
},
{
key: LinkTarget.blank,
text: strings.targetNew
}
]
}
]
}),
this.propertyFieldNumber('tileHeight', {
key: "tileHeight",
label: strings.TileHeight,
value: this.properties.tileHeight
})
]
}
]
}
]
};
}
}