UNPKG

gd-sprest-js

Version:

SharePoint 2013/Online js components.

86 lines (85 loc) 3.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Contextual Menu */ exports.ContextualMenu = function (props) { // Set the hidden property var isHidden = typeof (props.isHidden) === "boolean" ? props.isHidden : true; // Method to determine if checkboxes exist var hasCheckboxes = function (items) { // Parse the items for (var i = 0; i < items.length; i++) { // See if this item has icons if (items[i].isSelected) { return true; } } // Does not have icons return false; }; // Method to determine if icons exist var hasIcons = function (items) { // Parse the items for (var i = 0; i < items.length; i++) { // See if this item has icons if (items[i].icon) { return true; } } // Does not have icons return false; }; // Method to render the items var renderItems = function (items) { var menuItems = []; // Ensure items exist if (items && items.length > 0) { // Parse the items for (var i = 0; i < items.length; i++) { var item = items[i]; // Set the class name var className = [ "ms-ContextualMenu-link", item.isDisabled ? "is-disabled" : "", item.isSelected ? "is-selected" : "" ].join(" "); // Set the attributes var attributes = [ 'class="ms-ContextualMenu-item' + (item.menu ? ' ms-ContextualMenu-item--hasMenu' : '') + '"', item.data ? 'data-item="' + JSON.stringify(item.data) + '"' : '' ].join(" "); // Add the menu item menuItems.push([ '<li ' + attributes + '>', '<a class="' + className + '" tabindex="1">' + (item.text || "") + '</a>', item.icon ? '<i class="ms-Icon ms-Icon--' + item.icon + '"></i>' : '', item.menu ? '<i class="ms-ContextualMenu-subMenuIcon ms-Icon ms-Icon--ChevronRight"></i>' : '', item.menu ? renderList(false, "", item.menu) : '', '</li>' ].join('\n')); } } // Return the items return menuItems.join('\n'); }; // Method to render the list template var renderList = function (isHidden, className, items) { // Set the class name var elClassName = [ "ms-ContextualMenu", className || "", isHidden ? "is-hidden" : "", hasCheckboxes(items) ? "ms-ContextualMenu--hasChecks" : "", hasIcons(items) ? "ms-ContextualMenu--hasIcons" : "" ].join(' ').trim(); // Return the template return [ '<ul class="' + elClassName + '">', renderItems(items), '</ul>' ].join('\n'); }; // Render the template return renderList(isHidden, "", props.items); };