forked from pnp/sp-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TilesWebPart.ts
111 lines (105 loc) · 3.89 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
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, PropertyPaneLabel, PropertyPaneLink, PropertyPaneHorizontalRule } from '@microsoft/sp-webpart-base';
import { PropertyFieldNumber } from '@pnp/spfx-property-controls/lib/propertyFields/number';
import { PropertyFieldCollectionData, CustomCollectionFieldType } from '@pnp/spfx-property-controls/lib/PropertyFieldCollectionData';
import { Tiles, ITilesProps, ITileInfo, LinkTarget } from './components';
export interface ITilesWebPartProps {
collectionData: ITileInfo[];
tileHeight: number;
title: string;
}
export default class TilesWebPart extends BaseClientSideWebPart<ITilesWebPartProps> {
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');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupFields: [
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: CustomCollectionFieldType.string,
required: true
},
{
id: "description",
title: strings.descriptionField,
type: CustomCollectionFieldType.string,
required: false
},
{
id: "url",
title: strings.urlField,
type: CustomCollectionFieldType.string,
required: true
},
{
id: "icon",
title: strings.iconField,
type: CustomCollectionFieldType.fabricIcon,
required: true
},
{
id: "target",
title: strings.targetField,
type: CustomCollectionFieldType.dropdown,
options: [
{
key: LinkTarget.parent,
text: strings.targetCurrent
},
{
key: LinkTarget.blank,
text: strings.targetNew
}
]
}
]
}),
PropertyFieldNumber('tileHeight', {
key: "tileHeight",
label: strings.TileHeight,
value: this.properties.tileHeight
})
]
}
]
}
]
};
}
}