gd-sprest-bs
Version:
SharePoint JavaScript, TypeScript and Web Components designed using the Bootstrap framework.
73 lines (72 loc) • 2.21 kB
JavaScript
import { Components } from "../components/core";
/**
* Base Property Pane
*/
export class BasePropertyPane {
get config() { return this._config; }
// Constructor
constructor(targetProperty, config, context) {
// Set the type (Custom = 1)
this.type = 1;
// Save the configuration
this._config = config;
// Save the key
this.targetProperty = targetProperty;
// Set the properties
this.properties = {
key: this.targetProperty,
context,
onDispose: (el, context) => {
// Call the events
this.dispose(el, context);
this.onDispose ? this.onDispose(el, context) : null;
},
onRender: (el, context, onChange) => {
this.render(el, context, onChange);
this.onRender ? this.onRender(el, context, onChange) : null;
}
};
}
// Applies the tooltip to an element
applyTooltip(el) {
// Apply the tooltip
let content = this._config.tooltip;
if (content) {
Components.Tooltip({
target: el,
content
});
}
}
// Returns the current value as a string
get currentValue() {
let properties = this._config.properties;
return properties ? properties[this.targetProperty] : undefined;
}
// Returns the current value as an object
currentValueAsObject() {
// Ensure a value exists
if (this.currentValue) {
try {
return JSON.parse(this.currentValue);
}
catch (_a) { }
}
// Return nothing
return undefined;
}
// Dispose of the component
onDispose(el, context) { }
dispose(el, context) {
// Clear the element
while (el.firstChild) {
el.removeChild(el.firstChild);
}
}
// Renders the component
onRender(el, context, onChange) { }
render(el, context, onChange) {
// Clear the component
this.dispose(el, context);
}
}