@gpa-gemstone/react-forms 1.1.59 → 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 -100
  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
package/lib/Select.d.ts CHANGED
@@ -1,17 +1,57 @@
1
- /// <reference types="react" />
2
- interface IProps<T> {
3
- Record: T;
4
- Field: keyof T;
5
- Options: {
6
- Value: string;
7
- Label: string;
8
- }[];
9
- Setter: (record: T) => void;
10
- Label?: string;
11
- Disabled?: boolean;
12
- EmptyOption?: boolean;
13
- EmptyLabel?: string;
14
- Help?: string | JSX.Element;
15
- }
16
- export default function Select<T>(props: IProps<T>): JSX.Element;
17
- export {};
1
+ interface IProps<T> {
2
+ /**
3
+ * Record to be used in form
4
+ * @type {T}
5
+ */
6
+ Record: T;
7
+ /**
8
+ * Field of the record to be edited
9
+ * @type {keyof T}
10
+ */
11
+ Field: keyof T;
12
+ /**
13
+ * Options for the select dropdown
14
+ * @type {{ Value: string; Label: string }[]}
15
+ */
16
+ Options: {
17
+ Value: string;
18
+ Label: string;
19
+ }[];
20
+ /**
21
+ * Setter function to update the Record
22
+ * @param record - Updated Record
23
+ */
24
+ Setter: (record: T) => void;
25
+ /**
26
+ * Label to display for the form, defaults to the Field prop
27
+ * @type {string}
28
+ * @optional
29
+ */
30
+ Label?: string;
31
+ /**
32
+ * Flag to disable the input field
33
+ * @type {boolean}
34
+ * @optional
35
+ */
36
+ Disabled?: boolean;
37
+ /**
38
+ * Flag to include an empty option in the select dropdown
39
+ * @type {boolean}
40
+ * @optional
41
+ */
42
+ EmptyOption?: boolean;
43
+ /**
44
+ * Label to display for the empty option
45
+ * @type {string}
46
+ * @optional
47
+ */
48
+ EmptyLabel?: string;
49
+ /**
50
+ * Help message or element to display
51
+ * @type {string | JSX.Element}
52
+ * @optional
53
+ */
54
+ Help?: string | JSX.Element;
55
+ }
56
+ export default function Select<T>(props: IProps<T>): JSX.Element;
57
+ export {};
package/lib/Select.js CHANGED
@@ -1,80 +1,84 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // Select.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
- // 01/28/2020 - Billy Ernest
21
- // Generated original version of source code.
22
- // 05/05/2021 - C. Lackner
23
- // Added Help Message.
24
- //
25
- // ******************************************************************************************************
26
- var __assign = (this && this.__assign) || function () {
27
- __assign = Object.assign || function(t) {
28
- for (var s, i = 1, n = arguments.length; i < n; i++) {
29
- s = arguments[i];
30
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
31
- t[p] = s[p];
32
- }
33
- return t;
34
- };
35
- return __assign.apply(this, arguments);
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- var React = require("react");
39
- var HelperMessage_1 = require("./HelperMessage");
40
- var helper_functions_1 = require("@gpa-gemstone/helper-functions");
41
- function Select(props) {
42
- var _a;
43
- var _b = React.useState(""), guid = _b[0], setGuid = _b[1];
44
- var _c = React.useState(false), showHelp = _c[0], setShowHelp = _c[1];
45
- React.useEffect(function () {
46
- setGuid((0, helper_functions_1.CreateGuid)());
47
- }, []);
48
- React.useEffect(function () {
49
- var _a;
50
- var currentValue = GetRecordValue();
51
- if (!((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) && props.Options.length > 0 && props.Options.findIndex(function (option) { return option.Value === currentValue; }) === -1) {
52
- SetRecord(props.Options[0].Value);
53
- // tslint:disable-next-line
54
- console.warn("The current value is not available as an option. Specify EmptyOption=true if the value should be allowed.");
55
- }
56
- }, [props.Options]);
57
- function SetRecord(value) {
58
- var record = __assign({}, props.Record);
59
- if (value !== '')
60
- record[props.Field] = value;
61
- else
62
- record[props.Field] = null;
63
- props.Setter(record);
64
- }
65
- function GetRecordValue() {
66
- return props.Record[props.Field] == null ? '' : props.Record[props.Field].toString();
67
- }
68
- return (React.createElement("div", { className: "form-group" },
69
- (props.Label !== "") ?
70
- React.createElement("label", null,
71
- props.Label === undefined ? props.Field : props.Label,
72
- props.Help !== undefined ? 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,
73
- props.Help !== undefined ?
74
- React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
75
- : null,
76
- React.createElement("select", { "data-help": guid, className: "form-control", onChange: function (evt) { return SetRecord(evt.target.value); }, value: GetRecordValue(), disabled: props.Disabled == null ? false : props.Disabled },
77
- ((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : true) ? React.createElement("option", { value: "" }, props.EmptyLabel !== undefined ? props.EmptyLabel : '') : null,
78
- props.Options.map(function (a, i) { return (React.createElement("option", { key: i, value: a.Value }, a.Label)); }))));
79
- }
80
- exports.default = Select;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // Select.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
+ // 01/28/2020 - Billy Ernest
21
+ // Generated original version of source code.
22
+ // 05/05/2021 - C. Lackner
23
+ // Added Help Message.
24
+ //
25
+ // ******************************************************************************************************
26
+ var __assign = (this && this.__assign) || function () {
27
+ __assign = Object.assign || function(t) {
28
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29
+ s = arguments[i];
30
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
31
+ t[p] = s[p];
32
+ }
33
+ return t;
34
+ };
35
+ return __assign.apply(this, arguments);
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.default = Select;
39
+ var React = require("react");
40
+ var HelperMessage_1 = require("./HelperMessage");
41
+ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
42
+ function Select(props) {
43
+ var _a;
44
+ var _b = React.useState(""), guid = _b[0], setGuid = _b[1];
45
+ var _c = React.useState(false), showHelp = _c[0], setShowHelp = _c[1];
46
+ // Effect to generate a unique ID for the component.
47
+ React.useEffect(function () {
48
+ setGuid((0, helper_functions_1.CreateGuid)());
49
+ }, []);
50
+ // Effect to validate the current value against the available options.
51
+ React.useEffect(function () {
52
+ var _a;
53
+ var currentValue = GetRecordValue();
54
+ if (!((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) && props.Options.length > 0 && props.Options.findIndex(function (option) { return option.Value === currentValue; }) === -1) {
55
+ SetRecord(props.Options[0].Value);
56
+ // tslint:disable-next-line
57
+ console.warn("The current value is not available as an option. Specify EmptyOption=true if the value should be allowed.");
58
+ }
59
+ }, [props.Options]);
60
+ // Update the parent component's state with the new value.
61
+ function SetRecord(value) {
62
+ var record = __assign({}, props.Record);
63
+ if (value !== '')
64
+ record[props.Field] = value;
65
+ else
66
+ record[props.Field] = null;
67
+ props.Setter(record);
68
+ }
69
+ // Rretrieve the current value of the select field from the record.
70
+ function GetRecordValue() {
71
+ return props.Record[props.Field] == null ? '' : props.Record[props.Field].toString();
72
+ }
73
+ return (React.createElement("div", { className: "form-group" },
74
+ (props.Label !== "") ?
75
+ React.createElement("label", null,
76
+ props.Label === undefined ? props.Field : props.Label,
77
+ props.Help !== undefined ? 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,
78
+ props.Help !== undefined ?
79
+ React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
80
+ : null,
81
+ React.createElement("select", { "data-help": guid, className: "form-control", onChange: function (evt) { return SetRecord(evt.target.value); }, value: GetRecordValue(), disabled: props.Disabled == null ? false : props.Disabled },
82
+ ((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) ? React.createElement("option", { value: "" }, props.EmptyLabel !== undefined ? props.EmptyLabel : '') : null,
83
+ props.Options.map(function (a, i) { return (React.createElement("option", { key: i, value: a.Value }, a.Label)); }))));
84
+ }
@@ -1,17 +1,53 @@
1
- import * as React from 'react';
2
- export interface IOption {
3
- Value: any;
4
- Element: React.ReactElement<any>;
5
- }
6
- interface IProps<T> {
7
- Record: T;
8
- Field: keyof T;
9
- Setter: (record: T) => void;
10
- Options: IOption[];
11
- Label?: string;
12
- Disabled?: boolean;
13
- Help?: string | JSX.Element;
14
- Style?: React.CSSProperties;
15
- }
16
- export default function StylableSelect<T>(props: IProps<T>): JSX.Element;
17
- export {};
1
+ import * as React from 'react';
2
+ export interface IOption {
3
+ Value: any;
4
+ Element: React.ReactElement<any>;
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
+ * Options for the select dropdown
24
+ * @type {{ Value: any, Element: React.ReactElement<any> }[]}
25
+ */
26
+ Options: IOption[];
27
+ /**
28
+ * Label to display for the form, defaults to the Field prop
29
+ * @type {string}
30
+ * @optional
31
+ */
32
+ Label?: string;
33
+ /**
34
+ * Flag to disable the input field
35
+ * @type {boolean}
36
+ * @optional
37
+ */
38
+ Disabled?: boolean;
39
+ /**
40
+ * Help message or element to display
41
+ * @type {string | JSX.Element}
42
+ * @optional
43
+ */
44
+ Help?: string | JSX.Element;
45
+ /**
46
+ * CSS styles to apply to the selected value
47
+ * @type {React.CSSProperties}
48
+ * @optional
49
+ */
50
+ Style?: React.CSSProperties;
51
+ }
52
+ export default function StylableSelect<T>(props: IProps<T>): JSX.Element;
53
+ export {};
@@ -1,100 +1,106 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // StylableSelect.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
- // 10/14/2022 - Gabriel Santos
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
- var React = require("react");
37
- var HelperMessage_1 = require("./HelperMessage");
38
- var helper_functions_1 = require("@gpa-gemstone/helper-functions");
39
- function StylableSelect(props) {
40
- var _a = React.useState(false), show = _a[0], setShow = _a[1];
41
- var _b = React.useState(props.Options[0].Element), selected = _b[0], setSelected = _b[1];
42
- var _c = React.useState(""), guid = _c[0], setGuid = _c[1];
43
- var _d = React.useState(false), showHelp = _d[0], setShowHelp = _d[1];
44
- var stylableSelect = React.useRef(null);
45
- function HandleShow(evt) {
46
- // Ignore if disabled or not a mousedown event
47
- if ((props.Disabled === undefined ? false : props.Disabled) || evt.type !== 'mousedown')
48
- return;
49
- if (!stylableSelect.current.contains(evt.target))
50
- setShow(false);
51
- else
52
- setShow(!show);
53
- }
54
- function SetRecord(selectedOption) {
55
- setSelected(selectedOption.Element);
56
- var record = __assign({}, props.Record);
57
- if (selectedOption.Value !== '')
58
- record[props.Field] = selectedOption.Value;
59
- else
60
- record[props.Field] = null;
61
- props.Setter(record);
62
- }
63
- React.useEffect(function () {
64
- setGuid((0, helper_functions_1.CreateGuid)());
65
- document.addEventListener('mousedown', HandleShow, false);
66
- return function () {
67
- document.removeEventListener('mousedown', HandleShow, false);
68
- };
69
- }, []);
70
- React.useEffect(function () {
71
- var element = props.Options.find(function (e) { return e.Value === props.Record[props.Field]; });
72
- setSelected(element !== undefined ? element.Element : React.createElement("div", null));
73
- }, [props.Record, props.Options]);
74
- return (React.createElement("div", { ref: stylableSelect, style: { position: 'relative', display: 'inline-block', width: 'inherit' } },
75
- (props.Label !== "") ?
76
- React.createElement("label", null,
77
- props.Label === undefined ? props.Field : props.Label,
78
- props.Help !== undefined ? 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,
79
- props.Help !== undefined ?
80
- React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
81
- : null,
82
- React.createElement("button", { type: "button", style: { border: '1px solid #ced4da', padding: '.375rem .75rem', fontSize: '1rem', borderRadius: '.25rem' }, "data-help": guid, className: "btn form-control dropdown-toggle", onClick: HandleShow, disabled: props.Disabled === undefined ? false : props.Disabled },
83
- React.createElement("div", { style: props.Style }, 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
- boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
92
- zIndex: 401,
93
- minWidth: '100%',
94
- } },
95
- React.createElement("table", { className: "table", style: { margin: 0 } },
96
- React.createElement("tbody", null, props.Options.map(function (f, i) { return (f.Value == props.Record[props.Field] ? null :
97
- React.createElement("tr", { key: i, onClick: function (evt) { evt.preventDefault(); SetRecord(f); setShow(false); } },
98
- React.createElement("td", null, f.Element))); }))))));
99
- }
100
- exports.default = StylableSelect;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // StylableSelect.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
+ // 10/14/2022 - Gabriel Santos
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 = StylableSelect;
37
+ var React = require("react");
38
+ var HelperMessage_1 = require("./HelperMessage");
39
+ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
40
+ var lodash_1 = require("lodash");
41
+ function StylableSelect(props) {
42
+ // State hooks and ref for managing component state and interactions.
43
+ var _a = React.useState(false), show = _a[0], setShow = _a[1];
44
+ var _b = React.useState(props.Options[0].Element), selected = _b[0], setSelected = _b[1];
45
+ var _c = React.useState(""), guid = _c[0], setGuid = _c[1];
46
+ var _d = React.useState(false), showHelp = _d[0], setShowHelp = _d[1];
47
+ var stylableSelect = React.useRef(null);
48
+ // Handle showing and hiding of the dropdown.
49
+ function HandleShow(evt) {
50
+ // Ignore if disabled or not a mousedown event
51
+ if ((props.Disabled === undefined ? false : props.Disabled) || evt.type !== 'mousedown')
52
+ return;
53
+ if (!stylableSelect.current.contains(evt.target))
54
+ setShow(false);
55
+ else
56
+ setShow(!show);
57
+ }
58
+ // Update the parent component's state with the selected option.
59
+ function SetRecord(selectedOption) {
60
+ setSelected(selectedOption.Element);
61
+ var record = __assign({}, props.Record);
62
+ if (selectedOption.Value !== '')
63
+ record[props.Field] = selectedOption.Value;
64
+ else
65
+ record[props.Field] = null;
66
+ props.Setter(record);
67
+ }
68
+ // Effect for initial setup and event listeners.
69
+ React.useEffect(function () {
70
+ setGuid((0, helper_functions_1.CreateGuid)());
71
+ document.addEventListener('mousedown', HandleShow, false);
72
+ return function () {
73
+ document.removeEventListener('mousedown', HandleShow, false);
74
+ };
75
+ }, []);
76
+ // Effect to handle changes to the record's field value.
77
+ React.useEffect(function () {
78
+ var element = props.Options.find(function (e) { return (0, lodash_1.isEqual)(e.Value, props.Record[props.Field]); });
79
+ setSelected(element !== undefined ? element.Element : React.createElement("div", null));
80
+ }, [props.Record, props.Options]);
81
+ return (React.createElement("div", { ref: stylableSelect, style: { position: 'absolute', display: 'inline-block', width: 'inherit' } },
82
+ (props.Label !== "") ?
83
+ React.createElement("label", null,
84
+ props.Label === undefined ? props.Field : props.Label,
85
+ props.Help !== undefined ? 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,
86
+ props.Help !== undefined ?
87
+ React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
88
+ : null,
89
+ React.createElement("button", { type: "button", style: { border: '1px solid #ced4da', padding: '.375rem .75rem', fontSize: '1rem', borderRadius: '.25rem' }, "data-help": guid, className: "btn form-control dropdown-toggle", onClick: HandleShow, disabled: props.Disabled === undefined ? false : props.Disabled },
90
+ React.createElement("div", { style: props.Style }, selected)),
91
+ React.createElement("div", { style: {
92
+ maxHeight: window.innerHeight * 0.75,
93
+ overflowY: 'auto',
94
+ padding: '10 5',
95
+ display: show ? 'block' : 'none',
96
+ position: 'absolute',
97
+ backgroundColor: '#fff',
98
+ boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
99
+ zIndex: 401,
100
+ minWidth: '100%',
101
+ } },
102
+ React.createElement("table", { className: "table", style: { margin: 0 } },
103
+ React.createElement("tbody", null, props.Options.map(function (f, i) { return (f.Value == props.Record[props.Field] ? null :
104
+ React.createElement("tr", { key: i, onClick: function (evt) { evt.preventDefault(); SetRecord(f); setShow(false); } },
105
+ React.createElement("td", null, f.Element))); }))))));
106
+ }
package/lib/TextArea.d.ts CHANGED
@@ -1,14 +1,54 @@
1
- /// <reference types="react" />
2
- interface IProps<T> {
3
- Rows: number;
4
- Record: T;
5
- Field: keyof T;
6
- Setter: (record: T) => void;
7
- Valid: (field: keyof T) => boolean;
8
- Label?: string;
9
- Feedback?: string;
10
- Disabled?: boolean;
11
- Help?: string | JSX.Element;
12
- }
13
- export default function TextArea<T>(props: IProps<T>): JSX.Element;
14
- export {};
1
+ interface IProps<T> {
2
+ /**
3
+ * Number of rows for the textarea
4
+ * @type {number}
5
+ */
6
+ Rows: number;
7
+ /**
8
+ * Record to be used in the 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
+ * Function to determine the validity of a field
24
+ * @param field - Field of the record to check
25
+ * @returns {boolean}
26
+ */
27
+ Valid: (field: keyof T) => boolean;
28
+ /**
29
+ * Label to display for the form, defaults to the Field prop
30
+ * @type {string}
31
+ * @optional
32
+ */
33
+ Label?: string;
34
+ /**
35
+ * Feedback message to show when input is invalid
36
+ * @type {string}
37
+ * @optional
38
+ */
39
+ Feedback?: 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
+ export default function TextArea<T>(props: IProps<T>): JSX.Element;
54
+ export {};