@gpa-gemstone/react-forms 1.1.60 → 1.1.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/lib/ArrayCheckBoxes.d.ts +33 -11
  2. package/lib/ArrayCheckBoxes.js +81 -79
  3. package/lib/ArrayMultiSelect.d.ts +47 -13
  4. package/lib/ArrayMultiSelect.js +49 -47
  5. package/lib/CheckBox.d.ts +37 -11
  6. package/lib/CheckBox.js +62 -60
  7. package/lib/ColorPicker.d.ts +59 -15
  8. package/lib/ColorPicker.js +114 -114
  9. package/lib/DatePicker.d.ts +23 -21
  10. package/lib/DatePicker.js +221 -214
  11. package/lib/DateRangePicker.d.ts +64 -13
  12. package/lib/DateRangePicker.js +143 -132
  13. package/lib/DateTimeUI/Calender.d.ts +7 -8
  14. package/lib/DateTimeUI/Calender.js +180 -180
  15. package/lib/DateTimeUI/Clock.d.ts +9 -10
  16. package/lib/DateTimeUI/Clock.js +153 -153
  17. package/lib/DateTimeUI/DateTimePopup.d.ts +16 -17
  18. package/lib/DateTimeUI/DateTimePopup.js +59 -59
  19. package/lib/DoubleInput.d.ts +58 -12
  20. package/lib/DoubleInput.js +55 -51
  21. package/lib/EnumCheckBoxes.d.ts +41 -9
  22. package/lib/EnumCheckBoxes.js +65 -58
  23. package/lib/HelperMessage.d.ts +37 -10
  24. package/lib/HelperMessage.js +93 -83
  25. package/lib/Input.d.ts +80 -18
  26. package/lib/Input.js +111 -106
  27. package/lib/InputWithButton.d.ts +109 -23
  28. package/lib/InputWithButton.js +107 -107
  29. package/lib/MutliCheckBoxSelect.d.ts +42 -18
  30. package/lib/MutliCheckBoxSelect.js +110 -104
  31. package/lib/RadioButtons.d.ts +15 -0
  32. package/lib/RadioButtons.js +62 -0
  33. package/lib/SearchableSelect.d.ts +60 -18
  34. package/lib/SearchableSelect.js +84 -85
  35. package/lib/Select.d.ts +57 -17
  36. package/lib/Select.js +84 -80
  37. package/lib/StylableSelect.d.ts +53 -17
  38. package/lib/StylableSelect.js +106 -101
  39. package/lib/TextArea.d.ts +54 -14
  40. package/lib/TextArea.js +76 -72
  41. package/lib/TimePicker.d.ts +50 -11
  42. package/lib/TimePicker.js +60 -51
  43. package/lib/ToggleSwitch.d.ts +44 -12
  44. package/lib/ToggleSwitch.js +57 -61
  45. package/lib/index.d.ts +19 -18
  46. package/lib/index.js +61 -59
  47. package/package.json +4 -3
@@ -1,104 +1,110 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // MultiCheckBoxSelect.tsx - Gbtc
4
- //
5
- // Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
6
- //
7
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
- // file except in compliance with the License. You may obtain a copy of the License at:
11
- //
12
- // http://opensource.org/licenses/MIT
13
- //
14
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
- // License for the specific language governing permissions and limitations.
17
- //
18
- // Code Modification History:
19
- // ----------------------------------------------------------------------------------------------------
20
- // 07/17/2020 - Billy Ernest
21
- // Generated original version of source code.
22
- //
23
- // ******************************************************************************************************
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- var helper_functions_1 = require("@gpa-gemstone/helper-functions");
26
- var React = require("react");
27
- var HelperMessage_1 = require("./HelperMessage");
28
- var MultiSelect = function (props) {
29
- var _a;
30
- var _b = React.useState(false), show = _b[0], setShow = _b[1];
31
- var _c = React.useState(false), showHelp = _c[0], setShowHelp = _c[1];
32
- var _d = React.useState(false), showItems = _d[0], setShowItems = _d[1];
33
- var _e = React.useState(""), guid = _e[0], setGuid = _e[1];
34
- var multiSelect = React.useRef(null);
35
- var showLabel = React.useMemo(function () { return props.Label !== ""; }, [props.Label]);
36
- var showHelpIcon = React.useMemo(function () { return props.Help !== undefined; }, [props.Help]);
37
- var selectedOptions = React.useMemo(function () { return props.Options.filter(function (opt) { return opt.Selected; }); }, [props.Options]);
38
- React.useEffect(function () {
39
- setGuid((0, helper_functions_1.CreateGuid)());
40
- }, []);
41
- function HandleShow(evt) {
42
- if (multiSelect.current === null)
43
- setShow(!show);
44
- else if (!multiSelect.current.contains(evt.target))
45
- setShow(false);
46
- else
47
- setShow(true);
48
- }
49
- React.useEffect(function () {
50
- document.addEventListener('mousedown', HandleShow, false);
51
- return function () {
52
- document.removeEventListener('mousedown', HandleShow, false);
53
- };
54
- }, []);
55
- return (React.createElement("div", { className: "form-group" },
56
- showLabel || showHelpIcon ?
57
- React.createElement("label", null,
58
- showLabel ?
59
- (props.Label === undefined ? 'Select' : props.Label)
60
- : '',
61
- showHelpIcon ? React.createElement("div", { style: { width: 20, height: 20, borderRadius: '50%', display: 'inline-block', background: '#0D6EFD', marginLeft: 10, textAlign: 'center', fontWeight: 'bold' }, onMouseEnter: function () { return setShowHelp(true); }, onMouseLeave: function () { return setShowHelp(false); } }, " ? ") : null) : null,
62
- showHelpIcon ?
63
- React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
64
- : null,
65
- ((_a = props.ItemTooltip) !== null && _a !== void 0 ? _a : 'no-tip') !== 'no-tip' ?
66
- React.createElement(HelperMessage_1.default, { Show: showItems, Target: guid, Background: props.ItemTooltip === 'dark' ? "#222" : '#fff', Color: props.ItemTooltip === 'dark' ? "#fff" : '#222' },
67
- React.createElement("p", null, "Selected Options:"),
68
- selectedOptions.slice(0, 10).map(function (opt) { return React.createElement("p", null, opt.Text); }),
69
- selectedOptions.length > 10 ? React.createElement("p", null, "and " + (selectedOptions.length - 10) + " other(s)") : null)
70
- : null,
71
- React.createElement("div", { ref: multiSelect, style: { position: 'relative', display: 'block', width: 'inherit' } },
72
- React.createElement("button", { "data-help": guid, type: "button", style: { border: '1px solid #ced4da', padding: '.375rem .75rem', fontSize: '1rem', borderRadius: '.25rem' }, className: "btn form-control dropdown-toggle", onClick: HandleShow, onMouseEnter: function () { return setShowItems(true); }, onMouseLeave: function () { return setShowItems(false); } },
73
- props.Options.filter(function (x) { return x.Selected; }).length !== props.Options.length
74
- ? props.Options.filter(function (x) { return x.Selected; }).length
75
- : 'All ',
76
- ' ',
77
- "Selected"),
78
- React.createElement("div", { style: {
79
- maxHeight: window.innerHeight * 0.75,
80
- overflowY: 'auto',
81
- padding: '10 5',
82
- display: show ? 'block' : 'none',
83
- position: 'absolute',
84
- backgroundColor: '#fff',
85
- color: 'black',
86
- boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
87
- zIndex: 401,
88
- minWidth: '100%',
89
- } },
90
- React.createElement("table", { className: "table", style: { margin: 0 } },
91
- React.createElement("tbody", null,
92
- React.createElement("tr", { onClick: function (evt) {
93
- evt.preventDefault();
94
- props.OnChange(evt, props.Options.filter(function (x) { return x.Selected === (props.Options.filter(function (o) { return o.Selected; }).length === props.Options.length); }));
95
- } },
96
- React.createElement("td", null,
97
- React.createElement("input", { type: "checkbox", checked: props.Options.filter(function (x) { return x.Selected; }).length === props.Options.length, onChange: function () { return null; } })),
98
- React.createElement("td", null, "All")),
99
- props.Options.map(function (f, i) { return (React.createElement("tr", { key: i, onClick: function (evt) { return props.OnChange(evt, [f]); } },
100
- React.createElement("td", null,
101
- React.createElement("input", { type: "checkbox", checked: f.Selected, onChange: function () { return null; } })),
102
- React.createElement("td", null, f.Text))); })))))));
103
- };
104
- exports.default = MultiSelect;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // MultiCheckBoxSelect.tsx - Gbtc
4
+ //
5
+ // Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
6
+ //
7
+ // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
+ // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
+ // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
+ // file except in compliance with the License. You may obtain a copy of the License at:
11
+ //
12
+ // http://opensource.org/licenses/MIT
13
+ //
14
+ // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
+ // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
+ // License for the specific language governing permissions and limitations.
17
+ //
18
+ // Code Modification History:
19
+ // ----------------------------------------------------------------------------------------------------
20
+ // 07/17/2020 - Billy Ernest
21
+ // Generated original version of source code.
22
+ //
23
+ // ******************************************************************************************************
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
26
+ var React = require("react");
27
+ var HelperMessage_1 = require("./HelperMessage");
28
+ var MultiSelect = function (props) {
29
+ var _a;
30
+ // State hooks for managing the visibility of the dropdown and help message.
31
+ var _b = React.useState(false), show = _b[0], setShow = _b[1];
32
+ var _c = React.useState(false), showHelp = _c[0], setShowHelp = _c[1];
33
+ var _d = React.useState(false), showItems = _d[0], setShowItems = _d[1];
34
+ var _e = React.useState(""), guid = _e[0], setGuid = _e[1];
35
+ var multiSelect = React.useRef(null);
36
+ var showLabel = React.useMemo(function () { return props.Label !== ""; }, [props.Label]);
37
+ var showHelpIcon = React.useMemo(function () { return props.Help !== undefined; }, [props.Help]);
38
+ var selectedOptions = React.useMemo(function () { return props.Options.filter(function (opt) { return opt.Selected; }); }, [props.Options]);
39
+ // Effect to generate a unique ID for the component.
40
+ React.useEffect(function () {
41
+ setGuid((0, helper_functions_1.CreateGuid)());
42
+ }, []);
43
+ // Handle showing and hiding of the dropdown.
44
+ function HandleShow(evt) {
45
+ if (multiSelect.current === null)
46
+ setShow(!show);
47
+ else if (!multiSelect.current.contains(evt.target))
48
+ setShow(false);
49
+ else
50
+ setShow(true);
51
+ }
52
+ // Effect to add and remove event listener for clicking outside the component.
53
+ React.useEffect(function () {
54
+ document.addEventListener('mousedown', HandleShow, false);
55
+ return function () {
56
+ document.removeEventListener('mousedown', HandleShow, false);
57
+ };
58
+ }, []);
59
+ return (React.createElement("div", { className: "form-group" },
60
+ showLabel || showHelpIcon ?
61
+ React.createElement("label", null,
62
+ showLabel ?
63
+ (props.Label === undefined ? 'Select' : props.Label)
64
+ : '',
65
+ showHelpIcon ?
66
+ React.createElement("div", { style: { width: 20, height: 20, borderRadius: '50%', display: 'inline-block', background: '#0D6EFD', marginLeft: 10, textAlign: 'center', fontWeight: 'bold' }, onMouseEnter: function () { return setShowHelp(true); }, onMouseLeave: function () { return setShowHelp(false); } }, " ?")
67
+ : null) : null,
68
+ showHelpIcon ?
69
+ React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
70
+ : null,
71
+ ((_a = props.ItemTooltip) !== null && _a !== void 0 ? _a : 'no-tip') !== 'no-tip' ?
72
+ React.createElement(HelperMessage_1.default, { Show: showItems, Target: guid, Background: props.ItemTooltip === 'dark' ? "#222" : '#fff', Color: props.ItemTooltip === 'dark' ? "#fff" : '#222' },
73
+ React.createElement("p", null, "Selected Options:"),
74
+ selectedOptions.slice(0, 10).map(function (opt) { return React.createElement("p", null, opt.Text); }),
75
+ selectedOptions.length > 10 ? React.createElement("p", null, "and ".concat(selectedOptions.length - 10, " other(s)")) : null)
76
+ : null,
77
+ React.createElement("div", { ref: multiSelect, style: { position: 'relative', display: 'block', width: 'inherit' } },
78
+ React.createElement("button", { "data-help": guid, type: "button", style: { border: '1px solid #ced4da', padding: '.375rem .75rem', fontSize: '1rem', borderRadius: '.25rem' }, className: "btn form-control dropdown-toggle", onClick: HandleShow, onMouseEnter: function () { return setShowItems(true); }, onMouseLeave: function () { return setShowItems(false); } },
79
+ props.Options.filter(function (x) { return x.Selected; }).length !== props.Options.length
80
+ ? props.Options.filter(function (x) { return x.Selected; }).length
81
+ : 'All ',
82
+ ' ',
83
+ "Selected"),
84
+ React.createElement("div", { style: {
85
+ maxHeight: window.innerHeight * 0.75,
86
+ overflowY: 'auto',
87
+ padding: '10 5',
88
+ display: show ? 'block' : 'none',
89
+ position: 'absolute',
90
+ backgroundColor: '#fff',
91
+ color: 'black',
92
+ boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
93
+ zIndex: 401,
94
+ minWidth: '100%',
95
+ } },
96
+ React.createElement("table", { className: "table", style: { margin: 0 } },
97
+ React.createElement("tbody", null,
98
+ React.createElement("tr", { onClick: function (evt) {
99
+ evt.preventDefault();
100
+ props.OnChange(evt, props.Options.filter(function (x) { return x.Selected === (props.Options.filter(function (o) { return o.Selected; }).length === props.Options.length); }));
101
+ } },
102
+ React.createElement("td", null,
103
+ React.createElement("input", { type: "checkbox", checked: props.Options.filter(function (x) { return x.Selected; }).length === props.Options.length, onChange: function () { return null; } })),
104
+ React.createElement("td", null, "All")),
105
+ props.Options.map(function (f, i) { return (React.createElement("tr", { key: i, onClick: function (evt) { return props.OnChange(evt, [f]); } },
106
+ React.createElement("td", null,
107
+ React.createElement("input", { type: "checkbox", checked: f.Selected, onChange: function () { return null; } })),
108
+ React.createElement("td", null, f.Text))); })))))));
109
+ };
110
+ exports.default = MultiSelect;
@@ -0,0 +1,15 @@
1
+ interface IProps<T> {
2
+ Record: T;
3
+ Field: keyof T;
4
+ Setter: (record: T) => void;
5
+ Help?: string | JSX.Element;
6
+ Position?: ('vertical' | 'horizontal');
7
+ Options: {
8
+ Value: string;
9
+ Label: string;
10
+ Disabled?: boolean;
11
+ }[];
12
+ Label?: string;
13
+ }
14
+ export default function RadioButtons<T>(props: IProps<T>): JSX.Element;
15
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // RadioButtons.tsx - Gbtc
4
+ //
5
+ // Copyright © 2024, Grid Protection Alliance. All Rights Reserved.
6
+ //
7
+ // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
+ // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
+ // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
+ // file except in compliance with the License. You may obtain a copy of the License at:
11
+ //
12
+ // http://opensource.org/licenses/MIT
13
+ //
14
+ // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
+ // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
+ // License for the specific language governing permissions and limitations.
17
+ //
18
+ // Code Modification History:
19
+ // ----------------------------------------------------------------------------------------------------
20
+ // 06/10/2024 - Preston Crawford
21
+ // Generated original version of source code.
22
+ //
23
+ // ******************************************************************************************************
24
+ var __assign = (this && this.__assign) || function () {
25
+ __assign = Object.assign || function(t) {
26
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
27
+ s = arguments[i];
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
+ t[p] = s[p];
30
+ }
31
+ return t;
32
+ };
33
+ return __assign.apply(this, arguments);
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.default = RadioButtons;
37
+ var React = require("react");
38
+ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
39
+ var HelperMessage_1 = require("./HelperMessage");
40
+ function RadioButtons(props) {
41
+ var _a;
42
+ var guid = React.useRef((0, helper_functions_1.CreateGuid)());
43
+ var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
44
+ var showHelpIcon = props.Help !== undefined;
45
+ return (React.createElement("div", { className: "form-group", "data-help": guid.current },
46
+ React.createElement("label", { className: "form-check-label d-block" }, (_a = props.Label) !== null && _a !== void 0 ? _a : props.Field),
47
+ props.Options.map(function (option, index) {
48
+ var _a;
49
+ return (React.createElement("div", { key: index, className: "form-check ".concat(props.Position == 'vertical' ? '' : 'form-check-inline') },
50
+ React.createElement("input", { type: "radio", className: "form-check-input", style: { zIndex: 1 }, onChange: function () {
51
+ var record = __assign({}, props.Record);
52
+ record[props.Field] = option.Value;
53
+ props.Setter(record);
54
+ }, 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) }),
55
+ React.createElement("label", { className: "form-check-label", htmlFor: "".concat(option.Label, "-").concat(index) }, option.Label)));
56
+ }),
57
+ showHelpIcon ?
58
+ React.createElement(React.Fragment, null,
59
+ React.createElement("div", { style: { width: 20, height: 20, borderRadius: '50%', display: 'inline-block', background: '#0D6EFD', marginLeft: 10, textAlign: 'center', fontWeight: 'bold' }, onMouseEnter: function () { return setShowHelp(true); }, onMouseLeave: function () { return setShowHelp(false); } }, "?"),
60
+ React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid.current }, props.Help))
61
+ : null));
62
+ }
@@ -1,18 +1,60 @@
1
- import * as React from 'react';
2
- interface IOption {
3
- Value: string;
4
- Label: string;
5
- }
6
- interface IProps<T> {
7
- Record: T;
8
- Field: keyof T;
9
- Setter: (record: T) => void;
10
- AllowCustom?: boolean;
11
- Search: (search: string) => [promise: Promise<IOption[]>, callback?: () => void];
12
- Label?: string;
13
- Disabled?: boolean;
14
- Help?: string | JSX.Element;
15
- Style?: React.CSSProperties;
16
- }
17
- export default function SearchableSelect<T>(props: IProps<T>): JSX.Element;
18
- export {};
1
+ import * as React from 'react';
2
+ interface IOption {
3
+ Value: string;
4
+ Label: string;
5
+ }
6
+ interface IProps<T> {
7
+ /**
8
+ * Record to be used in form
9
+ * @type {T}
10
+ */
11
+ Record: T;
12
+ /**
13
+ * Field of the record to be edited
14
+ * @type {keyof T}
15
+ */
16
+ Field: keyof T;
17
+ /**
18
+ * Setter function to update the Record
19
+ * @param record - Updated Record
20
+ */
21
+ Setter: (record: T) => void;
22
+ /**
23
+ * Flag to allow custom input values
24
+ * @type {boolean}
25
+ * @optional
26
+ */
27
+ AllowCustom?: boolean;
28
+ /**
29
+ * Function to perform a search and return a promise with a list of IOption and an optional callback
30
+ * @param search - Search string
31
+ * @returns {[promise: Promise<IOption[]>, callback?: () => void]}
32
+ */
33
+ Search: (search: string) => [promise: Promise<IOption[]>, callback?: () => void];
34
+ /**
35
+ * Label to display for the form, defaults to the Field prop
36
+ * @type {string}
37
+ * @optional
38
+ */
39
+ Label?: string;
40
+ /**
41
+ * Flag to disable the input field
42
+ * @type {boolean}
43
+ * @optional
44
+ */
45
+ Disabled?: boolean;
46
+ /**
47
+ * Help message or element to display
48
+ * @type {string | JSX.Element}
49
+ * @optional
50
+ */
51
+ Help?: string | JSX.Element;
52
+ /**
53
+ * CSS styles to apply to the form group
54
+ * @type {React.CSSProperties}
55
+ * @optional
56
+ */
57
+ Style?: React.CSSProperties;
58
+ }
59
+ export default function SearchableSelect<T>(props: IProps<T>): JSX.Element;
60
+ export {};
@@ -1,85 +1,84 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // SearchableSelect.tsx - Gbtc
4
- //
5
- // Copyright © 2024, Grid Protection Alliance. All Rights Reserved.
6
- //
7
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
- // file except in compliance with the License. You may obtain a copy of the License at:
11
- //
12
- // http://opensource.org/licenses/MIT
13
- //
14
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
- // License for the specific language governing permissions and limitations.
17
- //
18
- // Code Modification History:
19
- // ----------------------------------------------------------------------------------------------------
20
- // 03/17/2024 - C. Lackner
21
- // Generated original version of source code.
22
- //
23
- // ******************************************************************************************************
24
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
25
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
26
- return cooked;
27
- };
28
- var __assign = (this && this.__assign) || function () {
29
- __assign = Object.assign || function(t) {
30
- for (var s, i = 1, n = arguments.length; i < n; i++) {
31
- s = arguments[i];
32
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
33
- t[p] = s[p];
34
- }
35
- return t;
36
- };
37
- return __assign.apply(this, arguments);
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- var React = require("react");
41
- var StylableSelect_1 = require("./StylableSelect");
42
- var styled_components_1 = require("styled-components");
43
- function SearchableSelect(props) {
44
- var _a = React.useState(props.Record[props.Field].toString()), search = _a[0], setSearch = _a[1];
45
- var _b = React.useState([]), results = _b[0], setResults = _b[1];
46
- var _c = React.useState(false), loading = _c[0], setLoading = _c[1];
47
- React.useEffect(function () {
48
- setLoading(true);
49
- var _a = props.Search(search), h = _a[0], c = _a[1];
50
- h.then(function (d) { setResults(d.map(function (o) { return ({ Value: o.Value, Element: React.createElement("p", null, o.Label) }); })); setLoading(false); });
51
- return c;
52
- }, [search]);
53
- var options = React.useMemo(function () {
54
- var _a, _b, _c;
55
- var r = [];
56
- if ((_a = props.AllowCustom) !== null && _a !== void 0 ? _a : false)
57
- r.push({ Value: search, Element: React.createElement("p", null, search) });
58
- r.push({
59
- Value: props.Record[props.Field], Element: React.createElement("div", { className: 'input-group' },
60
- React.createElement("input", { type: "text", className: "form-control", value: search, onChange: function (d) { return setSearch(d.target.value); }, onBlur: (((_b = props.AllowCustom) !== null && _b !== void 0 ? _b : false) ? function () {
61
- var _a;
62
- return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = search, _a)));
63
- } : function () { return setSearch(props.Record[props.Field].toString()); }) }),
64
- React.createElement("div", { className: "input-group-append" },
65
- React.createElement("span", { className: "input-group-text" },
66
- React.createElement(Icon, null))),
67
- "s")
68
- });
69
- r.push.apply(r, results.filter(function (f) { return f.Value !== search && f.Value !== props.Record[props.Field]; }));
70
- if (!((_c = props.AllowCustom) !== null && _c !== void 0 ? _c : false))
71
- r.push({ Value: 'search-' + props.Record[props.Field], Element: React.createElement("p", null, props.Record[props.Field]) });
72
- return r;
73
- }, [search, props.Record[props.Field], results, props.Disabled, loading]);
74
- var update = React.useCallback(function (record) {
75
- if (record[props.Field].toString().startsWith('search-'))
76
- return;
77
- props.Setter(record);
78
- setSearch(record[props.Field].toString());
79
- }, [props.Setter, props.Field]);
80
- return React.createElement(StylableSelect_1.default, { Record: props.Record, Field: props.Field, Setter: update, Label: props.Label, Disabled: props.Disabled, Help: props.Help, Style: props.Style, Options: options });
81
- }
82
- exports.default = SearchableSelect;
83
- var spin = (0, styled_components_1.keyframes)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"], ["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"])));
84
- var Icon = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\tanimation: ", " 1s linear infinite;\n\tborder: 5px solid #f3f3f3;\n\tborder-Top: 5px solid #555;\n\tborder-Radius: 50%;\n\twidth: 25px;\n\theight: 25px\n"], ["\n\tanimation: ", " 1s linear infinite;\n\tborder: 5px solid #f3f3f3;\n\tborder-Top: 5px solid #555;\n\tborder-Radius: 50%;\n\twidth: 25px;\n\theight: 25px\n"])), spin);
85
- var templateObject_1, templateObject_2;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // SearchableSelect.tsx - Gbtc
4
+ //
5
+ // Copyright © 2024, Grid Protection Alliance. All Rights Reserved.
6
+ //
7
+ // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
+ // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
+ // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
+ // file except in compliance with the License. You may obtain a copy of the License at:
11
+ //
12
+ // http://opensource.org/licenses/MIT
13
+ //
14
+ // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
+ // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
+ // License for the specific language governing permissions and limitations.
17
+ //
18
+ // Code Modification History:
19
+ // ----------------------------------------------------------------------------------------------------
20
+ // 03/17/2024 - C. Lackner
21
+ // Generated original version of source code.
22
+ //
23
+ // ******************************************************************************************************
24
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
25
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
26
+ return cooked;
27
+ };
28
+ var __assign = (this && this.__assign) || function () {
29
+ __assign = Object.assign || function(t) {
30
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
31
+ s = arguments[i];
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
33
+ t[p] = s[p];
34
+ }
35
+ return t;
36
+ };
37
+ return __assign.apply(this, arguments);
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.default = SearchableSelect;
41
+ var React = require("react");
42
+ var StylableSelect_1 = require("./StylableSelect");
43
+ var styled_components_1 = require("styled-components");
44
+ function SearchableSelect(props) {
45
+ var _a = React.useState(props.Record[props.Field].toString()), search = _a[0], setSearch = _a[1];
46
+ var _b = React.useState([]), results = _b[0], setResults = _b[1];
47
+ var _c = React.useState(false), loading = _c[0], setLoading = _c[1];
48
+ React.useEffect(function () {
49
+ setLoading(true);
50
+ var _a = props.Search(search), h = _a[0], c = _a[1];
51
+ h.then(function (d) { setResults(d.map(function (o) { return ({ Value: o.Value, Element: React.createElement("p", null, o.Label) }); })); setLoading(false); });
52
+ return c;
53
+ }, [search]);
54
+ var options = React.useMemo(function () {
55
+ var _a, _b, _c;
56
+ var r = [];
57
+ if ((_a = props.AllowCustom) !== null && _a !== void 0 ? _a : false)
58
+ r.push({ Value: search, Element: React.createElement("p", null, search) });
59
+ r.push({
60
+ Value: props.Record[props.Field], Element: React.createElement("div", { className: 'input-group' },
61
+ React.createElement("input", { type: "text", className: "form-control", value: search, onChange: function (d) { return setSearch(d.target.value); }, onBlur: (((_b = props.AllowCustom) !== null && _b !== void 0 ? _b : false) ? function () {
62
+ var _a;
63
+ return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = search, _a)));
64
+ } : function () { return setSearch(props.Record[props.Field].toString()); }) }),
65
+ React.createElement("div", { className: "input-group-append" },
66
+ React.createElement("span", { className: "input-group-text" },
67
+ React.createElement(Icon, null))))
68
+ });
69
+ r.push.apply(r, results.filter(function (f) { return f.Value !== search && f.Value !== props.Record[props.Field]; }));
70
+ if (!((_c = props.AllowCustom) !== null && _c !== void 0 ? _c : false))
71
+ r.push({ Value: 'search-' + props.Record[props.Field], Element: React.createElement("p", null, props.Record[props.Field]) });
72
+ return r;
73
+ }, [search, props.Record[props.Field], results, props.Disabled, loading]);
74
+ var update = React.useCallback(function (record) {
75
+ if (record[props.Field].toString().startsWith('search-'))
76
+ return;
77
+ props.Setter(record);
78
+ setSearch(record[props.Field].toString());
79
+ }, [props.Setter, props.Field]);
80
+ return React.createElement(StylableSelect_1.default, { Record: props.Record, Field: props.Field, Setter: update, Label: props.Label, Disabled: props.Disabled, Help: props.Help, Style: props.Style, Options: options });
81
+ }
82
+ var spin = (0, styled_components_1.keyframes)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"], ["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"])));
83
+ var Icon = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\tanimation: ", " 1s linear infinite;\n\tborder: 5px solid #f3f3f3;\n\tborder-Top: 5px solid #555;\n\tborder-Radius: 50%;\n\twidth: 25px;\n\theight: 25px\n"], ["\n\tanimation: ", " 1s linear infinite;\n\tborder: 5px solid #f3f3f3;\n\tborder-Top: 5px solid #555;\n\tborder-Radius: 50%;\n\twidth: 25px;\n\theight: 25px\n"])), spin);
84
+ var templateObject_1, templateObject_2;