Skip to content

Instantly share code, notes, and snippets.

@gautamdsheth
Created April 6, 2020 14:11
Show Gist options
  • Select an option

  • Save gautamdsheth/49d162d57bfa67bcc4c5ee5e678ed603 to your computer and use it in GitHub Desktop.

Select an option

Save gautamdsheth/49d162d57bfa67bcc4c5ee5e678ed603 to your computer and use it in GitHub Desktop.
PnP Controls in property pane
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'TestPnPControlsV110WebPartStrings';
import TestPnPControlsV110 from './components/TestPnPControlsV110';
import { ITestPnPControlsV110Props } from './components/ITestPnPControlsV110Props';
import { PropertyFieldCollectionData, CustomCollectionFieldType } from '@pnp/spfx-property-controls/lib/PropertyFieldCollectionData';
import { TaxonomyPicker, IPickerTerms } from "@pnp/spfx-controls-react/lib/TaxonomyPicker";
import { ListPicker, IListPickerProps } from "@pnp/spfx-controls-react/lib/ListPicker";
import { DateTimePicker, DateConvention, TimeConvention } from '@pnp/spfx-controls-react/lib/DateTimePicker';
import { FilePicker, IFilePickerResult , IFilePickerProps } from '@pnp/spfx-controls-react/lib/FilePicker';
import { RichText, IRichTextProps } from "@pnp/spfx-controls-react/lib/RichText";
export interface ITestPnPControlsV110WebPartProps {
description: string;
collectionData: any[];
}
export default class TestPnPControlsV110WebPart extends BaseClientSideWebPart<ITestPnPControlsV110WebPartProps> {
public render(): void {
const element: React.ReactElement<ITestPnPControlsV110Props> = React.createElement(
TestPnPControlsV110,
{
description: this.properties.description,
context: this.context,
collectionData: this.properties.collectionData
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: ""
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyFieldCollectionData("collectionData", {
key: "collectionData",
label: "Collection data",
panelHeader: "Collection data panel header",
manageBtnLabel: "Manage collection data",
value: this.properties.collectionData,
fields: [
{
id: "Title",
title: "Title",
type: CustomCollectionFieldType.string,
},
{
id: "filePicker",
title: "Select File",
type: CustomCollectionFieldType.custom,
onCustomRender: (field, value, onUpdate, item, itemId, onError) => {
return (
React.createElement(FilePicker, {
key: itemId,
context: this.context,
buttonLabel:"Select File",
onChanged: (selectedFile: IFilePickerResult) => {
onUpdate(field.id, selectedFile);
return event;
},
onSave: (filePickerResult: IFilePickerResult) => {
// write code to save file to SharePoint doc library
onUpdate(field.id, filePickerResult);
return event;
}
}))
}
},
{
id: "listPicker",
title: "List",
type: CustomCollectionFieldType.custom,
onCustomRender: (field, value, onUpdate, item, itemId, onError) => {
return (
React.createElement(ListPicker, {
key: itemId,
context: this.context,
includeHidden: false,
selectedList: value,
placeholder: "Select your list",
onSelectionChanged: (selectedList: string) => {
onUpdate(field.id, selectedList);
return event;
}
}))
}
},
{
id: "countryTaxValues",
title: "Countries",
type: CustomCollectionFieldType.custom,
onCustomRender: (field, value, onUpdate, item, itemId, onError) => {
return (
React.createElement(TaxonomyPicker, {
key: itemId,
initialValues: value,
termsetNameOrID: "Countries",
panelTitle: "Select Term",
label: "",
context: this.context,
isTermSetSelectable: false,
onChange: (event: IPickerTerms) => {
onUpdate(field.id, event);
return event;
}
}))
}
},
{
id: "selectedDate",
title: "Select Date",
type: CustomCollectionFieldType.custom,
onCustomRender: (field, value, onUpdate, item, itemId, onError) => {
return (
React.createElement(DateTimePicker, {
key: itemId,
label:"",
showLabels:false,
placeholder: "Select date",
dateConvention: DateConvention.Date,
value:value,
onChange: (event) => {
onUpdate(field.id,event);
return event;
}
}))
}
},
],
disabled: false
})
]
}
]
}
]
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment