UNPKG

@pnp/spfx-property-controls

Version:

Reusable property pane controls for SharePoint Framework solutions

87 lines 3.64 kB
import * as React from 'react'; import * as ReactDom from 'react-dom'; import { PropertyPaneFieldType, } from '@microsoft/sp-property-pane'; import PropertyFieldPeoplePickerHost from './PropertyFieldPeoplePickerHost'; /** * Represents a PropertyFieldPeoplePicker object */ class PropertyFieldPeoplePickerBuilder { /** * Constructor method */ constructor(_targetProperty, _properties) { // Properties defined by IPropertyPaneField this.type = PropertyPaneFieldType.Custom; this.disabled = false; this.allowDuplicate = true; this.multiSelect = true; this.principalType = []; this.deferredValidationTime = 200; this.render = this.render.bind(this); this.label = _properties.label; this.targetProperty = _properties.targetProperty; this.properties = _properties; this.properties.onDispose = this.dispose; this.properties.onRender = this.render; this.onPropertyChange = _properties.onPropertyChange; this.context = _properties.context; this.initialData = _properties.initialData; this.allowDuplicate = _properties.allowDuplicate; this.principalType = _properties.principalType; this.targetSiteUrl = _properties.targetSiteUrl; this.customProperties = _properties.properties; this.key = _properties.key; this.onGetErrorMessage = _properties.onGetErrorMessage; if (typeof _properties.disabled !== 'undefined') { this.disabled = _properties.disabled; } if (_properties.deferredValidationTime) { this.deferredValidationTime = _properties.deferredValidationTime; } if (typeof _properties.multiSelect !== "undefined") { this.multiSelect = _properties.multiSelect; } } /** * Renders the PeoplePicker field content */ render(elem, ctx, changeCallback) { // Construct the JSX properties const element = React.createElement(PropertyFieldPeoplePickerHost, { label: this.label, disabled: this.disabled, targetProperty: this.targetProperty, initialData: this.initialData, allowDuplicate: this.allowDuplicate, multiSelect: this.multiSelect, principalType: this.principalType, onDispose: this.dispose, onRender: this.render, onChange: changeCallback, onPropertyChange: this.onPropertyChange, context: this.context, properties: this.customProperties, targetSiteUrl: this.targetSiteUrl, key: this.key, onGetErrorMessage: this.onGetErrorMessage, deferredValidationTime: this.deferredValidationTime }); // Calls the REACT content generator ReactDom.render(element, elem); } /** * Disposes the current object */ dispose(elem) { } } /** * Helper method to create a People Picker on the PropertyPane. * @param targetProperty - Target property the people picker is associated to. * @param properties - Strongly typed people Picker properties. */ export function PropertyFieldPeoplePicker(targetProperty, properties) { // Calls the PropertyFieldPeoplePicker builder object // This object will simulate a PropertyFieldCustom to manage his rendering process return new PropertyFieldPeoplePickerBuilder(targetProperty, Object.assign(Object.assign({}, properties), { targetProperty: targetProperty, onDispose: null, onRender: null })); } //# sourceMappingURL=PropertyFieldPeoplePicker.js.map