Skip to content

Instantly share code, notes, and snippets.

@beckettkev
Last active October 9, 2018 09:19
Show Gist options
  • Save beckettkev/e15bc661783a447a26afd31a4bbe750b to your computer and use it in GitHub Desktop.
Save beckettkev/e15bc661783a447a26afd31a4bbe750b to your computer and use it in GitHub Desktop.
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
WebPartContext
} from '@microsoft/sp-webpart-base';
import * as strings from 'MyWebPartStrings';
import MyComponent from './components/MyComponent';
import { DisplayMode } from '@microsoft/sp-core-library';
export interface IMyWebPartProps {
categories: {
key: string;
name: string;
icon: string;
};
}
export default class MyWebPart extends BaseClientSideWebPart<IMyWebPartProps> {
private _propertyFieldCollectionData:any = null;
private _customCollectionFieldType:any = null;
public render(): void {
const { categories } = this.properties;
const element: React.ReactElement<IMyWebPartProps> = React.createElement(
MyComponent,
{
categories
}
);
ReactDom.render(element, this.domElement);
}
protected async onInit<IMyWebPartProps>():Promise<void> {
if (this.displayMode === DisplayMode.Edit) {
const { PropertyFieldCollectionData, CustomCollectionFieldType } = await import (
/* webpackChunkName: 'PropertyFieldCollectionData' */
'@pnp/spfx-property-controls/lib/PropertyFieldCollectionData'
);
this._propertyFieldCollectionData = PropertyFieldCollectionData;
this._customCollectionFieldType = CustomCollectionFieldType;
}
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
const { categories } = this.properties;
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.CategoryGroupName,
groupFields: [
this._propertyFieldCollectionData("categories", {
key: "categories",
label: "Categories",
panelHeader: "Manage categories",
manageBtnLabel: "Manage categories",
value: categories,
fields: [
{
id: "key",
title: "Key",
type: this._customCollectionFieldType.string,
required: true
},
{
id: "name",
title: "Title",
type: this._customCollectionFieldType.string,
required: true
},
{
id: "icon",
title: "Icon",
type: this._customCollectionFieldType.fabricIcon,
required: true
}
],
disabled: false
})
],
isCollapsed: true
}
],
displayGroupsAsAccordion: true,
}
]
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment