UNPKG

@pnp/spfx-property-controls

Version:

Reusable property pane controls for SharePoint Framework solutions

52 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyFieldCollectionData = PropertyFieldCollectionData; const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const ReactDOM = tslib_1.__importStar(require("react-dom")); const sp_property_pane_1 = require("@microsoft/sp-property-pane"); const PropertyFieldCollectionDataHost_1 = require("./PropertyFieldCollectionDataHost"); /** * Property Field Collection Data Builder Class */ class PropertyFieldCollectionDataBuilder { constructor(_targetProperty, _properties) { this.type = sp_property_pane_1.PropertyPaneFieldType.Custom; this.targetProperty = _targetProperty; this.properties = _properties; this.properties.onRender = this.render.bind(this); this.properties.onDispose = this.dispose.bind(this); } render(elem, context, changeCallback) { const props = this.properties; const element = React.createElement(PropertyFieldCollectionDataHost_1.PropertyFieldCollectionDataHost, Object.assign(Object.assign({}, props), { onChanged: this.onChanged.bind(this) })); ReactDOM.render(element, elem); if (changeCallback) { this._onChangeCallback = changeCallback; } } /** * Dispose the property field */ dispose(elem) { ReactDOM.unmountComponentAtNode(elem); } /** * On field change event handler * @param value */ onChanged(value) { if (this._onChangeCallback) { this._onChangeCallback(this.targetProperty, value); } } } /** * Property field * @param targetProperty * @param properties */ function PropertyFieldCollectionData(targetProperty, properties) { return new PropertyFieldCollectionDataBuilder(targetProperty, Object.assign(Object.assign({}, properties), { onRender: null, onDispose: null })); } //# sourceMappingURL=PropertyFieldCollectionData.js.map