UNPKG

@gpa-gemstone/react-forms

Version:
105 lines (104 loc) 7.34 kB
"use strict"; // ****************************************************************************************************** // AutoCompleteMultiInput.tsx - Gbtc // // Copyright © 2026, 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: // ---------------------------------------------------------------------------------------------------- // 02/26/2026 - Preston Crawford // Generated original version of source code. // // ****************************************************************************************************** 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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var AutoCompleteInput_1 = require("./AutoCompleteInput"); var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols"); var HelpIcon_1 = require("./HelpIcon"); function AutoCompleteMultiInput(props) { var _a, _b; var fieldArray = props.Record[props.Field]; if ((fieldArray === null || fieldArray === void 0 ? void 0 : fieldArray.constructor) !== Array) { console.warn("AutoCompleteMultiInput: ".concat(props.Field.toString(), " is not of type array.")); return React.createElement(React.Fragment, null); } // Variables to control the rendering of label and help icon. var showLabel = props.Label !== ""; var label = props.Label === undefined ? props.Field : props.Label; return (React.createElement(React.Fragment, null, fieldArray.length === 0 ? React.createElement(React.Fragment, null, showLabel ? React.createElement("label", { className: "d-flex align-items-center" }, React.createElement("span", null, showLabel ? label : ''), React.createElement(HelpIcon_1.default, { Help: props.Help }), React.createElement("button", { className: 'btn', style: ((_a = props.DisableAdd) !== null && _a !== void 0 ? _a : false) || ((_b = props.Disabled) !== null && _b !== void 0 ? _b : false) ? { display: 'none' } : undefined, onClick: function () { var _a; return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = [props.DefaultValue], _a))); } }, React.createElement(gpa_symbols_1.ReactIcons.CirclePlus, null))) : null) : null, fieldArray.map(function (r, index) { var _a, _b, _c, _d, _e; return (React.createElement("div", { className: 'row no-gutters', key: index }, React.createElement("div", { className: 'col-10' }, React.createElement(AutoCompleteInput_1.default, { Record: fieldArray, Field: index, Label: index === 0 ? props.Label : '', AllowNull: props.AllowNull, Help: index === 0 ? props.Help : undefined, Feedback: (_b = (_a = props.ItemFeedback) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : undefined, Valid: function () { var _a, _b; return (_b = (_a = props.ItemValid) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : true; }, Style: props.Style, Disabled: props.Disabled, DefaultValue: typeof props.DefaultValue === 'number' ? props.DefaultValue : undefined, Options: props.Options, Setter: function (record) { var _a; var _b; var newArray = __spreadArray([], fieldArray, true); if (!((_b = props.AllowNull) !== null && _b !== void 0 ? _b : true) && record[index] === null) newArray[index] = props.DefaultValue; else newArray[index] = record[index]; props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newArray, _a))); } })), React.createElement("div", { className: "col-".concat(index === __spreadArray([], fieldArray, true).length - 1 ? 1 : 2, " ").concat(index === 0 ? 'd-flex align-items-center justify-content-center' : '') }, React.createElement("button", { className: 'btn', style: ((_c = props.Disabled) !== null && _c !== void 0 ? _c : false) ? { display: 'none' } : undefined, onClick: function () { var _a; var newRecords = __spreadArray([], fieldArray, true).filter(function (_, i) { return i !== index; }); props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newRecords, _a))); } }, React.createElement(gpa_symbols_1.ReactIcons.TrashCan, { Color: 'red' }))), index === __spreadArray([], fieldArray, true).length - 1 ? React.createElement("div", { className: "col-1 ".concat(index === 0 ? 'd-flex align-items-center justify-content-center' : '') }, React.createElement("button", { className: 'btn', style: ((_d = props.DisableAdd) !== null && _d !== void 0 ? _d : false) || ((_e = props.Disabled) !== null && _e !== void 0 ? _e : false) ? { display: 'none' } : undefined, onClick: function () { var _a; var newRecords = __spreadArray(__spreadArray([], __spreadArray([], fieldArray, true), true), [props.DefaultValue], false); props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newRecords, _a))); } }, React.createElement(gpa_symbols_1.ReactIcons.CirclePlus, null))) : null)); }))); } exports.default = AutoCompleteMultiInput;