UNPKG

@gpa-gemstone/react-interactive

Version:
104 lines (103 loc) 6.54 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); // ****************************************************************************************************** // DropdownButton.tsx - Gbtc // // Copyright © 2023, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 10/24/2023 - C. Lackner // Generated original version of source code. // // ****************************************************************************************************** var React = __importStar(require("react")); var helper_functions_1 = require("@gpa-gemstone/helper-functions"); var react_forms_1 = require("@gpa-gemstone/react-forms"); var BtnDropdown = function (props) { var _a, _b, _c, _d, _e; var guid = React.useRef((0, helper_functions_1.CreateGuid)()); var size = (_a = props.Size) !== null && _a !== void 0 ? _a : 'sm'; var className = (_b = props.BtnClass) !== null && _b !== void 0 ? _b : 'btn-primary'; var disabled = (_c = props.Disabled) !== null && _c !== void 0 ? _c : false; var _f = React.useState(false), hover = _f[0], setHover = _f[1]; var _g = React.useState(false), showDropdown = _g[0], setShowDropdown = _g[1]; return (React.createElement("div", { className: "btn-group btn-group-".concat(size) }, React.createElement("button", { type: "button", className: "btn ".concat(className, " ").concat((!disabled ? "" : " disabled")), "data-tooltip": guid.current, onMouseEnter: function () { return setHover(true); }, onMouseLeave: function () { return setHover(false); }, onClick: function () { if (disabled) return; props.Callback(); } }, " ", props.Label), React.createElement("button", { type: "button", className: "btn ".concat(className, " dropdown-toggle dropdown-toggle-split"), onClick: function () { setShowDropdown(function (x) { return !x; }); } }, React.createElement("span", { className: "sr-only" }, "Toggle Dropdown")), React.createElement("div", { className: "dropdown-menu" + (showDropdown ? " show" : "") }, props.Options.map(function (option, i) { var _a; return React.createElement(React.Fragment, { key: (_a = option.Key) !== null && _a !== void 0 ? _a : i }, i > 0 && props.Options[i].Group !== props.Options[i - 1].Group ? React.createElement("div", { className: "dropdown-divider" }) : null, React.createElement(DropDownOption, __assign({}, option, { setShowDropDown: setShowDropdown }))); })), React.createElement(react_forms_1.ToolTip, { Show: hover && ((_d = props.ShowToolTip) !== null && _d !== void 0 ? _d : false), Position: (_e = props.TooltipLocation) !== null && _e !== void 0 ? _e : 'top', Target: guid.current }, props.TooltipContent))); }; var DropDownOption = function (props) { var _a, _b, _c, _d; var _e = React.useState(false), dropDownHover = _e[0], setDropDownHover = _e[1]; var guid = React.useRef((0, helper_functions_1.CreateGuid)()); return (React.createElement(React.Fragment, null, React.createElement("a", { className: "dropdown-item" + (((_a = props === null || props === void 0 ? void 0 : props.Disabled) !== null && _a !== void 0 ? _a : false) ? " disabled" : ""), style: { cursor: (((_b = props === null || props === void 0 ? void 0 : props.Disabled) !== null && _b !== void 0 ? _b : false) ? undefined : 'pointer') }, onClick: function () { var _a; props.setShowDropDown(false); if (!((_a = props === null || props === void 0 ? void 0 : props.Disabled) !== null && _a !== void 0 ? _a : false)) props.Callback(); }, onMouseEnter: function () { return setDropDownHover(true); }, onMouseLeave: function () { return setDropDownHover(false); }, "data-tooltip": guid.current }, props.Label), React.createElement(react_forms_1.ToolTip, { Show: dropDownHover && ((_c = props.ShowToolTip) !== null && _c !== void 0 ? _c : false), Position: (_d = props.ToolTipLocation) !== null && _d !== void 0 ? _d : 'top', Target: guid.current }, props.ToolTipContent))); }; exports.default = BtnDropdown;