@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.
- package/lib/ArrayCheckBoxes.d.ts +33 -11
- package/lib/ArrayCheckBoxes.js +81 -79
- package/lib/ArrayMultiSelect.d.ts +47 -13
- package/lib/ArrayMultiSelect.js +49 -47
- package/lib/CheckBox.d.ts +37 -11
- package/lib/CheckBox.js +62 -60
- package/lib/ColorPicker.d.ts +59 -15
- package/lib/ColorPicker.js +114 -114
- package/lib/DatePicker.d.ts +23 -21
- package/lib/DatePicker.js +221 -214
- package/lib/DateRangePicker.d.ts +64 -13
- package/lib/DateRangePicker.js +143 -132
- package/lib/DateTimeUI/Calender.d.ts +7 -8
- package/lib/DateTimeUI/Calender.js +180 -180
- package/lib/DateTimeUI/Clock.d.ts +9 -10
- package/lib/DateTimeUI/Clock.js +153 -153
- package/lib/DateTimeUI/DateTimePopup.d.ts +16 -17
- package/lib/DateTimeUI/DateTimePopup.js +59 -59
- package/lib/DoubleInput.d.ts +58 -12
- package/lib/DoubleInput.js +55 -51
- package/lib/EnumCheckBoxes.d.ts +41 -9
- package/lib/EnumCheckBoxes.js +65 -58
- package/lib/HelperMessage.d.ts +37 -10
- package/lib/HelperMessage.js +93 -83
- package/lib/Input.d.ts +80 -18
- package/lib/Input.js +111 -106
- package/lib/InputWithButton.d.ts +109 -23
- package/lib/InputWithButton.js +107 -107
- package/lib/MutliCheckBoxSelect.d.ts +42 -18
- package/lib/MutliCheckBoxSelect.js +110 -104
- package/lib/RadioButtons.d.ts +15 -0
- package/lib/RadioButtons.js +62 -0
- package/lib/SearchableSelect.d.ts +60 -18
- package/lib/SearchableSelect.js +84 -85
- package/lib/Select.d.ts +57 -17
- package/lib/Select.js +84 -80
- package/lib/StylableSelect.d.ts +53 -17
- package/lib/StylableSelect.js +106 -101
- package/lib/TextArea.d.ts +54 -14
- package/lib/TextArea.js +76 -72
- package/lib/TimePicker.d.ts +50 -11
- package/lib/TimePicker.js +60 -51
- package/lib/ToggleSwitch.d.ts +44 -12
- package/lib/ToggleSwitch.js +57 -61
- package/lib/index.d.ts +19 -18
- package/lib/index.js +61 -59
- package/package.json +6 -5
package/lib/Select.d.ts
CHANGED
|
@@ -1,17 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
React.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
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
|
+
}
|
package/lib/StylableSelect.d.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 {};
|
package/lib/StylableSelect.js
CHANGED
|
@@ -1,101 +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
|
-
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 {};
|