@gpa-gemstone/react-forms 1.1.60 → 1.1.62

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 +6 -5
@@ -1,51 +1,55 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // DoubleInput.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/07/2021 - C. Lackner
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
- function DoubleInput(props) {
38
- return (React.createElement("div", { className: "form-group" },
39
- React.createElement("label", null, props.Label == null ? (props.Field1 + ' ' + props.Field2) : props.Label),
40
- React.createElement("div", { className: "input-group" },
41
- React.createElement("input", { type: props.Type === undefined ? 'text' : props.Type, className: props.Valid(props.Field1) ? 'form-control' : 'form-control is-invalid', onChange: function (evt) {
42
- var _a;
43
- return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field1] = evt.target.value !== '' ? evt.target.value : null, _a)));
44
- }, value: props.Record[props.Field1] == null ? '' : props.Record[props.Field1].toString(), disabled: props.Disabled == null ? false : props.Disabled }),
45
- React.createElement("input", { type: props.Type === undefined ? 'text' : props.Type, className: props.Valid(props.Field2) ? 'form-control' : 'form-control is-invalid', onChange: function (evt) {
46
- var _a;
47
- return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field2] = evt.target.value !== '' ? evt.target.value : null, _a)));
48
- }, value: props.Record[props.Field2] == null ? '' : props.Record[props.Field2].toString(), disabled: props.Disabled == null ? false : props.Disabled })),
49
- React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? (props.Field1 + ' ' + props.Field2 + ' is a required field.') : props.Feedback)));
50
- }
51
- exports.default = DoubleInput;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // DoubleInput.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/07/2021 - C. Lackner
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 = DoubleInput;
37
+ var React = require("react");
38
+ /**
39
+ * DoubleInput Component.
40
+ * A component that renders two input fields, allowing input for two related fields in a single record.
41
+ */
42
+ function DoubleInput(props) {
43
+ return (React.createElement("div", { className: "form-group" },
44
+ React.createElement("label", null, props.Label == null ? (props.Field1 + ' ' + props.Field2) : props.Label),
45
+ React.createElement("div", { className: "input-group" },
46
+ React.createElement("input", { type: props.Type === undefined ? 'text' : props.Type, className: props.Valid(props.Field1) ? 'form-control' : 'form-control is-invalid', onChange: function (evt) {
47
+ var _a;
48
+ return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field1] = evt.target.value !== '' ? evt.target.value : null, _a)));
49
+ }, value: props.Record[props.Field1] == null ? '' : props.Record[props.Field1].toString(), disabled: props.Disabled == null ? false : props.Disabled }),
50
+ React.createElement("input", { type: props.Type === undefined ? 'text' : props.Type, className: props.Valid(props.Field2) ? 'form-control' : 'form-control is-invalid', onChange: function (evt) {
51
+ var _a;
52
+ return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field2] = evt.target.value !== '' ? evt.target.value : null, _a)));
53
+ }, value: props.Record[props.Field2] == null ? '' : props.Record[props.Field2].toString(), disabled: props.Disabled == null ? false : props.Disabled })),
54
+ React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? (props.Field1 + ' ' + props.Field2 + ' is a required field.') : props.Feedback)));
55
+ }
@@ -1,9 +1,41 @@
1
- /// <reference types="react" />
2
- export default function EnumCheckBoxes<T>(props: {
3
- Record: T;
4
- Field: keyof T;
5
- Setter: (record: T) => void;
6
- Enum: string[];
7
- Label?: string;
8
- IsDisabled?: (item: string) => boolean;
9
- }): JSX.Element;
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
+ * Setter function to update the Record
14
+ * @param record - Updated Record
15
+ */
16
+ Setter: (record: T) => void;
17
+ /**
18
+ * Array of enumerable values to create checkboxes for
19
+ * @type {string[]}
20
+ */
21
+ Enum: string[];
22
+ /**
23
+ * Label to display for the form, defaults to the Field prop
24
+ * @type {string}
25
+ * @optional
26
+ */
27
+ Label?: string;
28
+ /**
29
+ * Function to determine if a checkbox should be disabled
30
+ * @param item - The enumeration value
31
+ * @returns {boolean}
32
+ * @optional
33
+ */
34
+ IsDisabled?: (item: string) => boolean;
35
+ }
36
+ /**
37
+ * EnumCheckBoxes Component.
38
+ * Renders a set of checkboxes based on an enumeration, allowing multiple selection.
39
+ */
40
+ export default function EnumCheckBoxes<T>(props: IProps<T>): JSX.Element;
41
+ export {};
@@ -1,58 +1,65 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // EnumCheckBoxes.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/22/2020 - Billy Ernest
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
- function EnumCheckBoxes(props) {
38
- /* tslint:disable-next-line:no-bitwise */
39
- var EquateFlag = function (index) { return ((props.Record[props.Field] / Math.pow(2, index)) & 1) !== 0; };
40
- var DecrementFlag = function (index) { return props.Record[props.Field] - Math.pow(2, index); };
41
- var IncrementFlag = function (index) { return props.Record[props.Field] + Math.pow(2, index); };
42
- return (React.createElement("div", { className: "form-group" },
43
- React.createElement("label", null, props.Label == null ? props.Field : props.Label),
44
- React.createElement("br", null),
45
- React.createElement("div", { className: "form-check form-check-inline" },
46
- React.createElement("input", { className: "form-check-input", type: "checkbox", checked: props.Record[props.Field] === (Math.pow(2, props.Enum.length) - 1), onChange: function (evt) {
47
- var _a;
48
- return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = evt.target.checked ? Math.pow(2, props.Enum.length) - 1 : 0, _a)));
49
- } }),
50
- React.createElement("label", { className: "form-check-label" }, "All")),
51
- props.Enum.map(function (flag, i) { return (React.createElement("div", { key: i, className: "form-check form-check-inline" },
52
- React.createElement("input", { className: "form-check-input", type: "checkbox", checked: EquateFlag(i), disabled: props.IsDisabled !== undefined ? props.IsDisabled(flag) : false, onChange: function (evt) {
53
- var _a;
54
- return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = evt.target.checked ? IncrementFlag(i) : DecrementFlag(i), _a)));
55
- } }),
56
- React.createElement("label", { className: "form-check-label" }, flag))); })));
57
- }
58
- exports.default = EnumCheckBoxes;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // EnumCheckBoxes.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/22/2020 - Billy Ernest
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 = EnumCheckBoxes;
37
+ var React = require("react");
38
+ /**
39
+ * EnumCheckBoxes Component.
40
+ * Renders a set of checkboxes based on an enumeration, allowing multiple selection.
41
+ */
42
+ function EnumCheckBoxes(props) {
43
+ // Determine if an enum flag is set.
44
+ /* tslint:disable-next-line:no-bitwise */
45
+ var EquateFlag = function (index) { return ((props.Record[props.Field] / Math.pow(2, index)) & 1) !== 0; };
46
+ // Turn off a flag in the enumeration.
47
+ var DecrementFlag = function (index) { return props.Record[props.Field] - Math.pow(2, index); };
48
+ // Turn on a flag in the enumeration.
49
+ var IncrementFlag = function (index) { return props.Record[props.Field] + Math.pow(2, index); };
50
+ return (React.createElement("div", { className: "form-group" },
51
+ React.createElement("label", null, props.Label == null ? props.Field : props.Label),
52
+ React.createElement("br", null),
53
+ React.createElement("div", { className: "form-check form-check-inline" },
54
+ React.createElement("input", { className: "form-check-input", type: "checkbox", checked: props.Record[props.Field] === (Math.pow(2, props.Enum.length) - 1), onChange: function (evt) {
55
+ var _a;
56
+ return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = evt.target.checked ? Math.pow(2, props.Enum.length) - 1 : 0, _a)));
57
+ } }),
58
+ React.createElement("label", { className: "form-check-label" }, "All")),
59
+ props.Enum.map(function (flag, i) { return (React.createElement("div", { key: i, className: "form-check form-check-inline" },
60
+ React.createElement("input", { className: "form-check-input", type: "checkbox", checked: EquateFlag(i), disabled: props.IsDisabled !== undefined ? props.IsDisabled(flag) : false, onChange: function (evt) {
61
+ var _a;
62
+ return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = evt.target.checked ? IncrementFlag(i) : DecrementFlag(i), _a)));
63
+ } }),
64
+ React.createElement("label", { className: "form-check-label" }, flag))); })));
65
+ }
@@ -1,10 +1,37 @@
1
- import * as React from 'react';
2
- interface IProps {
3
- Show: boolean;
4
- Target?: string;
5
- Zindex?: number;
6
- Color?: string;
7
- Background?: string;
8
- }
9
- declare const HelperMessage: React.FunctionComponent<IProps>;
10
- export default HelperMessage;
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ /**
4
+ * Flag to show the helper message
5
+ * @type {boolean}
6
+ */
7
+ Show: boolean;
8
+ /**
9
+ * Value of the target element's data-help attribute
10
+ * @type {string}
11
+ * @optional
12
+ */
13
+ Target?: string;
14
+ /**
15
+ * z-index for the helper message
16
+ * @type {number}
17
+ */
18
+ Zindex?: number;
19
+ /**
20
+ * Text color for the helper message
21
+ * @type {string}
22
+ * @optional
23
+ */
24
+ Color?: string;
25
+ /**
26
+ * Background color for the helper message
27
+ * @type {string}
28
+ * @optional
29
+ */
30
+ Background?: string;
31
+ }
32
+ /**
33
+ * HelperMessage Component.
34
+ * Displays a floating message box.
35
+ */
36
+ declare const HelperMessage: React.FunctionComponent<IProps>;
37
+ export default HelperMessage;
@@ -1,83 +1,93 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // HelperMessage.tsx - Gbtc
4
- //
5
- // Copyright © 2021, 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
- // 05/05/2021 - 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
- Object.defineProperty(exports, "__esModule", { value: true });
29
- var React = require("react");
30
- var styled_components_1 = require("styled-components");
31
- var helper_functions_1 = require("@gpa-gemstone/helper-functions");
32
- var react_portal_1 = require("react-portal");
33
- var WrapperDiv = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px 21px;\n position: fixed;\n pointer-events: none;\n transition: opacity 0.3s ease-out;\n z-index: ", ";\n opacity: ", ";\n color: ", ";;\n background: ", ";\n top: ", ";\n left: ", ";\n width: ", ";\n border: 1px solid transparent;\n }\n \n ", ""], ["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px 21px;\n position: fixed;\n pointer-events: none;\n transition: opacity 0.3s ease-out;\n z-index: ", ";\n opacity: ", ";\n color: ", ";;\n background: ", ";\n top: ", ";\n left: ", ";\n width: ", ";\n border: 1px solid transparent;\n }\n \n ", ""])), function (props) { return props.Zindex; }, function (props) { return props.Show ? "1.0" : "0"; }, function (props) { var _a; return (_a = props.Color) !== null && _a !== void 0 ? _a : '#000'; }, function (props) { var _a; return (_a = props.Background) !== null && _a !== void 0 ? _a : '#0DCAF0'; }, function (props) { return props.Top + "px"; }, function (props) { return props.Left + "px"; }, function (props) { return props.Width + "px"; }, function (props) {
34
- var _a;
35
- return "\n &::before {\n border-left: 8px solid transparent;\n border-right: 8px solid transparent;\n border-bottom: 8px solid " + ((_a = props.Background) !== null && _a !== void 0 ? _a : '#0DCAF0') + ";\n left: 50%;\n top: -6px;\n margin-left: -8px;\n content: \"\";\n width: 0px;\n height: 0px;\n position: absolute\n }\n ";
36
- });
37
- var HelperMessage = function (props) {
38
- var helpMessage = React.useRef(null);
39
- var _a = React.useState(0), top = _a[0], setTop = _a[1];
40
- var _b = React.useState(0), left = _b[0], setLeft = _b[1];
41
- var _c = React.useState(0), width = _c[0], setWidth = _c[1];
42
- var _d = React.useState(0), targetLeft = _d[0], setTargetLeft = _d[1];
43
- var _e = React.useState(0), targetTop = _e[0], setTargetTop = _e[1];
44
- var _f = React.useState(0), targetWidth = _f[0], setTargetWidth = _f[1];
45
- var _g = React.useState(0), targetHeight = _g[0], setTargetHeight = _g[1];
46
- React.useEffect(function () {
47
- var target = document.querySelectorAll("[data-help" + (props.Target === undefined ? '' : "=\"" + props.Target + "\"") + "]");
48
- if (target.length === 0) {
49
- setTargetHeight(0);
50
- setTargetWidth(0);
51
- setTargetLeft(-999);
52
- setTargetTop(-999);
53
- }
54
- else {
55
- var targetLocation = (0, helper_functions_1.GetNodeSize)(target[0]);
56
- setTargetHeight(targetLocation.height);
57
- setTargetWidth(targetLocation.width);
58
- setTargetLeft(targetLocation.left);
59
- setTargetTop(targetLocation.top);
60
- }
61
- }, [props.Show]);
62
- React.useLayoutEffect(function () {
63
- var _a = UpdatePosition(), t = _a[0], l = _a[1], w = _a[2];
64
- setTop(t);
65
- setLeft(l);
66
- setWidth(w);
67
- });
68
- var zIndex = (props.Zindex === undefined ? 9999 : props.Zindex);
69
- function UpdatePosition() {
70
- if (helpMessage.current === null)
71
- return [-999, -999];
72
- var offset = 5;
73
- var result = [0, 0, 0];
74
- result[0] = targetTop + targetHeight + offset;
75
- result[1] = targetLeft;
76
- result[2] = targetWidth;
77
- return result;
78
- }
79
- return (React.createElement(react_portal_1.Portal, null,
80
- React.createElement(WrapperDiv, { Show: props.Show, Top: top, Left: left, Width: width, ref: helpMessage, Zindex: zIndex, Color: props.Color, Background: props.Background }, props.children)));
81
- };
82
- exports.default = HelperMessage;
83
- var templateObject_1;
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // HelperMessage.tsx - Gbtc
4
+ //
5
+ // Copyright © 2021, 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
+ // 05/05/2021 - 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
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ var React = require("react");
30
+ var styled_components_1 = require("styled-components");
31
+ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
32
+ var react_portal_1 = require("react-portal");
33
+ var lodash_1 = require("lodash");
34
+ // Styled component for the wrapper of the helper message.
35
+ var WrapperDiv = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px 21px;\n position: fixed;\n pointer-events: none;\n transition: opacity 0.3s ease-out;\n z-index: ", ";\n opacity: ", ";\n color: ", ";;\n background: ", ";\n top: ", ";\n left: ", ";\n width: ", ";\n border: 1px solid transparent;\n }\n ", ""], ["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px 21px;\n position: fixed;\n pointer-events: none;\n transition: opacity 0.3s ease-out;\n z-index: ", ";\n opacity: ", ";\n color: ", ";;\n background: ", ";\n top: ", ";\n left: ", ";\n width: ", ";\n border: 1px solid transparent;\n }\n ", ""
36
+ /**
37
+ * HelperMessage Component.
38
+ * Displays a floating message box.
39
+ */
40
+ ])), function (props) { return props.Zindex; }, function (props) { return props.Show ? "1.0" : "0"; }, function (props) { var _a; return (_a = props.Color) !== null && _a !== void 0 ? _a : '#000'; }, function (props) { var _a; return (_a = props.Background) !== null && _a !== void 0 ? _a : '#0DCAF0'; }, function (props) { return "".concat(props.Top, "px"); }, function (props) { return "".concat(props.Left, "px"); }, function (props) { return "".concat(props.Width, "px"); }, function (props) {
41
+ var _a;
42
+ return "\n &::before {\n border-left: 8px solid transparent;\n border-right: 8px solid transparent;\n border-bottom: 8px solid ".concat((_a = props.Background) !== null && _a !== void 0 ? _a : '#0DCAF0', ";\n left: ").concat(props.TargetLeft - props.Left + props.TargetWidth / 2, "px;\n top: -6px;\n margin-left: -8px;\n content: \"\";\n width: 0px;\n height: 0px;\n position: absolute\n }\n ");
43
+ });
44
+ /**
45
+ * HelperMessage Component.
46
+ * Displays a floating message box.
47
+ */
48
+ var HelperMessage = function (props) {
49
+ var helpMessage = React.useRef(null);
50
+ // State variables for positioning and sizing the helper message.
51
+ var _a = React.useState(0), top = _a[0], setTop = _a[1];
52
+ var _b = React.useState(0), left = _b[0], setLeft = _b[1];
53
+ // State variables for the target element's position and size.
54
+ var _c = React.useState({ Top: -999, Left: -999, Width: 0, Height: 0 }), targetPosition = _c[0], setTargetPosition = _c[1];
55
+ // Effect for updating the target element's position and size.
56
+ React.useEffect(function () {
57
+ var target = document.querySelectorAll("[data-help".concat(props.Target === undefined ? '' : "=\"".concat(props.Target, "\""), "]"));
58
+ if (target.length === 0) {
59
+ setTargetPosition({ Height: 0, Top: -999, Left: -999, Width: 0 });
60
+ return;
61
+ }
62
+ var targetLocation = (0, helper_functions_1.GetNodeSize)(target[0]);
63
+ var newPosition = { Height: targetLocation.height, Top: targetLocation.top, Left: targetLocation.left, Width: targetLocation.width };
64
+ if (!(0, lodash_1.isEqual)(newPosition, targetPosition))
65
+ setTargetPosition(newPosition);
66
+ }, [props.Show]);
67
+ React.useLayoutEffect(function () {
68
+ var _a = UpdatePosition(helpMessage, targetPosition), t = _a[0], l = _a[1];
69
+ setTop(t);
70
+ setLeft(l);
71
+ }, [targetPosition]);
72
+ var zIndex = (props.Zindex === undefined ? 9999 : props.Zindex);
73
+ return (React.createElement(react_portal_1.Portal, null,
74
+ React.createElement(WrapperDiv, { Show: props.Show, Top: top, Left: left, ref: helpMessage, Zindex: zIndex, Color: props.Color, Background: props.Background, TargetLeft: targetPosition.Left, TargetWidth: targetPosition.Width, Width: targetPosition.Width }, props.children)));
75
+ };
76
+ var UpdatePosition = function (helpMessage, targetPosition) {
77
+ if (helpMessage.current === null)
78
+ return [-999, -999];
79
+ var offset = 5;
80
+ var windowWidth = window.innerWidth;
81
+ var top = targetPosition.Top + targetPosition.Height + offset;
82
+ var left = targetPosition.Left;
83
+ var width = targetPosition.Width;
84
+ // If tooltip goes beyond the right viewport boundary, adjust the left position to fit
85
+ if (left + width >= windowWidth)
86
+ left = windowWidth - width - offset;
87
+ // If tooltip goes beyond the left viewport boundary, adjust the left position to fit
88
+ if (left <= 0)
89
+ left = offset;
90
+ return [top, left, width];
91
+ };
92
+ exports.default = HelperMessage;
93
+ var templateObject_1;
package/lib/Input.d.ts CHANGED
@@ -1,18 +1,80 @@
1
- import * as React from 'react';
2
- interface IProps<T> {
3
- Record: T;
4
- Field: keyof T;
5
- Setter: (record: T) => void;
6
- Valid: (field: keyof T) => boolean;
7
- Label?: string;
8
- Feedback?: string;
9
- Disabled?: boolean;
10
- Type?: 'number' | 'text' | 'password' | 'email' | 'color' | 'integer';
11
- Help?: string | JSX.Element;
12
- Style?: React.CSSProperties;
13
- AllowNull?: boolean;
14
- Size?: 'small' | 'large';
15
- DefaultValue?: number;
16
- }
17
- export default function Input<T>(props: IProps<T>): JSX.Element;
18
- export {};
1
+ import * as React from 'react';
2
+ interface IProps<T> {
3
+ /**
4
+ * Record to be used in form
5
+ * @type {T}
6
+ */
7
+ Record: T;
8
+ /**
9
+ * Field of the record to be edited
10
+ * @type {keyof T}
11
+ */
12
+ Field: keyof T;
13
+ /**
14
+ * Setter function to update the Record
15
+ * @param record - Updated Record
16
+ */
17
+ Setter: (record: T) => void;
18
+ /**
19
+ * Function to determine the validity of a field
20
+ * @param field - Field of the record to check
21
+ * @returns {boolean}
22
+ */
23
+ Valid: (field: keyof T) => boolean;
24
+ /**
25
+ * Label to display for the form, defaults to the Field prop
26
+ * @type {string}
27
+ * @optional
28
+ */
29
+ Label?: string;
30
+ /**
31
+ * Feedback message to show when input is invalid
32
+ * @type {string}
33
+ * @optional
34
+ */
35
+ Feedback?: string;
36
+ /**
37
+ * Flag to disable the input field
38
+ * @type {boolean}
39
+ * @optional
40
+ */
41
+ Disabled?: boolean;
42
+ /**
43
+ * Type of the input field
44
+ * @type {'number' | 'text' | 'password' | 'email' | 'color' | 'integer'}
45
+ * @optional
46
+ */
47
+ Type?: 'number' | 'text' | 'password' | 'email' | 'color' | 'integer';
48
+ /**
49
+ * Help message or element to display
50
+ * @type {string | JSX.Element}
51
+ * @optional
52
+ */
53
+ Help?: string | JSX.Element;
54
+ /**
55
+ * CSS styles to apply to the form group
56
+ * @type {React.CSSProperties}
57
+ * @optional
58
+ */
59
+ Style?: React.CSSProperties;
60
+ /**
61
+ * Flag to allow null values
62
+ * @type {boolean}
63
+ * @optional
64
+ */
65
+ AllowNull?: boolean;
66
+ /**
67
+ * Size of the input field
68
+ * @type {'small' | 'large'}
69
+ * @optional
70
+ */
71
+ Size?: 'small' | 'large';
72
+ /**
73
+ * Default value for the input field if it's null
74
+ * @type {number}
75
+ * @optional
76
+ */
77
+ DefaultValue?: number;
78
+ }
79
+ export default function Input<T>(props: IProps<T>): JSX.Element;
80
+ export {};