UNPKG

@pnp/spfx-property-controls

Version:

Reusable property pane controls for SharePoint Framework solutions

46 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyFieldSliderWithCallout = PropertyFieldSliderWithCallout; 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 PropertyFieldSliderWithCalloutHost_1 = tslib_1.__importDefault(require("./PropertyFieldSliderWithCalloutHost")); const Util_1 = require("../../common/util/Util"); class PropertyFieldSliderWithCalloutBuilder { constructor(_targetProperty, _properties) { this.type = sp_property_pane_1.PropertyPaneFieldType.Custom; // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type this._debounce = (0, Util_1.debounce)(); 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(PropertyFieldSliderWithCalloutHost_1.default, Object.assign(Object.assign({}, props), { onChange: this._onChanged.bind(this) })); ReactDOM.render(element, elem); if (changeCallback) { this._onChangeCallback = changeCallback; } } _dispose(elem) { ReactDOM.unmountComponentAtNode(elem); } _onChanged(value) { const props = this.properties; if (this._onChangeCallback) { if (props.debounce) { this._debounce(() => { console.log(`Debounced after ${props.debounce}`); this._onChangeCallback(this.targetProperty, value); }, props.debounce); } else { this._onChangeCallback(this.targetProperty, value); } } } } function PropertyFieldSliderWithCallout(targetProperty, properties) { return new PropertyFieldSliderWithCalloutBuilder(targetProperty, Object.assign(Object.assign({}, properties), { onRender: null, onDispose: null })); } //# sourceMappingURL=PropertyFieldSliderWithCallout.js.map