@gpa-gemstone/react-forms 1.1.23 → 1.1.26
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/DatePicker.d.ts +1 -0
- package/lib/DatePicker.js +13 -4
- package/lib/DateRangePicker.d.ts +5 -2
- package/lib/DateRangePicker.js +33 -88
- package/lib/Input.js +15 -6
- package/lib/Select.js +4 -3
- package/lib/TimePicker.d.ts +1 -0
- package/lib/TimePicker.js +3 -2
- package/package.json +5 -4
package/lib/DatePicker.d.ts
CHANGED
package/lib/DatePicker.js
CHANGED
|
@@ -49,6 +49,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
51
|
var React = require("react");
|
|
52
|
+
var moment = require("moment");
|
|
52
53
|
var DatePicker = /** @class */ (function (_super) {
|
|
53
54
|
__extends(DatePicker, _super);
|
|
54
55
|
function DatePicker() {
|
|
@@ -57,15 +58,23 @@ var DatePicker = /** @class */ (function (_super) {
|
|
|
57
58
|
DatePicker.prototype.render = function () {
|
|
58
59
|
var _this = this;
|
|
59
60
|
return (React.createElement("div", { className: "form-group" },
|
|
60
|
-
|
|
61
|
+
(this.props.Label !== "") ?
|
|
62
|
+
React.createElement("label", null, this.props.Label == null ? this.props.Field : this.props.Label) : null,
|
|
61
63
|
React.createElement("input", { className: this.props.Valid(this.props.Field) ? 'form-control' : 'form-control is-invalid', type: "date", onChange: function (evt) {
|
|
62
64
|
var record = __assign({}, _this.props.Record);
|
|
63
|
-
if (evt.target.value !== '')
|
|
64
|
-
|
|
65
|
+
if (evt.target.value !== '') {
|
|
66
|
+
if (_this.props.Format === null)
|
|
67
|
+
record[_this.props.Field] = evt.target.value;
|
|
68
|
+
else
|
|
69
|
+
record[_this.props.Field] = moment(evt.target.value).format(_this.props.Format);
|
|
70
|
+
}
|
|
65
71
|
else
|
|
66
72
|
record[_this.props.Field] = null;
|
|
67
73
|
_this.props.Setter(record);
|
|
68
|
-
}, value: this.props.Record[this.props.Field] == null ? '' :
|
|
74
|
+
}, value: this.props.Record[this.props.Field] == null ? '' :
|
|
75
|
+
this.props.Format == null ?
|
|
76
|
+
this.props.Record[this.props.Field].toString() :
|
|
77
|
+
moment(this.props.Record[this.props.Field]).format("YYYY-MM-DD"), disabled: this.props.Disabled == null ? false : this.props.Disabled }),
|
|
69
78
|
React.createElement("div", { className: "invalid-feedback" }, this.props.Feedback == null ? this.props.Field + ' is a required field.' : this.props.Feedback)));
|
|
70
79
|
};
|
|
71
80
|
return DatePicker;
|
package/lib/DateRangePicker.d.ts
CHANGED
|
@@ -4,7 +4,10 @@ export default function DateRangePicker<T>(props: {
|
|
|
4
4
|
FromField: keyof T;
|
|
5
5
|
ToField: keyof T;
|
|
6
6
|
Setter: (record: T) => void;
|
|
7
|
-
Disabled?: boolean;
|
|
8
7
|
Label: string;
|
|
9
|
-
Valid
|
|
8
|
+
Valid: (fieldFrom: keyof T, fieldTo: keyof T) => boolean;
|
|
9
|
+
Disabled?: boolean;
|
|
10
|
+
Feedback?: string;
|
|
11
|
+
Format?: string;
|
|
12
|
+
Type?: ('datetime-local' | 'date');
|
|
10
13
|
}): JSX.Element;
|
package/lib/DateRangePicker.js
CHANGED
|
@@ -34,47 +34,18 @@ var __assign = (this && this.__assign) || function () {
|
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
var React = require("react");
|
|
37
|
+
var moment = require("moment");
|
|
37
38
|
function DateRangePicker(props) {
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
var
|
|
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];
|
|
39
|
+
// Range box vars, need a secondary var to avoid looping react hooks
|
|
40
|
+
var _a = React.useState('Custom'), formRange = _a[0], setFormRange = _a[1];
|
|
41
|
+
var _b = React.useState('Custom'), range = _b[0], setRange = _b[1];
|
|
43
42
|
React.useEffect(function () {
|
|
44
|
-
|
|
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);
|
|
43
|
+
setRange(ToRange(moment(props.Record[props.ToField]).diff(props.Record[props.FromField], 'days')));
|
|
58
44
|
}, [props.Record]);
|
|
59
45
|
React.useEffect(function () {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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]);
|
|
46
|
+
setRange(formRange);
|
|
47
|
+
RecordSetter(moment(props.Record[props.FromField]).add(GetDays(formRange), 'days').toString(), props.ToField);
|
|
48
|
+
}, [formRange]);
|
|
78
49
|
function GetDays(val) {
|
|
79
50
|
if (val === '1 Day')
|
|
80
51
|
return 1;
|
|
@@ -90,47 +61,6 @@ function DateRangePicker(props) {
|
|
|
90
61
|
return 365;
|
|
91
62
|
return 0;
|
|
92
63
|
}
|
|
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
64
|
function ToRange(days) {
|
|
135
65
|
if (days === 1)
|
|
136
66
|
return ('1 Day');
|
|
@@ -147,15 +77,32 @@ function DateRangePicker(props) {
|
|
|
147
77
|
else
|
|
148
78
|
return ('Custom');
|
|
149
79
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
80
|
+
function RecordSetter(val, field) {
|
|
81
|
+
var record = __assign({}, props.Record);
|
|
82
|
+
if (val !== '') {
|
|
83
|
+
if (props.Format === null)
|
|
84
|
+
record[field] = val;
|
|
85
|
+
else
|
|
86
|
+
record[field] = moment(val).format(props.Format);
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
record[field] = null;
|
|
90
|
+
props.Setter(record);
|
|
91
|
+
}
|
|
92
|
+
function dateBox(field) {
|
|
93
|
+
return React.createElement("div", { className: "col" },
|
|
94
|
+
React.createElement("input", { className: "form-control" + (props.Valid(props.FromField, props.ToField) ? '' : ' is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
|
|
95
|
+
RecordSetter(evt.target.value, field);
|
|
96
|
+
}, value: props.Record[field] === null ? '' :
|
|
97
|
+
moment(props.Record[field]).format("YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "Thh:mm")), disabled: props.Disabled === null ? false : props.Disabled }),
|
|
98
|
+
field !== props.FromField ? null :
|
|
99
|
+
React.createElement("div", { className: "invalid-feedback" }, props.Feedback === undefined ? 'From and to dates required, and from must be before to.' : props.Feedback));
|
|
100
|
+
}
|
|
154
101
|
return (React.createElement("div", { className: "form-group" },
|
|
155
|
-
React.createElement("label", null, props.Label),
|
|
102
|
+
props.Label === "" ? null : React.createElement("label", null, props.Label),
|
|
156
103
|
React.createElement("div", { className: "row" },
|
|
157
104
|
React.createElement("div", { className: "col" },
|
|
158
|
-
React.createElement("select", { className: "form-control", value: range, onChange: function (evt) { return
|
|
105
|
+
React.createElement("select", { className: "form-control", value: range, onChange: function (evt) { return setFormRange(evt.target.value); } },
|
|
159
106
|
React.createElement("option", { value: "Custom" }, "Custom"),
|
|
160
107
|
React.createElement("option", { value: "1 Day" }, "1 Day"),
|
|
161
108
|
React.createElement("option", { value: "7 Days" }, "7 Days"),
|
|
@@ -163,9 +110,7 @@ function DateRangePicker(props) {
|
|
|
163
110
|
React.createElement("option", { value: "90 Days" }, "90 Days"),
|
|
164
111
|
React.createElement("option", { value: "180 Days" }, "180 Days"),
|
|
165
112
|
React.createElement("option", { value: "365 Days" }, "365 Days"))),
|
|
166
|
-
|
|
167
|
-
|
|
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 })))));
|
|
113
|
+
dateBox(props.FromField),
|
|
114
|
+
dateBox(props.ToField))));
|
|
170
115
|
}
|
|
171
116
|
exports.default = DateRangePicker;
|
package/lib/Input.js
CHANGED
|
@@ -41,24 +41,33 @@ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
|
41
41
|
function Input(props) {
|
|
42
42
|
var _a = React.useState(""), guid = _a[0], setGuid = _a[1];
|
|
43
43
|
var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
|
|
44
|
+
var _c = React.useState(''), heldVal = _c[0], setHeldVal = _c[1];
|
|
44
45
|
React.useEffect(function () {
|
|
45
46
|
setGuid((0, helper_functions_1.CreateGuid)());
|
|
46
47
|
}, []);
|
|
48
|
+
React.useEffect(function () {
|
|
49
|
+
setHeldVal(props.Record[props.Field] == null ? '' : props.Record[props.Field].toString());
|
|
50
|
+
}, [props.Record[props.Field]]);
|
|
47
51
|
function valueChange(evt) {
|
|
48
52
|
var _a, _b;
|
|
49
|
-
if (props.Type === 'number')
|
|
50
|
-
|
|
53
|
+
if (props.Type === 'number') {
|
|
54
|
+
if (parseFloat(heldVal) !== parseFloat(evt.target.value))
|
|
55
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = evt.target.value !== '' ? parseFloat(evt.target.value) : null, _a)));
|
|
56
|
+
else
|
|
57
|
+
setHeldVal(evt.target.value);
|
|
58
|
+
}
|
|
51
59
|
else
|
|
52
60
|
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = evt.target.value !== '' ? evt.target.value : null, _b)));
|
|
53
61
|
}
|
|
54
62
|
return (React.createElement("div", { className: "form-group" },
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
(props.Label !== "") ?
|
|
64
|
+
React.createElement("label", null,
|
|
65
|
+
props.Label === null ? props.Field : props.Label,
|
|
66
|
+
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,
|
|
58
67
|
props.Help !== undefined ?
|
|
59
68
|
React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
|
|
60
69
|
: null,
|
|
61
|
-
React.createElement("input", { "data-help": guid, type: props.Type === undefined ? 'text' : props.Type, className: props.Valid(props.Field) ? 'form-control' : 'form-control is-invalid', onChange: function (evt) { return valueChange(evt); }, value:
|
|
70
|
+
React.createElement("input", { "data-help": guid, type: props.Type === undefined ? 'text' : props.Type, className: props.Valid(props.Field) ? 'form-control' : 'form-control is-invalid', onChange: function (evt) { return valueChange(evt); }, value: heldVal, disabled: props.Disabled == null ? false : props.Disabled }),
|
|
62
71
|
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field + ' is a required field.' : props.Feedback)));
|
|
63
72
|
}
|
|
64
73
|
exports.default = Input;
|
package/lib/Select.js
CHANGED
|
@@ -45,9 +45,10 @@ function Select(props) {
|
|
|
45
45
|
setGuid((0, helper_functions_1.CreateGuid)());
|
|
46
46
|
}, []);
|
|
47
47
|
return (React.createElement("div", { className: "form-group" },
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
(props.Label !== "") ?
|
|
49
|
+
React.createElement("label", null,
|
|
50
|
+
props.Label === null ? props.Field : props.Label,
|
|
51
|
+
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,
|
|
51
52
|
props.Help !== undefined ?
|
|
52
53
|
React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
|
|
53
54
|
: null,
|
package/lib/TimePicker.d.ts
CHANGED
package/lib/TimePicker.js
CHANGED
|
@@ -57,8 +57,9 @@ var TimePicker = /** @class */ (function (_super) {
|
|
|
57
57
|
TimePicker.prototype.render = function () {
|
|
58
58
|
var _this = this;
|
|
59
59
|
return (React.createElement("div", { className: "form-group" },
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
(this.props.Label !== "") ?
|
|
61
|
+
React.createElement("label", null, this.props.Label == null ? this.props.Field : this.props.Label) : null,
|
|
62
|
+
React.createElement("input", { className: this.props.Valid(this.props.Field) ? 'form-control' : 'form-control is-invalid', type: "time", step: this.props.Step === null ? 60 : this.props.Step, onChange: function (evt) {
|
|
62
63
|
var record = __assign({}, _this.props.Record);
|
|
63
64
|
if (evt.target.value !== '')
|
|
64
65
|
record[_this.props.Field] = evt.target.value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gpa-gemstone/react-forms",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.26",
|
|
4
4
|
"description": "React Form modules for gpa webapps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,11 +45,12 @@
|
|
|
45
45
|
"typescript": "4.4.4"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@gpa-gemstone/helper-functions": "0.0.
|
|
48
|
+
"@gpa-gemstone/helper-functions": "0.0.16",
|
|
49
49
|
"@types/react": "^17.0.14",
|
|
50
50
|
"@types/styled-components": "^5.1.11",
|
|
51
|
-
"react": "^
|
|
52
|
-
"styled-components": "5.3.3"
|
|
51
|
+
"react": "^18.2.0",
|
|
52
|
+
"styled-components": "5.3.3",
|
|
53
|
+
"moment": "2.29.4"
|
|
53
54
|
},
|
|
54
55
|
"publishConfig": {
|
|
55
56
|
"access": "public"
|