@gpa-gemstone/react-forms 1.1.8 → 1.1.13
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/README.md +38 -38
- package/lib/ArrayCheckBoxes.d.ts +11 -11
- package/lib/ArrayCheckBoxes.js +73 -75
- package/lib/ArrayMultiSelect.d.ts +13 -13
- package/lib/ArrayMultiSelect.js +47 -47
- package/lib/CheckBox.d.ts +10 -10
- package/lib/CheckBox.js +69 -67
- package/lib/DatePicker.d.ts +10 -10
- package/lib/DatePicker.js +72 -70
- package/lib/DateRangePicker.d.ts +10 -10
- package/lib/DateRangePicker.js +171 -171
- package/lib/DoubleInput.d.ts +12 -12
- package/lib/DoubleInput.js +51 -51
- package/lib/EnumCheckBoxes.d.ts +8 -8
- package/lib/EnumCheckBoxes.js +58 -58
- package/lib/HelperMessage.d.ts +8 -0
- package/lib/HelperMessage.js +70 -0
- package/lib/Input.d.ts +14 -11
- package/lib/Input.js +60 -46
- package/lib/MutliCheckBoxSelect.d.ts +14 -14
- package/lib/MutliCheckBoxSelect.js +75 -75
- package/lib/Select.d.ts +17 -14
- package/lib/Select.js +65 -51
- package/lib/TextArea.d.ts +11 -11
- package/lib/TextArea.js +50 -50
- package/lib/index.d.ts +11 -11
- package/lib/index.js +45 -45
- package/package.json +57 -54
package/lib/DatePicker.js
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// ******************************************************************************************************
|
|
3
|
-
// DatePicker.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
|
-
// 02/05/2020 - Billy Ernest
|
|
21
|
-
// Generated original version of source code.
|
|
22
|
-
//
|
|
23
|
-
// ******************************************************************************************************
|
|
24
|
-
var __extends = (this && this.__extends) || (function () {
|
|
25
|
-
var extendStatics = function (d, b) {
|
|
26
|
-
extendStatics = Object.setPrototypeOf ||
|
|
27
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
28
|
-
function (d, b) { for (var p in b) if (
|
|
29
|
-
return extendStatics(d, b);
|
|
30
|
-
};
|
|
31
|
-
return function (d, b) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
d
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
record[_this.props.Field] =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// DatePicker.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
|
+
// 02/05/2020 - Billy Ernest
|
|
21
|
+
// Generated original version of source code.
|
|
22
|
+
//
|
|
23
|
+
// ******************************************************************************************************
|
|
24
|
+
var __extends = (this && this.__extends) || (function () {
|
|
25
|
+
var extendStatics = function (d, b) {
|
|
26
|
+
extendStatics = Object.setPrototypeOf ||
|
|
27
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
28
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
29
|
+
return extendStatics(d, b);
|
|
30
|
+
};
|
|
31
|
+
return function (d, b) {
|
|
32
|
+
if (typeof b !== "function" && b !== null)
|
|
33
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
34
|
+
extendStatics(d, b);
|
|
35
|
+
function __() { this.constructor = d; }
|
|
36
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __assign = (this && this.__assign) || function () {
|
|
40
|
+
__assign = Object.assign || function(t) {
|
|
41
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
42
|
+
s = arguments[i];
|
|
43
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
44
|
+
t[p] = s[p];
|
|
45
|
+
}
|
|
46
|
+
return t;
|
|
47
|
+
};
|
|
48
|
+
return __assign.apply(this, arguments);
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
var React = require("react");
|
|
52
|
+
var DatePicker = /** @class */ (function (_super) {
|
|
53
|
+
__extends(DatePicker, _super);
|
|
54
|
+
function DatePicker() {
|
|
55
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
56
|
+
}
|
|
57
|
+
DatePicker.prototype.render = function () {
|
|
58
|
+
var _this = this;
|
|
59
|
+
return (React.createElement("div", { className: "form-group" },
|
|
60
|
+
React.createElement("label", null, this.props.Label == null ? this.props.Field : this.props.Label),
|
|
61
|
+
React.createElement("input", { className: "form-control", type: "date", onChange: function (evt) {
|
|
62
|
+
var record = __assign({}, _this.props.Record);
|
|
63
|
+
if (evt.target.value !== '')
|
|
64
|
+
record[_this.props.Field] = evt.target.value;
|
|
65
|
+
else
|
|
66
|
+
record[_this.props.Field] = null;
|
|
67
|
+
_this.props.Setter(record);
|
|
68
|
+
}, value: this.props.Record[this.props.Field] == null ? '' : this.props.Record[this.props.Field].toString(), disabled: this.props.Disabled == null ? false : this.props.Disabled })));
|
|
69
|
+
};
|
|
70
|
+
return DatePicker;
|
|
71
|
+
}(React.Component));
|
|
72
|
+
exports.default = DatePicker;
|
package/lib/DateRangePicker.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export default function DateRangePicker<T>(props: {
|
|
3
|
-
Record: T;
|
|
4
|
-
FromField: keyof T;
|
|
5
|
-
ToField: keyof T;
|
|
6
|
-
Setter: (record: T) => void;
|
|
7
|
-
Disabled?: boolean;
|
|
8
|
-
Label: string;
|
|
9
|
-
Valid?: boolean;
|
|
10
|
-
}): JSX.Element;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export default function DateRangePicker<T>(props: {
|
|
3
|
+
Record: T;
|
|
4
|
+
FromField: keyof T;
|
|
5
|
+
ToField: keyof T;
|
|
6
|
+
Setter: (record: T) => void;
|
|
7
|
+
Disabled?: boolean;
|
|
8
|
+
Label: string;
|
|
9
|
+
Valid?: boolean;
|
|
10
|
+
}): JSX.Element;
|
package/lib/DateRangePicker.js
CHANGED
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// ******************************************************************************************************
|
|
3
|
-
// DateRangePicker.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
|
-
// 02/05/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 DateRangePicker(props) {
|
|
38
|
-
var _a = React.useState('Custom'), range = _a[0], setRange = _a[1];
|
|
39
|
-
var _b = React.useState(ToDate(props.Record[props.FromField])), Tstart = _b[0], setTstart = _b[1];
|
|
40
|
-
var _c = React.useState(ToDate(props.Record[props.ToField])), Tend = _c[0], setTend = _c[1];
|
|
41
|
-
var _d = React.useState(Tstart != null ? ToString(Tstart) : ''), StartInput = _d[0], setStartInput = _d[1];
|
|
42
|
-
var _e = React.useState(Tend != null ? ToString(Tend) : ''), EndInput = _e[0], setEndInput = _e[1];
|
|
43
|
-
React.useEffect(function () {
|
|
44
|
-
var propsStart = ToDate(props.Record[props.FromField]);
|
|
45
|
-
var propsEnd = ToDate(props.Record[props.ToField]);
|
|
46
|
-
if (propsStart == null || Tstart == null) {
|
|
47
|
-
if (!(propsStart == null && Tstart == null))
|
|
48
|
-
setTstart(propsStart);
|
|
49
|
-
}
|
|
50
|
-
else if (propsStart.getTime() !== Tstart.getTime())
|
|
51
|
-
setTstart(propsStart);
|
|
52
|
-
if (propsEnd == null || Tend == null) {
|
|
53
|
-
if (!(propsEnd == null && Tend == null))
|
|
54
|
-
setTstart(propsEnd);
|
|
55
|
-
}
|
|
56
|
-
else if (propsEnd.getTime() !== Tend.getTime())
|
|
57
|
-
setTend(propsEnd);
|
|
58
|
-
}, [props.Record]);
|
|
59
|
-
React.useEffect(function () {
|
|
60
|
-
var days = (Tstart != null && Tend != null ? Math.round((Tend.getTime() - Tstart.getTime()) / (1000 * 60 * 60 * 24)) : 0);
|
|
61
|
-
if (ToRange(days) !== range)
|
|
62
|
-
setRange(ToRange(days));
|
|
63
|
-
UpdateTime();
|
|
64
|
-
}, [Tstart, Tend]);
|
|
65
|
-
React.useEffect(function () {
|
|
66
|
-
var days = GetDays(range);
|
|
67
|
-
if (days > 0) {
|
|
68
|
-
if (Tstart != null)
|
|
69
|
-
setTend(new Date(Tstart.valueOf() + 1000 * 24 * 60 * 60 * days));
|
|
70
|
-
else if (Tend != null)
|
|
71
|
-
setTstart(new Date(Tend.valueOf() - 1000 * 24 * 60 * 60 * days));
|
|
72
|
-
else {
|
|
73
|
-
setTstart(new Date(new Date().valueOf() - 1000 * 24 * 60 * 60 * days));
|
|
74
|
-
setTend(new Date());
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}, [range]);
|
|
78
|
-
function GetDays(val) {
|
|
79
|
-
if (val === '1 Day')
|
|
80
|
-
return 1;
|
|
81
|
-
if (val === '7 Days')
|
|
82
|
-
return 7;
|
|
83
|
-
if (val === '30 Days')
|
|
84
|
-
return 30;
|
|
85
|
-
if (val === '90 Days')
|
|
86
|
-
return 90;
|
|
87
|
-
if (val === '180 Days')
|
|
88
|
-
return 180;
|
|
89
|
-
if (val === '365 Days')
|
|
90
|
-
return 365;
|
|
91
|
-
return 0;
|
|
92
|
-
}
|
|
93
|
-
function ToDate(str) {
|
|
94
|
-
if (str === null)
|
|
95
|
-
return null;
|
|
96
|
-
var dt = new Date(str);
|
|
97
|
-
if (isNaN(dt.getTime()))
|
|
98
|
-
return null;
|
|
99
|
-
return dt;
|
|
100
|
-
}
|
|
101
|
-
React.useEffect(function () {
|
|
102
|
-
if (Tstart != null)
|
|
103
|
-
setStartInput(ToString(Tstart));
|
|
104
|
-
}, [Tstart]);
|
|
105
|
-
React.useEffect(function () {
|
|
106
|
-
// only if InputStart is a valid ToString
|
|
107
|
-
if (StartInput.match('^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-2][0-9])') != null)
|
|
108
|
-
setTstart(ToDate(StartInput));
|
|
109
|
-
else
|
|
110
|
-
setTstart(null);
|
|
111
|
-
}, [StartInput]);
|
|
112
|
-
React.useEffect(function () {
|
|
113
|
-
if (Tend != null)
|
|
114
|
-
setEndInput(ToString(Tend));
|
|
115
|
-
}, [Tend]);
|
|
116
|
-
React.useEffect(function () {
|
|
117
|
-
// only if EndInput is a valid ToString
|
|
118
|
-
if (EndInput.match('^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-2][0-9])') != null)
|
|
119
|
-
setTend(ToDate(EndInput));
|
|
120
|
-
else
|
|
121
|
-
setTend(null);
|
|
122
|
-
}, [EndInput]);
|
|
123
|
-
function UpdateTime() {
|
|
124
|
-
var _a;
|
|
125
|
-
var to = (Tend !== null ? ToString(Tend) : '');
|
|
126
|
-
var from = (Tstart !== null ? ToString(Tstart) : '');
|
|
127
|
-
var record = __assign(__assign({}, props.Record), (_a = {}, _a[props.ToField] = to, _a[props.FromField] = from, _a));
|
|
128
|
-
props.Setter(record);
|
|
129
|
-
}
|
|
130
|
-
function ToString(dt) {
|
|
131
|
-
return dt.getUTCFullYear() + "-" + (dt.getUTCMonth() + 1).toString()
|
|
132
|
-
.padStart(2, '0') + "-" + dt.getUTCDate().toString().padStart(2, '0');
|
|
133
|
-
}
|
|
134
|
-
function ToRange(days) {
|
|
135
|
-
if (days === 1)
|
|
136
|
-
return ('1 Day');
|
|
137
|
-
else if (days === 7)
|
|
138
|
-
return ('7 Days');
|
|
139
|
-
else if (days === 30)
|
|
140
|
-
return ('30 Days');
|
|
141
|
-
else if (days === 90)
|
|
142
|
-
return ('90 Days');
|
|
143
|
-
else if (days === 180)
|
|
144
|
-
return ('180 Days');
|
|
145
|
-
else if (days === 365)
|
|
146
|
-
return ('365 Days');
|
|
147
|
-
else
|
|
148
|
-
return ('Custom');
|
|
149
|
-
}
|
|
150
|
-
var startValid = (Tstart !== null) && (!isNaN(Tstart.getTime()));
|
|
151
|
-
var endValid = (Tend !== null) && (!isNaN(Tend.getTime())) && (!startValid || ((Tstart !== null) && (Tstart.getTime() < Tend.getTime())));
|
|
152
|
-
startValid = (props.Valid === undefined ? startValid : props.Valid);
|
|
153
|
-
endValid = (props.Valid === undefined ? endValid : props.Valid);
|
|
154
|
-
return (React.createElement("div", { className: "form-group" },
|
|
155
|
-
React.createElement("label", null, props.Label),
|
|
156
|
-
React.createElement("div", { className: "row" },
|
|
157
|
-
React.createElement("div", { className: "col" },
|
|
158
|
-
React.createElement("select", { className: "form-control", value: range, onChange: function (evt) { return setRange(evt.target.value); } },
|
|
159
|
-
React.createElement("option", { value: "Custom" }, "Custom"),
|
|
160
|
-
React.createElement("option", { value: "1 Day" }, "1 Day"),
|
|
161
|
-
React.createElement("option", { value: "7 Days" }, "7 Days"),
|
|
162
|
-
React.createElement("option", { value: "30 Days" }, "30 Days"),
|
|
163
|
-
React.createElement("option", { value: "90 Days" }, "90 Days"),
|
|
164
|
-
React.createElement("option", { value: "180 Days" }, "180 Days"),
|
|
165
|
-
React.createElement("option", { value: "365 Days" }, "365 Days"))),
|
|
166
|
-
React.createElement("div", { className: "col" },
|
|
167
|
-
React.createElement("input", { className: "form-control" + (startValid ? '' : ' is-invalid'), type: "date", onChange: function (evt) { setStartInput(evt.target.value); }, value: StartInput, disabled: props.Disabled == null ? false : props.Disabled })),
|
|
168
|
-
React.createElement("div", { className: "col" },
|
|
169
|
-
React.createElement("input", { className: "form-control" + (endValid ? '' : ' is-invalid'), type: "date", onChange: function (evt) { setEndInput(evt.target.value); }, value: EndInput, disabled: props.Disabled == null ? false : props.Disabled })))));
|
|
170
|
-
}
|
|
171
|
-
exports.default = DateRangePicker;
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// DateRangePicker.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
|
+
// 02/05/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 DateRangePicker(props) {
|
|
38
|
+
var _a = React.useState('Custom'), range = _a[0], setRange = _a[1];
|
|
39
|
+
var _b = React.useState(ToDate(props.Record[props.FromField])), Tstart = _b[0], setTstart = _b[1];
|
|
40
|
+
var _c = React.useState(ToDate(props.Record[props.ToField])), Tend = _c[0], setTend = _c[1];
|
|
41
|
+
var _d = React.useState(Tstart != null ? ToString(Tstart) : ''), StartInput = _d[0], setStartInput = _d[1];
|
|
42
|
+
var _e = React.useState(Tend != null ? ToString(Tend) : ''), EndInput = _e[0], setEndInput = _e[1];
|
|
43
|
+
React.useEffect(function () {
|
|
44
|
+
var propsStart = ToDate(props.Record[props.FromField]);
|
|
45
|
+
var propsEnd = ToDate(props.Record[props.ToField]);
|
|
46
|
+
if (propsStart == null || Tstart == null) {
|
|
47
|
+
if (!(propsStart == null && Tstart == null))
|
|
48
|
+
setTstart(propsStart);
|
|
49
|
+
}
|
|
50
|
+
else if (propsStart.getTime() !== Tstart.getTime())
|
|
51
|
+
setTstart(propsStart);
|
|
52
|
+
if (propsEnd == null || Tend == null) {
|
|
53
|
+
if (!(propsEnd == null && Tend == null))
|
|
54
|
+
setTstart(propsEnd);
|
|
55
|
+
}
|
|
56
|
+
else if (propsEnd.getTime() !== Tend.getTime())
|
|
57
|
+
setTend(propsEnd);
|
|
58
|
+
}, [props.Record]);
|
|
59
|
+
React.useEffect(function () {
|
|
60
|
+
var days = (Tstart != null && Tend != null ? Math.round((Tend.getTime() - Tstart.getTime()) / (1000 * 60 * 60 * 24)) : 0);
|
|
61
|
+
if (ToRange(days) !== range)
|
|
62
|
+
setRange(ToRange(days));
|
|
63
|
+
UpdateTime();
|
|
64
|
+
}, [Tstart, Tend]);
|
|
65
|
+
React.useEffect(function () {
|
|
66
|
+
var days = GetDays(range);
|
|
67
|
+
if (days > 0) {
|
|
68
|
+
if (Tstart != null)
|
|
69
|
+
setTend(new Date(Tstart.valueOf() + 1000 * 24 * 60 * 60 * days));
|
|
70
|
+
else if (Tend != null)
|
|
71
|
+
setTstart(new Date(Tend.valueOf() - 1000 * 24 * 60 * 60 * days));
|
|
72
|
+
else {
|
|
73
|
+
setTstart(new Date(new Date().valueOf() - 1000 * 24 * 60 * 60 * days));
|
|
74
|
+
setTend(new Date());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}, [range]);
|
|
78
|
+
function GetDays(val) {
|
|
79
|
+
if (val === '1 Day')
|
|
80
|
+
return 1;
|
|
81
|
+
if (val === '7 Days')
|
|
82
|
+
return 7;
|
|
83
|
+
if (val === '30 Days')
|
|
84
|
+
return 30;
|
|
85
|
+
if (val === '90 Days')
|
|
86
|
+
return 90;
|
|
87
|
+
if (val === '180 Days')
|
|
88
|
+
return 180;
|
|
89
|
+
if (val === '365 Days')
|
|
90
|
+
return 365;
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
function ToDate(str) {
|
|
94
|
+
if (str === null)
|
|
95
|
+
return null;
|
|
96
|
+
var dt = new Date(str);
|
|
97
|
+
if (isNaN(dt.getTime()))
|
|
98
|
+
return null;
|
|
99
|
+
return dt;
|
|
100
|
+
}
|
|
101
|
+
React.useEffect(function () {
|
|
102
|
+
if (Tstart != null)
|
|
103
|
+
setStartInput(ToString(Tstart));
|
|
104
|
+
}, [Tstart]);
|
|
105
|
+
React.useEffect(function () {
|
|
106
|
+
// only if InputStart is a valid ToString
|
|
107
|
+
if (StartInput.match('^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-2][0-9])') != null)
|
|
108
|
+
setTstart(ToDate(StartInput));
|
|
109
|
+
else
|
|
110
|
+
setTstart(null);
|
|
111
|
+
}, [StartInput]);
|
|
112
|
+
React.useEffect(function () {
|
|
113
|
+
if (Tend != null)
|
|
114
|
+
setEndInput(ToString(Tend));
|
|
115
|
+
}, [Tend]);
|
|
116
|
+
React.useEffect(function () {
|
|
117
|
+
// only if EndInput is a valid ToString
|
|
118
|
+
if (EndInput.match('^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-2][0-9])') != null)
|
|
119
|
+
setTend(ToDate(EndInput));
|
|
120
|
+
else
|
|
121
|
+
setTend(null);
|
|
122
|
+
}, [EndInput]);
|
|
123
|
+
function UpdateTime() {
|
|
124
|
+
var _a;
|
|
125
|
+
var to = (Tend !== null ? ToString(Tend) : '');
|
|
126
|
+
var from = (Tstart !== null ? ToString(Tstart) : '');
|
|
127
|
+
var record = __assign(__assign({}, props.Record), (_a = {}, _a[props.ToField] = to, _a[props.FromField] = from, _a));
|
|
128
|
+
props.Setter(record);
|
|
129
|
+
}
|
|
130
|
+
function ToString(dt) {
|
|
131
|
+
return dt.getUTCFullYear() + "-" + (dt.getUTCMonth() + 1).toString()
|
|
132
|
+
.padStart(2, '0') + "-" + dt.getUTCDate().toString().padStart(2, '0');
|
|
133
|
+
}
|
|
134
|
+
function ToRange(days) {
|
|
135
|
+
if (days === 1)
|
|
136
|
+
return ('1 Day');
|
|
137
|
+
else if (days === 7)
|
|
138
|
+
return ('7 Days');
|
|
139
|
+
else if (days === 30)
|
|
140
|
+
return ('30 Days');
|
|
141
|
+
else if (days === 90)
|
|
142
|
+
return ('90 Days');
|
|
143
|
+
else if (days === 180)
|
|
144
|
+
return ('180 Days');
|
|
145
|
+
else if (days === 365)
|
|
146
|
+
return ('365 Days');
|
|
147
|
+
else
|
|
148
|
+
return ('Custom');
|
|
149
|
+
}
|
|
150
|
+
var startValid = (Tstart !== null) && (!isNaN(Tstart.getTime()));
|
|
151
|
+
var endValid = (Tend !== null) && (!isNaN(Tend.getTime())) && (!startValid || ((Tstart !== null) && (Tstart.getTime() < Tend.getTime())));
|
|
152
|
+
startValid = (props.Valid === undefined ? startValid : props.Valid);
|
|
153
|
+
endValid = (props.Valid === undefined ? endValid : props.Valid);
|
|
154
|
+
return (React.createElement("div", { className: "form-group" },
|
|
155
|
+
React.createElement("label", null, props.Label),
|
|
156
|
+
React.createElement("div", { className: "row" },
|
|
157
|
+
React.createElement("div", { className: "col" },
|
|
158
|
+
React.createElement("select", { className: "form-control", value: range, onChange: function (evt) { return setRange(evt.target.value); } },
|
|
159
|
+
React.createElement("option", { value: "Custom" }, "Custom"),
|
|
160
|
+
React.createElement("option", { value: "1 Day" }, "1 Day"),
|
|
161
|
+
React.createElement("option", { value: "7 Days" }, "7 Days"),
|
|
162
|
+
React.createElement("option", { value: "30 Days" }, "30 Days"),
|
|
163
|
+
React.createElement("option", { value: "90 Days" }, "90 Days"),
|
|
164
|
+
React.createElement("option", { value: "180 Days" }, "180 Days"),
|
|
165
|
+
React.createElement("option", { value: "365 Days" }, "365 Days"))),
|
|
166
|
+
React.createElement("div", { className: "col" },
|
|
167
|
+
React.createElement("input", { className: "form-control" + (startValid ? '' : ' is-invalid'), type: "date", onChange: function (evt) { setStartInput(evt.target.value); }, value: StartInput, disabled: props.Disabled == null ? false : props.Disabled })),
|
|
168
|
+
React.createElement("div", { className: "col" },
|
|
169
|
+
React.createElement("input", { className: "form-control" + (endValid ? '' : ' is-invalid'), type: "date", onChange: function (evt) { setEndInput(evt.target.value); }, value: EndInput, disabled: props.Disabled == null ? false : props.Disabled })))));
|
|
170
|
+
}
|
|
171
|
+
exports.default = DateRangePicker;
|
package/lib/DoubleInput.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export default function DoubleInput<T>(props: {
|
|
3
|
-
Record: T;
|
|
4
|
-
Field1: keyof T;
|
|
5
|
-
Field2: keyof T;
|
|
6
|
-
Setter: (record: T) => void;
|
|
7
|
-
Valid: (field: keyof T) => boolean;
|
|
8
|
-
Label?: string;
|
|
9
|
-
Feedback?: string;
|
|
10
|
-
Disabled?: boolean;
|
|
11
|
-
Type?: 'number' | 'text' | 'password' | 'email' | 'color';
|
|
12
|
-
}): JSX.Element;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export default function DoubleInput<T>(props: {
|
|
3
|
+
Record: T;
|
|
4
|
+
Field1: keyof T;
|
|
5
|
+
Field2: keyof T;
|
|
6
|
+
Setter: (record: T) => void;
|
|
7
|
+
Valid: (field: keyof T) => boolean;
|
|
8
|
+
Label?: string;
|
|
9
|
+
Feedback?: string;
|
|
10
|
+
Disabled?: boolean;
|
|
11
|
+
Type?: 'number' | 'text' | 'password' | 'email' | 'color';
|
|
12
|
+
}): JSX.Element;
|