@gpa-gemstone/react-forms 1.1.77 → 1.1.79

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.
@@ -1,19 +1,5 @@
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;
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
17
3
  /**
18
4
  * Array of checkboxes with their IDs and labels
19
5
  * @type {{ ID: string; Label: string }[]}
@@ -22,12 +8,6 @@ interface IProps<T> {
22
8
  ID: string;
23
9
  Label: string;
24
10
  }[];
25
- /**
26
- * Label to display for the form, defaults to the Field prop
27
- * @type {string}
28
- * @optional
29
- */
30
- Label?: string;
31
11
  }
32
12
  export default function ArrayCheckBoxes<T>(props: IProps<T>): JSX.Element;
33
13
  export {};
@@ -1,15 +1,6 @@
1
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;
2
+ import { Gemstone } from '@gpa-gemstone/application-typings';
3
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
13
4
  /**
14
5
  * Options for the select dropdown
15
6
  * @type {{ Value: string; Label: string }[]}
@@ -18,23 +9,6 @@ interface IProps<T> {
18
9
  Value: string;
19
10
  Label: string;
20
11
  }[];
21
- /**
22
- * Setter function to update the Record
23
- * @param record - Updated Record
24
- */
25
- Setter: (record: T) => void;
26
- /**
27
- * Label to display for the form, defaults to the Field prop
28
- * @type {string}
29
- * @optional
30
- */
31
- Label?: string;
32
- /**
33
- * Flag to disable the input field
34
- * @type {boolean}
35
- * @optional
36
- */
37
- Disabled?: boolean;
38
12
  /**
39
13
  * CSS styles to apply to the select element
40
14
  * @type {React.CSSProperties}
package/lib/CheckBox.d.ts CHANGED
@@ -1,37 +1,2 @@
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
- * Label to display for the form, defaults to the Field prop
19
- * @type {string}
20
- * @optional
21
- */
22
- Label?: string;
23
- /**
24
- * Flag to disable the input field
25
- * @type {boolean}
26
- * @optional
27
- */
28
- Disabled?: boolean;
29
- /**
30
- * Help message or element to display
31
- * @type {string | JSX.Element}
32
- * @optional
33
- */
34
- Help?: string | JSX.Element;
35
- }
36
- export default function CheckBox<T>(props: IProps<T>): JSX.Element;
37
- export {};
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ export default function CheckBox<T>(props: Gemstone.TSX.Interfaces.IBaseFormProps<T>): JSX.Element;
@@ -1,17 +1,12 @@
1
1
  import * as moment from 'moment';
2
2
  import { Accuracy } from './DateTimeUI/Clock';
3
+ import { Gemstone } from '@gpa-gemstone/application-typings';
3
4
  export type TimeUnit = ('datetime-local' | 'date' | 'time');
4
- interface IProps<T> {
5
- Record: T;
6
- Field: keyof T;
7
- Setter: (record: T) => void;
5
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
8
6
  Valid: (field: keyof T) => boolean;
9
- Label?: string;
10
- Disabled?: boolean;
11
7
  Feedback?: string;
12
8
  Format?: string;
13
9
  Type?: TimeUnit;
14
- Help?: string | JSX.Element;
15
10
  AllowEmpty?: boolean;
16
11
  Accuracy?: Accuracy;
17
12
  MinDate?: moment.Moment;
@@ -1,9 +1,5 @@
1
- interface IProps<T> {
2
- /**
3
- * Record to be used in form
4
- * @type {T}
5
- */
6
- Record: T;
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
7
3
  /**
8
4
  * Field representing the start date in the record
9
5
  * @type {keyof T}
@@ -15,14 +11,8 @@ interface IProps<T> {
15
11
  */
16
12
  ToField: keyof T;
17
13
  /**
18
- * Setter function to update the Record
19
- * @param record - Updated Record
20
- */
21
- Setter: (record: T) => void;
22
- /**
23
- * Label to display for the form, defaults to the Field prop
14
+ * Label to display for the form
24
15
  * @type {string}
25
- * @optional
26
16
  */
27
17
  Label: string;
28
18
  /**
@@ -31,12 +21,6 @@ interface IProps<T> {
31
21
  * @returns {boolean}
32
22
  */
33
23
  Valid: (fieldFrom: keyof T, fieldTo: keyof T) => boolean;
34
- /**
35
- * Flag to disable the input field
36
- * @type {boolean}
37
- * @optional
38
- */
39
- Disabled?: boolean;
40
24
  /**
41
25
  * Feedback message to show when input is invalid
42
26
  * @type {string}
@@ -1,9 +1,5 @@
1
- interface IProps<T> {
2
- /**
3
- * Record to be used in form
4
- * @type {T}
5
- */
6
- Record: T;
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
7
3
  /**
8
4
  * First field of the record to be edited
9
5
  * @type {keyof T}
@@ -15,34 +11,17 @@ interface IProps<T> {
15
11
  */
16
12
  Field2: keyof T;
17
13
  /**
18
- * Setter function to update the Record
19
- * @param record - Updated Record
20
- */
21
- Setter: (record: T) => void;
22
- /**
23
14
  * Function to determine the validity of a field
24
15
  * @param field - Field of the record to check
25
16
  * @returns {boolean}
26
17
  */
27
18
  Valid: (field: keyof T) => boolean;
28
19
  /**
29
- * Label to display for the form, defaults to the Field prop
30
- * @type {string}
31
- * @optional
32
- */
33
- Label?: string;
34
- /**
35
20
  * Feedback message to show when input is invalid
36
21
  * @type {string}
37
22
  * @optional
38
23
  */
39
24
  Feedback?: string;
40
- /**
41
- * Flag to disable the input field
42
- * @type {boolean}
43
- * @optional
44
- */
45
- Disabled?: boolean;
46
25
  /**
47
26
  * Type of the input fields
48
27
  * @type {'number' | 'text' | 'password' | 'email' | 'color'}
@@ -0,0 +1,17 @@
1
+ interface IProps {
2
+ /**
3
+ * Callback function that will be called when a file is uploaded
4
+ * */
5
+ OnLoadHandler: (result: File) => void;
6
+ /**
7
+ * Callback function that will be called when clear button is clicked
8
+ * */
9
+ OnClearHandler: () => void;
10
+ /**
11
+ * Attribute used to control what type of files are filtered by default in file explorer
12
+ * @type {string}
13
+ * */
14
+ FileTypeAttribute: string;
15
+ }
16
+ declare const FileUpload: (props: IProps) => JSX.Element;
17
+ export default FileUpload;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ // ******************************************************************************************************
3
+ // FileUpload.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/01/2025 - Preston Crawford
21
+ // Generated original version of source code.
22
+ //
23
+ // ******************************************************************************************************
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ var React = require("react");
26
+ var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
27
+ var FileUpload = function (props) {
28
+ var _a = React.useState(null), fileName = _a[0], setFileName = _a[1];
29
+ var _b = React.useState(null), fileSize = _b[0], setFileSize = _b[1];
30
+ var _c = React.useState(false), isFileUpload = _c[0], setIsFileUploaded = _c[1];
31
+ var handleFileUpload = function (evt) {
32
+ if (evt.target == null || evt.target.files == null || evt.target.files.length === 0)
33
+ return;
34
+ var file = evt.target.files[0];
35
+ setMetaData(file);
36
+ };
37
+ var handleDrop = function (e) {
38
+ e.preventDefault();
39
+ e.stopPropagation();
40
+ if (e.dataTransfer == null || e.dataTransfer.files == null || e.dataTransfer.files.length === 0)
41
+ return;
42
+ var file = e.dataTransfer.files[0];
43
+ setMetaData(file);
44
+ // Clear drag data after handling
45
+ e.dataTransfer.clearData();
46
+ };
47
+ var handleDragOver = function (e) {
48
+ e.preventDefault();
49
+ e.stopPropagation();
50
+ };
51
+ var handleOnClear = function () {
52
+ setIsFileUploaded(false);
53
+ setFileName(null);
54
+ setFileSize(null);
55
+ props.OnClearHandler();
56
+ };
57
+ var setMetaData = function (file) {
58
+ setFileName(file.name);
59
+ setFileSize(file.size);
60
+ props.OnLoadHandler(file);
61
+ setIsFileUploaded(true);
62
+ };
63
+ return (React.createElement(React.Fragment, null,
64
+ React.createElement("div", { className: 'row' },
65
+ React.createElement("div", { className: 'col-auto mt-2' },
66
+ React.createElement("label", { style: { cursor: 'pointer' } },
67
+ React.createElement(gpa_symbols_1.ReactIcons.ShareArrow, { Color: 'var(--info)' }),
68
+ React.createElement("input", { type: "file", onChange: handleFileUpload, accept: props.FileTypeAttribute, style: { display: 'none' } }))),
69
+ React.createElement("div", { className: 'col-auto' },
70
+ React.createElement("button", { className: 'btn', onClick: handleOnClear },
71
+ React.createElement(gpa_symbols_1.ReactIcons.CircledX, { Color: 'red' })))),
72
+ isFileUpload ?
73
+ React.createElement(React.Fragment, null,
74
+ React.createElement("div", { className: 'row align-items-center justify-content-center', style: { border: '2px dashed var(--secondary)' } },
75
+ React.createElement("div", { className: 'col-auto' },
76
+ "File Name: ", fileName !== null && fileName !== void 0 ? fileName : ''),
77
+ React.createElement("div", { className: 'col-auto' },
78
+ "File Size: ",
79
+ formatFileSize(fileSize))))
80
+ :
81
+ React.createElement("div", { className: 'row', onDragOver: handleDragOver, onDrop: handleDrop, style: { border: '2px dashed var(--secondary)' } },
82
+ React.createElement("div", { className: 'col-12 pt-3 pb-3 d-flex justify-content-center align-items-center' },
83
+ React.createElement(gpa_symbols_1.ReactIcons.Image, { Size: 100 }),
84
+ React.createElement("span", null, "Drag and Drop")))));
85
+ };
86
+ //Helper Functions
87
+ var formatFileSize = function (size) {
88
+ if (size === null)
89
+ return '';
90
+ var units = ['bytes', 'KB', 'MB', 'GB', 'TB'];
91
+ var index = 0;
92
+ var fileSize = size;
93
+ while (fileSize >= 1024 && index < units.length - 1) {
94
+ fileSize /= 1024;
95
+ index++;
96
+ }
97
+ return "".concat(fileSize.toFixed(2), " ").concat(units[index]);
98
+ };
99
+ exports.default = FileUpload;
package/lib/Input.d.ts CHANGED
@@ -1,56 +1,24 @@
1
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;
2
+ import { Gemstone } from '@gpa-gemstone/application-typings';
3
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
18
4
  /**
19
5
  * Function to determine the validity of a field
20
6
  * @param field - Field of the record to check
21
7
  * @returns {boolean}
22
8
  */
23
9
  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
10
  /**
31
11
  * Feedback message to show when input is invalid
32
12
  * @type {string}
33
13
  * @optional
34
14
  */
35
15
  Feedback?: string;
36
- /**
37
- * Flag to disable the input field
38
- * @type {boolean}
39
- * @optional
40
- */
41
- Disabled?: boolean;
42
16
  /**
43
17
  * Type of the input field
44
18
  * @type {'number' | 'text' | 'password' | 'email' | 'color' | 'integer'}
45
19
  * @optional
46
20
  */
47
21
  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
22
  /**
55
23
  * CSS styles to apply to the form group
56
24
  * @type {React.CSSProperties}
@@ -1,32 +1,12 @@
1
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;
2
+ import { Gemstone } from '@gpa-gemstone/application-typings';
3
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
18
4
  /**
19
5
  * Function to determine the validity of a field
20
6
  * @param field - Field of the record to check
21
7
  * @returns {boolean}
22
8
  */
23
9
  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
10
  /**
31
11
  * Feedback message to show when input is invalid
32
12
  * @type {string}
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ import { Gemstone } from '@gpa-gemstone/application-typings';
3
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
4
+ /**
5
+ * Function to determine the validity of a field
6
+ * @param field - Field of the record to check
7
+ * @returns {boolean}
8
+ */
9
+ Valid: (field: keyof T) => boolean;
10
+ /**
11
+ * Type of the input field
12
+ * @type {'number' | 'text' | 'password' | 'email' | 'color' | 'integer'}
13
+ * @optional
14
+ */
15
+ Type?: 'number' | 'text' | 'password' | 'email' | 'color' | 'integer';
16
+ /**
17
+ * CSS styles to apply to the Input component
18
+ * @type {React.CSSProperties}
19
+ * @optional
20
+ */
21
+ Style?: React.CSSProperties;
22
+ /**
23
+ * Default value to use when adding an item and when value is null
24
+ * @type {number}
25
+ */
26
+ DefaultValue: number | string;
27
+ /**
28
+ * Flag to allow null values
29
+ * @type {boolean}
30
+ * @optional
31
+ */
32
+ AllowNull?: boolean;
33
+ /**
34
+ * Feedback message to show when input is invalid
35
+ * @type {string}
36
+ * @optional
37
+ */
38
+ Feedback?: string;
39
+ }
40
+ declare function MultiInput<T>(props: IProps<T>): JSX.Element;
41
+ export default MultiInput;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ //******************************************************************************************************
3
+ // MultiInput.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 may license 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
+ // 12/05/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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
37
+ if (ar || !(i in from)) {
38
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
39
+ ar[i] = from[i];
40
+ }
41
+ }
42
+ return to.concat(ar || Array.prototype.slice.call(from));
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ var React = require("react");
46
+ var Input_1 = require("./Input");
47
+ var HelperMessage_1 = require("./HelperMessage");
48
+ var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
49
+ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
50
+ //Only supporting string/number arrays for now
51
+ function MultiInput(props) {
52
+ var _a;
53
+ var guid = React.useRef((0, helper_functions_1.CreateGuid)());
54
+ var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
55
+ var fieldArray = props.Record[props.Field];
56
+ if ((fieldArray === null || fieldArray === void 0 ? void 0 : fieldArray.constructor) !== Array) {
57
+ console.warn("MultiInput: ".concat(props.Field.toString(), " is not of type array."));
58
+ return React.createElement(React.Fragment, null);
59
+ }
60
+ return (React.createElement(React.Fragment, null,
61
+ fieldArray.length === 0 ?
62
+ React.createElement(React.Fragment, null,
63
+ React.createElement("label", { className: 'd-flex align-items-center', "data-help": guid.current }, (_a = props.Label) !== null && _a !== void 0 ? _a : props.Field,
64
+ props.Help != null ?
65
+ React.createElement("button", { className: 'btn mb-1 pt-0 pb-0', onMouseEnter: function () { return setShowHelp(true); }, onMouseLeave: function () { return setShowHelp(false); } },
66
+ React.createElement(gpa_symbols_1.ReactIcons.QuestionMark, { Color: 'var(--info)', Size: 20 }))
67
+ : null,
68
+ React.createElement("button", { className: 'btn', onClick: function () {
69
+ var _a;
70
+ return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = [props.DefaultValue], _a)));
71
+ } },
72
+ " ",
73
+ React.createElement(gpa_symbols_1.ReactIcons.CirclePlus, null),
74
+ " ")),
75
+ React.createElement(HelperMessage_1.default, { Show: showHelp && props.Help != null, Target: guid.current }, props.Help))
76
+ : null,
77
+ fieldArray.map(function (r, index) {
78
+ var _a, _b;
79
+ return (React.createElement("div", { className: 'row align-items-center', key: index },
80
+ React.createElement("div", { className: 'col' },
81
+ React.createElement(Input_1.default, { Record: fieldArray, Field: index, Label: index === 0 ? props.Label : '', AllowNull: props.AllowNull, Type: props.Type, Help: index === 0 ? props.Help : undefined, Feedback: props.Feedback, Valid: function () { return props.Valid(props.Field); }, Style: props.Style, Disabled: props.Disabled, Setter: function (record) {
82
+ var _a;
83
+ var _b;
84
+ var newArray = __spreadArray([], fieldArray, true);
85
+ if (!((_b = props.AllowNull) !== null && _b !== void 0 ? _b : true) && record[index] === null)
86
+ newArray[index] = props.DefaultValue;
87
+ else
88
+ newArray[index] = record[index];
89
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newArray, _a)));
90
+ } })),
91
+ React.createElement("div", { className: 'col-auto' },
92
+ React.createElement("button", { className: 'btn', style: ((_a = props.Disabled) !== null && _a !== void 0 ? _a : false) ? { display: 'none' } : undefined, onClick: function () {
93
+ var _a;
94
+ var newRecords = __spreadArray([], fieldArray, true).filter(function (_, i) { return i !== index; });
95
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newRecords, _a)));
96
+ } },
97
+ React.createElement(gpa_symbols_1.ReactIcons.TrashCan, { Color: 'red' }))),
98
+ index === __spreadArray([], fieldArray, true).length - 1 ?
99
+ React.createElement("div", { className: 'col-auto' },
100
+ React.createElement("button", { className: 'btn', style: ((_b = props.Disabled) !== null && _b !== void 0 ? _b : false) ? { display: 'none' } : undefined, onClick: function () {
101
+ var _a;
102
+ var newRecords = __spreadArray(__spreadArray([], __spreadArray([], fieldArray, true), true), [props.DefaultValue], false);
103
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newRecords, _a)));
104
+ } },
105
+ React.createElement(gpa_symbols_1.ReactIcons.CirclePlus, null)))
106
+ : null));
107
+ })));
108
+ }
109
+ exports.default = MultiInput;
@@ -1,25 +1,5 @@
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
- * Help message or element to display
19
- * @type {string | JSX.Element}
20
- * @optional
21
- */
22
- Help?: string | JSX.Element;
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
23
3
  /**
24
4
  * Position to display radion buttons in
25
5
  * @type {'vertical' | 'horizontal'}
@@ -35,12 +15,6 @@ interface IProps<T> {
35
15
  Label: string;
36
16
  Disabled?: boolean;
37
17
  }[];
38
- /**
39
- * Label to display for the form, defaults to the Field prop
40
- * @type {string}
41
- * @optional
42
- */
43
- Label?: string;
44
18
  }
45
19
  export default function RadioButtons<T>(props: IProps<T>): JSX.Element;
46
20
  export {};
@@ -1,24 +1,10 @@
1
1
  import * as React from 'react';
2
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
3
  interface IOption {
3
4
  Value: string;
4
5
  Label: string;
5
6
  }
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;
7
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
22
8
  /**
23
9
  * Flag to allow custom input values
24
10
  * @type {boolean}
@@ -30,25 +16,7 @@ interface IProps<T> {
30
16
  * @param search - Search string
31
17
  * @returns {[promise: Promise<IOption[]>, callback?: () => void]}
32
18
  */
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;
19
+ Search: (search: string) => [Promise<IOption[]>, () => void];
52
20
  /**
53
21
  * CSS styles to apply to the form group
54
22
  * @type {React.CSSProperties}
@@ -59,9 +27,13 @@ interface IProps<T> {
59
27
  * CSS style to apply to the button holding the selected value
60
28
  * @type {React.CSSProperties}
61
29
  * @optional
62
- *
63
30
  */
64
31
  BtnStyle?: React.CSSProperties;
32
+ /**
33
+ * Custom label to display instead of the default record[field] value. Useful when having a field like an ID.
34
+ * @type {string}
35
+ * @optional
36
+ */
65
37
  SearchLabel?: string;
66
38
  }
67
39
  export default function SearchableSelect<T>(props: IProps<T>): JSX.Element;
@@ -38,46 +38,52 @@ var React = require("react");
38
38
  var StylableSelect_1 = require("./StylableSelect");
39
39
  var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
40
40
  function SearchableSelect(props) {
41
- var _a, _b, _c;
42
- var _d = React.useState((_c = (_b = ((_a = props.SearchLabel) !== null && _a !== void 0 ? _a : props.Record[props.Field])) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : ''), search = _d[0], setSearch = _d[1];
43
- var _e = React.useState([]), results = _e[0], setResults = _e[1];
44
- var _f = React.useState(false), loading = _f[0], setLoading = _f[1];
41
+ var _a;
42
+ var _b = React.useState(((_a = props.SearchLabel) !== null && _a !== void 0 ? _a : props.Record[props.Field]).toString()), search = _b[0], setSearch = _b[1];
43
+ var _c = React.useState([]), results = _c[0], setResults = _c[1];
44
+ var _d = React.useState(false), loading = _d[0], setLoading = _d[1];
45
45
  React.useEffect(function () {
46
46
  setLoading(true);
47
- var _a = props.Search(search), h = _a[0], c = _a[1];
48
- h.then(function (d) {
47
+ var _a = props.Search(search), handle = _a[0], callback = _a[1];
48
+ handle.then(function (d) {
49
49
  setResults(d.map(function (o) { return ({ Value: o.Value, Element: React.createElement("p", null, o.Label) }); }));
50
50
  setLoading(false);
51
51
  });
52
- return c;
52
+ return callback;
53
53
  }, [search]);
54
54
  React.useEffect(function () {
55
55
  if (props.SearchLabel == null)
56
56
  return;
57
57
  setSearch(props.SearchLabel);
58
58
  }, [props.SearchLabel]);
59
+ var handleOnBlur = React.useCallback(function () {
60
+ var _a;
61
+ var _b;
62
+ if ((_b = props.AllowCustom) !== null && _b !== void 0 ? _b : false)
63
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = search, _a)));
64
+ else
65
+ setSearch(props.Record[props.Field].toString());
66
+ }, [props.AllowCustom, props.Record, props.Field, search]);
59
67
  var options = React.useMemo(function () {
60
- var _a, _b, _c, _d;
68
+ var _a, _b, _c;
61
69
  var ops = [];
62
70
  ops.push({
63
- Value: props.Record[props.Field], Element: React.createElement("div", { className: 'input-group' },
64
- React.createElement("input", { type: "text", className: "form-control", value: search, onChange: function (d) { return setSearch(d.target.value); }, onBlur: (((_a = props.AllowCustom) !== null && _a !== void 0 ? _a : false) ? function () {
65
- var _a;
66
- return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = search, _a)));
67
- } : function () { var _a; return setSearch((_a = props.SearchLabel) !== null && _a !== void 0 ? _a : props.Record[props.Field].toString()); }) }),
71
+ Value: props.Record[props.Field],
72
+ Element: React.createElement("div", { className: 'input-group' },
73
+ React.createElement("input", { type: "text", className: "form-control", value: search, onChange: function (d) { return setSearch(d.target.value); }, onBlur: handleOnBlur }),
68
74
  loading ?
69
75
  React.createElement("div", { className: "input-group-append" },
70
76
  React.createElement("span", { className: "input-group-text" },
71
77
  React.createElement(gpa_symbols_1.ReactIcons.SpiningIcon, null)))
72
78
  : null)
73
79
  });
74
- if (!((_b = props.AllowCustom) !== null && _b !== void 0 ? _b : false))
75
- ops.push({ Value: 'search-' + props.Record[props.Field], Element: React.createElement("p", null, (_c = props.SearchLabel) !== null && _c !== void 0 ? _c : props.Record[props.Field]) });
76
- if ((_d = props.AllowCustom) !== null && _d !== void 0 ? _d : false)
80
+ if (!((_a = props.AllowCustom) !== null && _a !== void 0 ? _a : false))
81
+ ops.push({ Value: 'search-' + props.Record[props.Field], Element: React.createElement("p", null, (_b = props.SearchLabel) !== null && _b !== void 0 ? _b : props.Record[props.Field]) });
82
+ if ((_c = props.AllowCustom) !== null && _c !== void 0 ? _c : false)
77
83
  ops.push({ Value: search, Element: React.createElement("p", null, search) });
78
84
  ops.push.apply(ops, results.filter(function (f) { return f.Value !== search && f.Value !== props.Record[props.Field]; }));
79
85
  return ops;
80
- }, [search, props.Record[props.Field], props.Disabled, loading, props.SearchLabel, results]);
86
+ }, [search, props.Record[props.Field], results, props.Disabled, loading, props.SearchLabel, props.AllowCustom]);
81
87
  var update = React.useCallback(function (record) {
82
88
  var _a;
83
89
  var _b, _c;
package/lib/Select.d.ts CHANGED
@@ -1,14 +1,5 @@
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;
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
12
3
  /**
13
4
  * Options for the select dropdown
14
5
  * @type {{ Value: string; Label: string }[]}
@@ -17,23 +8,6 @@ interface IProps<T> {
17
8
  Value: string | number;
18
9
  Label: string;
19
10
  }[];
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
11
  /**
38
12
  * Flag to include an empty option in the select dropdown
39
13
  * @type {boolean}
@@ -46,12 +20,6 @@ interface IProps<T> {
46
20
  * @optional
47
21
  */
48
22
  EmptyLabel?: string;
49
- /**
50
- * Help message or element to display
51
- * @type {string | JSX.Element}
52
- * @optional
53
- */
54
- Help?: string | JSX.Element;
55
23
  }
56
24
  export default function Select<T>(props: IProps<T>): JSX.Element;
57
25
  export {};
@@ -1,47 +1,15 @@
1
1
  import * as React from 'react';
2
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
3
  export interface IOption {
3
4
  Value: any;
4
5
  Element: React.ReactElement<any>;
5
6
  }
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;
7
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
22
8
  /**
23
9
  * Options for the select dropdown
24
10
  * @type {{ Value: any, Element: React.ReactElement<any> }[]}
25
11
  */
26
12
  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
13
  /**
46
14
  * CSS styles to apply to the selected value
47
15
  * @type {React.CSSProperties}
@@ -145,6 +145,6 @@ function StylableSelect(props) {
145
145
  } },
146
146
  React.createElement("table", { className: "table table-hover", style: { margin: 0 }, ref: selectTable },
147
147
  React.createElement("tbody", null, props.Options.map(function (f, i) { return (f.Value === props.Record[props.Field] ? null :
148
- React.createElement("tr", { key: i, onClick: function (evt) { return handleOptionClick(evt, f); } },
148
+ React.createElement("tr", { key: i, onMouseDown: function (evt) { return handleOptionClick(evt, f); } },
149
149
  React.createElement("td", null, f.Element))); })))))));
150
150
  }
package/lib/TextArea.d.ts CHANGED
@@ -1,48 +1,22 @@
1
- interface IProps<T> {
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
2
3
  /**
3
4
  * Number of rows for the textarea
4
5
  * @type {number}
5
6
  */
6
7
  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
8
  /**
23
9
  * Function to determine the validity of a field
24
10
  * @param field - Field of the record to check
25
11
  * @returns {boolean}
26
12
  */
27
13
  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
14
  /**
35
15
  * Feedback message to show when input is invalid
36
16
  * @type {string}
37
17
  * @optional
38
18
  */
39
19
  Feedback?: string;
40
- /**
41
- * Flag to disable the input field
42
- * @type {boolean}
43
- * @optional
44
- */
45
- Disabled?: boolean;
46
20
  /**
47
21
  * Help message or element to display
48
22
  * @type {string | JSX.Element}
@@ -1,37 +1,11 @@
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;
1
+ import { Gemstone } from '@gpa-gemstone/application-typings';
2
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
17
3
  /**
18
4
  * Function to determine the validity of a field
19
5
  * @param field - Field of the record to check
20
6
  * @returns {boolean}
21
7
  */
22
8
  Valid: (field: keyof T) => boolean;
23
- /**
24
- * Label to display for the form, defaults to the Field prop
25
- * @type {string}
26
- * @optional
27
- */
28
- Label?: string;
29
- /**
30
- * Flag to disable the input field
31
- * @type {boolean}
32
- * @optional
33
- */
34
- Disabled?: boolean;
35
9
  /**
36
10
  * Feedback message to show when input is invalid
37
11
  * @type {string}
@@ -44,7 +18,6 @@ interface IProps<T> {
44
18
  * @optional
45
19
  */
46
20
  Step?: number;
47
- Help?: string | JSX.Element;
48
21
  }
49
22
  export default function DatePicker<T>(props: IProps<T>): JSX.Element;
50
23
  export {};
@@ -1,38 +1,6 @@
1
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
- * Label to display for the form, defaults to the Field prop
20
- * @type {string}
21
- * @optional
22
- */
23
- Label?: string;
24
- /**
25
- * Flag to disable the input field
26
- * @type {boolean}
27
- * @optional
28
- */
29
- Disabled?: boolean;
30
- /**
31
- * Help message or element to display
32
- * @type {string | JSX.Element}
33
- * @optional
34
- */
35
- Help?: string | JSX.Element;
2
+ import { Gemstone } from '@gpa-gemstone/application-typings';
3
+ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
36
4
  /**
37
5
  * CSS styles to apply to the form group
38
6
  * @type {React.CSSProperties}
package/lib/index.d.ts CHANGED
@@ -16,4 +16,6 @@ import SearchableSelect from './SearchableSelect';
16
16
  import ToggleSwitch from './ToggleSwitch';
17
17
  import InputWithButton from './InputWithButton';
18
18
  import RadioButtons from './RadioButtons';
19
- export { CheckBox, Input, DatePicker, Select, TextArea, DateRangePicker, EnumCheckBoxes, ArrayMultiSelect, ArrayCheckBoxes, MultiCheckBoxSelect, DoubleInput, TimePicker, StylableSelect, ColorPicker, SearchableSelect, ToggleSwitch, InputWithButton, RadioButtons };
19
+ import FileUpload from './FileUpload';
20
+ import MultiInput from './MultiInput';
21
+ export { CheckBox, Input, DatePicker, Select, TextArea, DateRangePicker, EnumCheckBoxes, ArrayMultiSelect, ArrayCheckBoxes, MultiCheckBoxSelect, DoubleInput, TimePicker, StylableSelect, ColorPicker, SearchableSelect, ToggleSwitch, InputWithButton, RadioButtons, FileUpload, MultiInput };
package/lib/index.js CHANGED
@@ -22,7 +22,7 @@
22
22
  //
23
23
  // ******************************************************************************************************
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.RadioButtons = exports.InputWithButton = exports.ToggleSwitch = exports.SearchableSelect = exports.ColorPicker = exports.StylableSelect = exports.TimePicker = exports.DoubleInput = exports.MultiCheckBoxSelect = exports.ArrayCheckBoxes = exports.ArrayMultiSelect = exports.EnumCheckBoxes = exports.DateRangePicker = exports.TextArea = exports.Select = exports.DatePicker = exports.Input = exports.CheckBox = void 0;
25
+ exports.MultiInput = exports.FileUpload = exports.RadioButtons = exports.InputWithButton = exports.ToggleSwitch = exports.SearchableSelect = exports.ColorPicker = exports.StylableSelect = exports.TimePicker = exports.DoubleInput = exports.MultiCheckBoxSelect = exports.ArrayCheckBoxes = exports.ArrayMultiSelect = exports.EnumCheckBoxes = exports.DateRangePicker = exports.TextArea = exports.Select = exports.DatePicker = exports.Input = exports.CheckBox = void 0;
26
26
  var CheckBox_1 = require("./CheckBox");
27
27
  exports.CheckBox = CheckBox_1.default;
28
28
  var Input_1 = require("./Input");
@@ -59,3 +59,7 @@ var InputWithButton_1 = require("./InputWithButton");
59
59
  exports.InputWithButton = InputWithButton_1.default;
60
60
  var RadioButtons_1 = require("./RadioButtons");
61
61
  exports.RadioButtons = RadioButtons_1.default;
62
+ var FileUpload_1 = require("./FileUpload");
63
+ exports.FileUpload = FileUpload_1.default;
64
+ var MultiInput_1 = require("./MultiInput");
65
+ exports.MultiInput = MultiInput_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.77",
3
+ "version": "1.1.79",
4
4
  "description": "React Form modules for gpa webapps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -45,9 +45,9 @@
45
45
  "typescript": "5.5.3"
46
46
  },
47
47
  "dependencies": {
48
- "@gpa-gemstone/application-typings": "0.0.78",
49
- "@gpa-gemstone/gpa-symbols": "0.0.45",
50
- "@gpa-gemstone/helper-functions": "0.0.36",
48
+ "@gpa-gemstone/application-typings": "0.0.80",
49
+ "@gpa-gemstone/gpa-symbols": "0.0.46",
50
+ "@gpa-gemstone/helper-functions": "0.0.37",
51
51
  "@types/react": "^17.0.14",
52
52
  "@types/styled-components": "^5.1.11",
53
53
  "lodash": "^4.17.21",