UNPKG

@gpa-gemstone/react-forms

Version:
67 lines (66 loc) 4.08 kB
"use strict"; // ****************************************************************************************************** // RadioButtons.tsx - Gbtc // // Copyright © 2024, 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: // ---------------------------------------------------------------------------------------------------- // 06/10/2024 - 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = RadioButtons; var React = require("react"); var helper_functions_1 = require("@gpa-gemstone/helper-functions"); var ToolTip_1 = require("./ToolTip"); var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols"); function RadioButtons(props) { var guid = React.useState((0, helper_functions_1.CreateGuid)())[0]; var _a = React.useState(false), showHelp = _a[0], setShowHelp = _a[1]; // Variables to control the rendering of label and help icon. var showHelpIcon = props.Help !== undefined; var label = props.Label === undefined ? props.Field : props.Label; return (React.createElement("div", { className: "form-group" }, React.createElement("label", { className: "form-check-label w-100 d-flex align-items-center" }, React.createElement("span", null, label), showHelpIcon ? React.createElement(React.Fragment, null, React.createElement("span", { className: "ml-2 d-flex align-items-center", onMouseEnter: function () { return setShowHelp(true); }, onMouseLeave: function () { return setShowHelp(false); }, "data-tooltip": guid }, React.createElement(gpa_symbols_1.ReactIcons.QuestionMark, { Color: "var(--info)", Size: 20 })), React.createElement(ToolTip_1.default, { Show: showHelp, Target: guid, Class: "info", Position: "top" }, props.Help)) : null), props.Options.map(function (option, index) { var _a; return (React.createElement("div", { key: index, className: "form-check ".concat(props.Position == 'vertical' ? '' : 'form-check-inline') }, React.createElement("input", { type: "radio", className: "form-check-input", style: { zIndex: 1 }, onChange: function () { var record = __assign({}, props.Record); record[props.Field] = option.Value; props.Setter(record); }, value: option.Value, checked: props.Record[props.Field] === option.Value, disabled: (_a = option.Disabled) !== null && _a !== void 0 ? _a : false, id: "".concat(option.Label, "-").concat(index) }), React.createElement("label", { className: "form-check-label", htmlFor: "".concat(option.Label, "-").concat(index) }, option.Label))); }))); }