UNPKG

gd-sprest-js

Version:

SharePoint 2013/Online js components.

41 lines (40 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _1 = require("."); /** * Toggle */ exports.Toggle = function (props) { // Method to get the toggle element var get = function () { // Returns the toggle element return props.el.querySelector(".ms-Toggle"); }; // Method to get the fabric component var getFabricComponent = function () { // Return the toggle return _toggle; }; // Method to get the value var getValue = function () { // Get the toggle value return _toggle ? _toggle._container.querySelector(".ms-Toggle-field").classList.contains("is-selected") : false; }; // Add the toggle html props.el.innerHTML = _1.Templates.Toggle(props); // Get the toggle var toggle = get(); // Set the toggle click event toggle.onclick = function () { // Execute the change event props.onChange ? props.onChange(getValue()) : null; }; // Create the toggle var _toggle = new _1.fabric.Toggle(toggle); // Return the toggle return { get: get, getFabricComponent: getFabricComponent, getValue: getValue }; };