@gpa-gemstone/react-forms 1.1.56 → 1.1.58
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.js +6 -4
- package/lib/DatePicker.d.ts +2 -0
- package/lib/DatePicker.js +67 -44
- package/lib/DateTimeUI/Calender.d.ts +1 -1
- package/lib/DateTimeUI/Calender.js +20 -15
- package/lib/DateTimeUI/Clock.d.ts +1 -1
- package/lib/DateTimeUI/Clock.js +13 -10
- package/lib/DateTimeUI/DateTimePopup.d.ts +1 -1
- package/lib/Input.js +7 -7
- package/lib/InputWithButton.d.ts +23 -0
- package/lib/InputWithButton.js +107 -0
- package/lib/ToggleSwitch.d.ts +11 -0
- package/lib/ToggleSwitch.js +61 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +5 -1
- package/package.json +1 -1
package/lib/ArrayCheckBoxes.js
CHANGED
|
@@ -43,6 +43,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
var React = require("react");
|
|
46
|
+
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
46
47
|
function ArrayCheckBoxes(props) {
|
|
47
48
|
var Remove = function (cb) {
|
|
48
49
|
var a = __spreadArray([], props.Record[props.Field], true);
|
|
@@ -58,20 +59,21 @@ function ArrayCheckBoxes(props) {
|
|
|
58
59
|
a.sort();
|
|
59
60
|
return a;
|
|
60
61
|
};
|
|
62
|
+
var id = React.useRef("array-checkbox-" + (0, helper_functions_1.CreateGuid)());
|
|
61
63
|
return (React.createElement("div", { className: "form-group" },
|
|
62
64
|
React.createElement("label", null, props.Label == null ? props.Field : props.Label),
|
|
63
65
|
React.createElement("br", null),
|
|
64
66
|
React.createElement("div", { className: "form-check form-check-inline" },
|
|
65
|
-
React.createElement("input", { className: "form-check-input", type: "checkbox", checked: JSON.stringify(props.Record[props.Field]) === JSON.stringify(props.Checkboxes.map(function (x) { return x.ID; })), onChange: function (evt) {
|
|
67
|
+
React.createElement("input", { id: id.current + "-all", className: "form-check-input", type: "checkbox", checked: JSON.stringify(props.Record[props.Field]) === JSON.stringify(props.Checkboxes.map(function (x) { return x.ID; })), onChange: function (evt) {
|
|
66
68
|
var _a;
|
|
67
69
|
return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = evt.target.checked ? props.Checkboxes.map(function (x) { return x.ID; }) : [], _a)));
|
|
68
70
|
} }),
|
|
69
|
-
React.createElement("label", { className: "form-check-label" }, "All")),
|
|
71
|
+
React.createElement("label", { htmlFor: id.current + "-all", className: "form-check-label" }, "All")),
|
|
70
72
|
props.Checkboxes.map(function (cb, i) { return (React.createElement("div", { key: i, className: "form-check form-check-inline" },
|
|
71
|
-
React.createElement("input", { className: "form-check-input", type: "checkbox", checked: props.Record[props.Field].find(function (x) { return cb.ID === x; }) !== undefined, onChange: function (evt) {
|
|
73
|
+
React.createElement("input", { id: id.current + "-" + i, className: "form-check-input", type: "checkbox", checked: props.Record[props.Field].find(function (x) { return cb.ID === x; }) !== undefined, onChange: function (evt) {
|
|
72
74
|
var _a;
|
|
73
75
|
return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = evt.target.checked ? Add(cb) : Remove(cb), _a)));
|
|
74
76
|
} }),
|
|
75
|
-
React.createElement("label", { className: "form-check-label" }, cb.Label))); })));
|
|
77
|
+
React.createElement("label", { htmlFor: id.current + "-" + i, className: "form-check-label" }, cb.Label))); })));
|
|
76
78
|
}
|
|
77
79
|
exports.default = ArrayCheckBoxes;
|
package/lib/DatePicker.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import * as moment from 'moment';
|
|
2
3
|
import { Accuracy } from './DateTimeUI/Clock';
|
|
3
4
|
export declare type TimeUnit = ('datetime-local' | 'date' | 'time');
|
|
4
5
|
interface IProps<T> {
|
|
@@ -14,6 +15,7 @@ interface IProps<T> {
|
|
|
14
15
|
Help?: string | JSX.Element;
|
|
15
16
|
AllowEmpty?: boolean;
|
|
16
17
|
Accuracy?: Accuracy;
|
|
18
|
+
MinDate?: moment.Moment;
|
|
17
19
|
}
|
|
18
20
|
export default function DateTimePicker<T>(props: IProps<T>): JSX.Element;
|
|
19
21
|
export {};
|
package/lib/DatePicker.js
CHANGED
|
@@ -44,7 +44,6 @@ function DateTimePicker(props) {
|
|
|
44
44
|
var recordFormat = props.Format !== undefined ? props.Format : "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]HH:mm:ss.SSS[Z]");
|
|
45
45
|
var parse = function (r) { return moment(props.Record[props.Field], recordFormat); };
|
|
46
46
|
var divRef = React.useRef(null);
|
|
47
|
-
var recordChange = React.useRef(false);
|
|
48
47
|
var _a = React.useState(""), guid = _a[0], setGuid = _a[1];
|
|
49
48
|
var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
|
|
50
49
|
// Adds a buffer between the outside props and what the box is reading to prevent box overwriting every render with a keystroke
|
|
@@ -58,43 +57,15 @@ function DateTimePicker(props) {
|
|
|
58
57
|
setGuid((0, helper_functions_1.CreateGuid)());
|
|
59
58
|
}, []);
|
|
60
59
|
React.useEffect(function () {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, [props.Record]);
|
|
65
|
-
React.useEffect(function () {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
var _c;
|
|
68
|
-
if (!recordChange.current)
|
|
69
|
-
return;
|
|
70
|
-
var date = moment(boxRecord, boxFormat);
|
|
71
|
-
var validStartDate = moment("1753-01-01", "YYYY-MM-DD");
|
|
72
|
-
var valid = true;
|
|
73
|
-
// Invalid date format
|
|
74
|
-
if (!date.isValid()) {
|
|
75
|
-
setFeedbackMessage("Please enter a date as " + boxFormat);
|
|
76
|
-
valid = false;
|
|
77
|
-
}
|
|
78
|
-
// Date before 1753
|
|
79
|
-
else if (date.isBefore(validStartDate)) {
|
|
80
|
-
setFeedbackMessage("Date cannot be before " + validStartDate.format(boxFormat));
|
|
81
|
-
valid = false;
|
|
60
|
+
if (props.Record[props.Field] !== null) {
|
|
61
|
+
setPickerRecord(parse(props.Record));
|
|
62
|
+
setBoxRecord(parse(props.Record).format(boxFormat));
|
|
82
63
|
}
|
|
83
64
|
else {
|
|
84
|
-
|
|
65
|
+
setPickerRecord(undefined);
|
|
66
|
+
setBoxRecord('');
|
|
85
67
|
}
|
|
86
|
-
|
|
87
|
-
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = null, _a)));
|
|
88
|
-
if (valid && parse(props.Record).format(boxFormat) !== boxRecord)
|
|
89
|
-
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = moment(boxRecord, boxFormat).format(recordFormat), _b)));
|
|
90
|
-
}, [boxRecord]);
|
|
91
|
-
React.useEffect(function () {
|
|
92
|
-
var _a;
|
|
93
|
-
if (!recordChange.current)
|
|
94
|
-
return;
|
|
95
|
-
if (pickerRecord.format(recordFormat) !== parse(props.Record).format(recordFormat))
|
|
96
|
-
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = pickerRecord.format(recordFormat), _a)));
|
|
97
|
-
}, [pickerRecord]);
|
|
68
|
+
}, [props.Record]);
|
|
98
69
|
React.useLayoutEffect(function () {
|
|
99
70
|
var node = (divRef.current !== null ? (0, helper_functions_1.GetNodeSize)(divRef.current) : { top: top, left: left, height: 0, width: 0 });
|
|
100
71
|
if (node.height === 0 && node.width === 0) {
|
|
@@ -108,10 +79,29 @@ function DateTimePicker(props) {
|
|
|
108
79
|
React.useEffect(function () {
|
|
109
80
|
window.addEventListener('click', onWindowClick);
|
|
110
81
|
return function () { window.removeEventListener('click', onWindowClick); };
|
|
111
|
-
}, []);
|
|
82
|
+
}, [props.Record, props.Field, boxFormat]);
|
|
83
|
+
function setPickerAndRecord(arg) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
var _c;
|
|
86
|
+
setPickerRecord(arg);
|
|
87
|
+
if (((_c = props.AllowEmpty) !== null && _c !== void 0 ? _c : false) && arg === undefined && props.Record[props.Field] !== null)
|
|
88
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = null, _a)));
|
|
89
|
+
var valid = arg != undefined && validateDate(arg);
|
|
90
|
+
if (valid && props.Record[props.Field].toString() !== arg.format(recordFormat))
|
|
91
|
+
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = arg.format(recordFormat), _b)));
|
|
92
|
+
}
|
|
112
93
|
function onWindowClick(evt) {
|
|
113
|
-
if (evt.target.closest(".gpa-gemstone-datetime") == null)
|
|
94
|
+
if (evt.target.closest(".gpa-gemstone-datetime") == null) {
|
|
114
95
|
setShowOverlay(false);
|
|
96
|
+
if (props.Record[props.Field] !== null) {
|
|
97
|
+
setPickerAndRecord(parse(props.Record));
|
|
98
|
+
setBoxRecord(parse(props.Record).format(boxFormat));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
setPickerAndRecord(undefined);
|
|
102
|
+
setBoxRecord('');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
115
105
|
}
|
|
116
106
|
function getBoxFormat(type, accuracy) {
|
|
117
107
|
var dateTime = type !== null && type !== void 0 ? type : 'date';
|
|
@@ -147,10 +137,25 @@ function DateTimePicker(props) {
|
|
|
147
137
|
return feedbackMessage;
|
|
148
138
|
}
|
|
149
139
|
else if (props.Feedback == null || props.Feedback.length == 0) {
|
|
150
|
-
return props.Field.toString();
|
|
140
|
+
return props.Field.toString() + " is a required field.";
|
|
151
141
|
}
|
|
152
142
|
else {
|
|
153
|
-
return props.
|
|
143
|
+
return props.Feedback;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function validateDate(date) {
|
|
147
|
+
var minStartDate = props.MinDate != null ? props.MinDate.startOf('day') : moment("1753-01-01", "YYYY-MM-DD").startOf('day');
|
|
148
|
+
if (!date.isValid()) {
|
|
149
|
+
setFeedbackMessage("Please enter a valid date.");
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
else if (date.startOf('day').isBefore(minStartDate)) {
|
|
153
|
+
setFeedbackMessage("Date must be on or after " + minStartDate.format("MM-DD-YYYY"));
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
setFeedbackMessage("");
|
|
158
|
+
return true;
|
|
154
159
|
}
|
|
155
160
|
}
|
|
156
161
|
var showLabel = props.Label !== "";
|
|
@@ -162,6 +167,23 @@ function DateTimePicker(props) {
|
|
|
162
167
|
return false;
|
|
163
168
|
return props.Valid(props.Field);
|
|
164
169
|
};
|
|
170
|
+
function valueChange(value) {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
var allowNull = props.AllowEmpty === undefined ? false : props.AllowEmpty;
|
|
173
|
+
var date = moment(value, boxFormat);
|
|
174
|
+
if (allowNull && value === '') {
|
|
175
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = null, _a)));
|
|
176
|
+
setPickerAndRecord(undefined);
|
|
177
|
+
}
|
|
178
|
+
else if (validateDate(date)) {
|
|
179
|
+
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = moment(value, boxFormat).format(recordFormat), _b)));
|
|
180
|
+
setPickerAndRecord(moment(value, boxFormat));
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
setPickerAndRecord(undefined);
|
|
184
|
+
}
|
|
185
|
+
setBoxRecord(value);
|
|
186
|
+
}
|
|
165
187
|
return (React.createElement("div", { className: "form-group", ref: divRef },
|
|
166
188
|
showHelpIcon || showLabel ?
|
|
167
189
|
React.createElement("label", null,
|
|
@@ -180,12 +202,13 @@ function DateTimePicker(props) {
|
|
|
180
202
|
React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
|
|
181
203
|
: null,
|
|
182
204
|
React.createElement("input", { "data-help": guid, className: "gpa-gemstone-datetime form-control " + (IsValid() ? '' : 'is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
|
|
183
|
-
|
|
184
|
-
setBoxRecord((_a = evt.target.value) !== null && _a !== void 0 ? _a : "");
|
|
185
|
-
recordChange.current = true;
|
|
205
|
+
valueChange(evt.target.value);
|
|
186
206
|
}, onFocus: function () { setShowOverlay(true); }, value: boxRecord, disabled: props.Disabled === undefined ? false : props.Disabled, onClick: function (e) { e.preventDefault(); }, step: step }),
|
|
187
207
|
React.createElement("div", { className: "invalid-feedback" }, getFeedbackMessage()),
|
|
188
|
-
React.createElement(DateTimePopup_1.default, { Setter: function (d) {
|
|
189
|
-
|
|
208
|
+
React.createElement(DateTimePopup_1.default, { Setter: function (d) {
|
|
209
|
+
setPickerAndRecord(d);
|
|
210
|
+
if (props.Type === 'date')
|
|
211
|
+
setShowOverlay(false);
|
|
212
|
+
}, Show: showOverlay, DateTime: pickerRecord, Valid: props.Valid(props.Field), Top: top, Center: left, Type: props.Type === undefined ? 'date' : props.Type, Accuracy: props.Accuracy })));
|
|
190
213
|
}
|
|
191
214
|
exports.default = DateTimePicker;
|
|
@@ -25,14 +25,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
var React = require("react");
|
|
26
26
|
var moment = require("moment");
|
|
27
27
|
function Calender(props) {
|
|
28
|
-
var _a
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
28
|
+
var _a, _b, _c, _d;
|
|
29
|
+
var _e = React.useState([]), weeks = _e[0], setWeeks = _e[1];
|
|
30
|
+
var _f = React.useState((_b = (_a = props.DateTime) === null || _a === void 0 ? void 0 : _a.month()) !== null && _b !== void 0 ? _b : 0), month = _f[0], setMonth = _f[1];
|
|
31
|
+
var _g = React.useState((_d = (_c = props.DateTime) === null || _c === void 0 ? void 0 : _c.year()) !== null && _d !== void 0 ? _d : moment.utc().year()), year = _g[0], setYear = _g[1];
|
|
32
|
+
var _h = React.useState('month'), mode = _h[0], setMode = _h[1];
|
|
33
|
+
var _j = React.useState('None'), hover = _j[0], setHover = _j[1];
|
|
33
34
|
React.useEffect(function () {
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
36
|
+
setMonth(isNaN((_b = (_a = props.DateTime) === null || _a === void 0 ? void 0 : _a.month()) !== null && _b !== void 0 ? _b : NaN) ? 0 : ((_d = (_c = props.DateTime) === null || _c === void 0 ? void 0 : _c.month()) !== null && _d !== void 0 ? _d : 0));
|
|
37
|
+
setYear(isNaN((_f = (_e = props.DateTime) === null || _e === void 0 ? void 0 : _e.year()) !== null && _f !== void 0 ? _f : NaN) ? moment.utc().year() : ((_h = (_g = props.DateTime) === null || _g === void 0 ? void 0 : _g.year()) !== null && _h !== void 0 ? _h : moment.utc().year()));
|
|
36
38
|
}, [props.DateTime]);
|
|
37
39
|
React.useEffect(function () {
|
|
38
40
|
var d1 = moment([year, month, 1]).startOf('week');
|
|
@@ -113,14 +115,17 @@ function Calender(props) {
|
|
|
113
115
|
React.createElement("td", { style: { width: 20, padding: 5 } }, "FR"),
|
|
114
116
|
React.createElement("td", { style: { width: 20, padding: 5 } }, "SA")) : null),
|
|
115
117
|
React.createElement("tbody", null,
|
|
116
|
-
mode === 'month' ? weeks.map(function (w) {
|
|
117
|
-
|
|
118
|
-
React.createElement(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
mode === 'month' ? weeks.map(function (w) {
|
|
119
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
120
|
+
return React.createElement("tr", { key: w.sunday.isoWeek(), style: { height: 20, lineHeight: '20px' } },
|
|
121
|
+
React.createElement(DayCell, { date: w.sunday, month: month, day: (_b = (_a = props.DateTime) === null || _a === void 0 ? void 0 : _a.date()) !== null && _b !== void 0 ? _b : -1, onClick: function (evt) { evt.stopPropagation(); setDate(w.sunday); } }),
|
|
122
|
+
React.createElement(DayCell, { date: w.monday, month: month, day: (_d = (_c = props.DateTime) === null || _c === void 0 ? void 0 : _c.date()) !== null && _d !== void 0 ? _d : -1, onClick: function (evt) { evt.stopPropagation(); setDate(w.monday); } }),
|
|
123
|
+
React.createElement(DayCell, { date: w.tuesday, month: month, day: (_f = (_e = props.DateTime) === null || _e === void 0 ? void 0 : _e.date()) !== null && _f !== void 0 ? _f : -1, onClick: function (evt) { evt.stopPropagation(); setDate(w.tuesday); } }),
|
|
124
|
+
React.createElement(DayCell, { date: w.wednesday, month: month, day: (_h = (_g = props.DateTime) === null || _g === void 0 ? void 0 : _g.date()) !== null && _h !== void 0 ? _h : -1, onClick: function (evt) { evt.stopPropagation(); setDate(w.wednesday); } }),
|
|
125
|
+
React.createElement(DayCell, { date: w.thursday, month: month, day: (_k = (_j = props.DateTime) === null || _j === void 0 ? void 0 : _j.date()) !== null && _k !== void 0 ? _k : -1, onClick: function (evt) { evt.stopPropagation(); setDate(w.thursday); } }),
|
|
126
|
+
React.createElement(DayCell, { date: w.friday, month: month, day: (_m = (_l = props.DateTime) === null || _l === void 0 ? void 0 : _l.date()) !== null && _m !== void 0 ? _m : -1, onClick: function (evt) { evt.stopPropagation(); setDate(w.friday); } }),
|
|
127
|
+
React.createElement(DayCell, { date: w.saturday, month: month, day: (_p = (_o = props.DateTime) === null || _o === void 0 ? void 0 : _o.date()) !== null && _p !== void 0 ? _p : -1, onClick: function (evt) { evt.stopPropagation(); setDate(w.saturday); } }));
|
|
128
|
+
}) : null,
|
|
124
129
|
mode === 'year' ? React.createElement(React.Fragment, null,
|
|
125
130
|
React.createElement("tr", { style: { height: 54, lineHeight: '54px' } },
|
|
126
131
|
React.createElement(MonthCell, { date: moment([year, 0, 1]), month: month, onClick: function (evt) { evt.stopPropagation(); setMode('month'); setMonth(0); } }),
|
package/lib/DateTimeUI/Clock.js
CHANGED
|
@@ -26,25 +26,28 @@ var React = require("react");
|
|
|
26
26
|
var moment = require("moment");
|
|
27
27
|
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
28
28
|
function Clock(props) {
|
|
29
|
-
var _a
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
29
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
30
|
+
var _j = React.useState((_b = (_a = props.DateTime) === null || _a === void 0 ? void 0 : _a.format("HH")) !== null && _b !== void 0 ? _b : '00'), hour = _j[0], setHour = _j[1];
|
|
31
|
+
var _k = React.useState((_d = (_c = props.DateTime) === null || _c === void 0 ? void 0 : _c.format("mm")) !== null && _d !== void 0 ? _d : '00'), minute = _k[0], setMinute = _k[1];
|
|
32
|
+
var _l = React.useState((_f = (_e = props.DateTime) === null || _e === void 0 ? void 0 : _e.format("ss")) !== null && _f !== void 0 ? _f : '00'), second = _l[0], setSecond = _l[1];
|
|
33
|
+
var _m = React.useState((_h = (_g = props.DateTime) === null || _g === void 0 ? void 0 : _g.format("SSS")) !== null && _h !== void 0 ? _h : '000'), millisecond = _m[0], setMilliSecond = _m[1];
|
|
34
|
+
var _o = React.useState('none'), hover = _o[0], setHover = _o[1];
|
|
34
35
|
React.useEffect(function () {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
37
|
+
setHour((_b = (_a = props.DateTime) === null || _a === void 0 ? void 0 : _a.format("HH")) !== null && _b !== void 0 ? _b : '00');
|
|
38
|
+
setMinute((_d = (_c = props.DateTime) === null || _c === void 0 ? void 0 : _c.format("mm")) !== null && _d !== void 0 ? _d : '00');
|
|
39
|
+
setSecond((_f = (_e = props.DateTime) === null || _e === void 0 ? void 0 : _e.format("ss")) !== null && _f !== void 0 ? _f : '00');
|
|
40
|
+
setMilliSecond((_h = (_g = props.DateTime) === null || _g === void 0 ? void 0 : _g.format("SSS")) !== null && _h !== void 0 ? _h : '000');
|
|
39
41
|
}, [props.DateTime]);
|
|
40
42
|
React.useEffect(function () {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
41
44
|
var h = parseInt(hour, 10);
|
|
42
45
|
var m = parseInt(minute, 10);
|
|
43
46
|
var s = parseInt(second, 10);
|
|
44
47
|
var ms = parseInt(millisecond, 10);
|
|
45
48
|
if (isNaN(h) || isNaN(m) || isNaN(s) || isNaN(ms))
|
|
46
49
|
return;
|
|
47
|
-
if (h !== props.DateTime.hour() || m !== props.DateTime.minute() || s !== props.DateTime.second() || ms !== props.DateTime.millisecond()) {
|
|
50
|
+
if (h !== ((_a = props.DateTime) === null || _a === void 0 ? void 0 : _a.hour()) || m !== ((_b = props.DateTime) === null || _b === void 0 ? void 0 : _b.minute()) || s !== ((_c = props.DateTime) === null || _c === void 0 ? void 0 : _c.second()) || ms !== ((_d = props.DateTime) === null || _d === void 0 ? void 0 : _d.millisecond())) {
|
|
48
51
|
var d = moment(props.DateTime);
|
|
49
52
|
if (!d.isValid())
|
|
50
53
|
d = moment.utc().startOf('d');
|
|
@@ -3,7 +3,7 @@ import * as moment from 'moment';
|
|
|
3
3
|
import { TimeUnit } from '../DatePicker';
|
|
4
4
|
import { Accuracy } from './Clock';
|
|
5
5
|
interface IProps {
|
|
6
|
-
DateTime: moment.Moment;
|
|
6
|
+
DateTime: moment.Moment | undefined;
|
|
7
7
|
Setter: (record: moment.Moment) => void;
|
|
8
8
|
Valid: boolean;
|
|
9
9
|
Feedback?: string;
|
package/lib/Input.js
CHANGED
|
@@ -39,31 +39,31 @@ var React = require("react");
|
|
|
39
39
|
var HelperMessage_1 = require("./HelperMessage");
|
|
40
40
|
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
41
41
|
function Input(props) {
|
|
42
|
+
var internal = React.useRef(false);
|
|
42
43
|
var _a = React.useState(""), guid = _a[0], setGuid = _a[1];
|
|
43
44
|
var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
|
|
44
|
-
var _c = React.useState(
|
|
45
|
-
var _d = React.useState(''), heldVal = _d[0], setHeldVal = _d[1]; // Need to buffer tha value because parseFloat will throw away trailing decimals or zeros
|
|
45
|
+
var _c = React.useState(''), heldVal = _c[0], setHeldVal = _c[1]; // Need to buffer tha value because parseFloat will throw away trailing decimals or zeros
|
|
46
46
|
React.useEffect(function () {
|
|
47
47
|
setGuid((0, helper_functions_1.CreateGuid)());
|
|
48
48
|
}, []);
|
|
49
49
|
React.useEffect(function () {
|
|
50
|
-
if (!internal) {
|
|
50
|
+
if (!internal.current) {
|
|
51
51
|
setHeldVal(props.Record[props.Field] == null ? '' : props.Record[props.Field].toString());
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
internal.current = false;
|
|
54
54
|
}, [props.Record[props.Field]]);
|
|
55
55
|
function onBlur() {
|
|
56
56
|
var _a;
|
|
57
57
|
var _b;
|
|
58
58
|
var allowNull = props.AllowNull === undefined ? false : props.AllowNull;
|
|
59
59
|
if (!allowNull && (props.Type === 'number' || props.Type === 'integer') && heldVal === '') {
|
|
60
|
-
|
|
60
|
+
internal.current = false;
|
|
61
61
|
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = (_b = props.DefaultValue) !== null && _b !== void 0 ? _b : 0, _a)));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
function valueChange(value) {
|
|
65
65
|
var _a, _b, _c;
|
|
66
|
-
|
|
66
|
+
internal.current = true;
|
|
67
67
|
var allowNull = props.AllowNull === undefined ? false : props.AllowNull;
|
|
68
68
|
if (props.Type === 'number') {
|
|
69
69
|
var v = (value.length > 0 && value[0] === '.' ? ("0" + value) : value);
|
|
@@ -101,6 +101,6 @@ function Input(props) {
|
|
|
101
101
|
React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
|
|
102
102
|
: null,
|
|
103
103
|
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.target.value); }, value: heldVal, disabled: props.Disabled == null ? false : props.Disabled, onBlur: onBlur, step: 'any' }),
|
|
104
|
-
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field + ' is a required field.' : props.Feedback)));
|
|
104
|
+
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field.toString() + ' is a required field.' : props.Feedback)));
|
|
105
105
|
}
|
|
106
106
|
exports.default = Input;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
interface IProps<T> {
|
|
3
|
+
Record: T;
|
|
4
|
+
Field: keyof T;
|
|
5
|
+
Setter: (record: T) => void;
|
|
6
|
+
Valid: (field: keyof T) => boolean;
|
|
7
|
+
Label?: string;
|
|
8
|
+
Feedback?: string;
|
|
9
|
+
InputDisabled?: boolean;
|
|
10
|
+
Type?: 'number' | 'text' | 'password' | 'email' | 'color' | 'integer';
|
|
11
|
+
Help?: string | JSX.Element;
|
|
12
|
+
InputStyle?: React.CSSProperties;
|
|
13
|
+
AllowNull?: boolean;
|
|
14
|
+
Size?: 'small' | 'large';
|
|
15
|
+
DefaultValue?: number;
|
|
16
|
+
OnBtnClick: (evt: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
17
|
+
BtnLabel: string;
|
|
18
|
+
BtnClass?: string;
|
|
19
|
+
BtnDisabled?: boolean;
|
|
20
|
+
BtnStyle?: React.CSSProperties;
|
|
21
|
+
}
|
|
22
|
+
declare function InputWithButton<T>(props: IProps<T>): JSX.Element;
|
|
23
|
+
export default InputWithButton;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// InputWithButton.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 licenses this file to you under the MIT License (MIT), the "License"; you may not use this
|
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
|
11
|
+
//
|
|
12
|
+
// http://opensource.org/licenses/MIT
|
|
13
|
+
//
|
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
|
16
|
+
// License for the specific language governing permissions and limitations.
|
|
17
|
+
//
|
|
18
|
+
// Code Modification History:
|
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
|
20
|
+
// 05/02/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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
var React = require("react");
|
|
37
|
+
var HelperMessage_1 = require("./HelperMessage");
|
|
38
|
+
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
39
|
+
function InputWithButton(props) {
|
|
40
|
+
var internal = React.useRef(false);
|
|
41
|
+
var _a = React.useState(""), guid = _a[0], setGuid = _a[1];
|
|
42
|
+
var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
|
|
43
|
+
var _c = React.useState(''), heldVal = _c[0], setHeldVal = _c[1]; // Need to buffer tha value because parseFloat will throw away trailing decimals or zeros
|
|
44
|
+
React.useEffect(function () {
|
|
45
|
+
setGuid((0, helper_functions_1.CreateGuid)());
|
|
46
|
+
}, []);
|
|
47
|
+
React.useEffect(function () {
|
|
48
|
+
if (!internal.current) {
|
|
49
|
+
setHeldVal(props.Record[props.Field] == null ? '' : props.Record[props.Field].toString());
|
|
50
|
+
}
|
|
51
|
+
internal.current = false;
|
|
52
|
+
}, [props.Record[props.Field]]);
|
|
53
|
+
function onBlur() {
|
|
54
|
+
var _a;
|
|
55
|
+
var _b;
|
|
56
|
+
var allowNull = props.AllowNull === undefined ? false : props.AllowNull;
|
|
57
|
+
if (!allowNull && (props.Type === 'number' || props.Type === 'integer') && heldVal === '') {
|
|
58
|
+
internal.current = false;
|
|
59
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = (_b = props.DefaultValue) !== null && _b !== void 0 ? _b : 0, _a)));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function valueChange(value) {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
internal.current = true;
|
|
65
|
+
var allowNull = props.AllowNull === undefined ? false : props.AllowNull;
|
|
66
|
+
if (props.Type === 'number') {
|
|
67
|
+
var v = (value.length > 0 && value[0] === '.' ? ("0" + value) : value);
|
|
68
|
+
if ((0, helper_functions_1.IsNumber)(v) || (v === '' && allowNull)) {
|
|
69
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = v !== '' ? parseFloat(v) : null, _a)));
|
|
70
|
+
setHeldVal(v);
|
|
71
|
+
}
|
|
72
|
+
else if (v === '') {
|
|
73
|
+
setHeldVal(v);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (props.Type === 'integer') {
|
|
77
|
+
if ((0, helper_functions_1.IsInteger)(value) || (value === '' && allowNull)) {
|
|
78
|
+
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = value !== '' ? parseFloat(value) : null, _b)));
|
|
79
|
+
setHeldVal(value);
|
|
80
|
+
}
|
|
81
|
+
else if (value === '') {
|
|
82
|
+
setHeldVal(value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
props.Setter(__assign(__assign({}, props.Record), (_c = {}, _c[props.Field] = value !== '' ? value : null, _c)));
|
|
87
|
+
setHeldVal(value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var showLabel = props.Label !== "";
|
|
91
|
+
var showHelpIcon = props.Help !== undefined;
|
|
92
|
+
var label = props.Label === undefined ? props.Field : props.Label;
|
|
93
|
+
return (React.createElement("div", { className: "form-group " + (props.Size === 'large' ? 'form-group-lg' : '') + (props.Size === 'small' ? 'form-group-sm' : ''), style: props.InputStyle },
|
|
94
|
+
showHelpIcon || showLabel ?
|
|
95
|
+
React.createElement("label", null,
|
|
96
|
+
showLabel ? label : '',
|
|
97
|
+
showHelpIcon ? 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,
|
|
98
|
+
showHelpIcon ?
|
|
99
|
+
React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
|
|
100
|
+
: null,
|
|
101
|
+
React.createElement("div", { className: "input-group" },
|
|
102
|
+
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.target.value); }, value: heldVal, disabled: props.InputDisabled == null ? false : props.InputDisabled, onBlur: onBlur, step: 'any' }),
|
|
103
|
+
React.createElement("div", { className: "input-group-prepend" },
|
|
104
|
+
React.createElement("button", { className: props.BtnClass != null ? props.BtnClass : "btn btn-outline-secondary", style: props.BtnStyle, disabled: props.BtnDisabled == null ? false : props.BtnDisabled, type: "button", onClick: function (evt) { return props.OnBtnClick(evt); } }, props.BtnLabel)),
|
|
105
|
+
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field.toString() + ' is a required field.' : props.Feedback))));
|
|
106
|
+
}
|
|
107
|
+
exports.default = InputWithButton;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface IProps<T> {
|
|
3
|
+
Record: T;
|
|
4
|
+
Field: keyof T;
|
|
5
|
+
Setter: (record: T) => void;
|
|
6
|
+
Label?: string;
|
|
7
|
+
Disabled?: boolean;
|
|
8
|
+
Help?: string | JSX.Element;
|
|
9
|
+
}
|
|
10
|
+
export default function ToggleSwitch<T>(props: IProps<T>): JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// ToggleSwitch.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
|
+
// 04/19/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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
var React = require("react");
|
|
37
|
+
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
38
|
+
var HelperMessage_1 = require("./HelperMessage");
|
|
39
|
+
function ToggleSwitch(props) {
|
|
40
|
+
var _a = React.useState(""), helpID = _a[0], setHelpID = _a[1];
|
|
41
|
+
var _b = React.useState(''), switchID = _b[0], setSwitchID = _b[1];
|
|
42
|
+
var _c = React.useState(false), showHelp = _c[0], setShowHelp = _c[1];
|
|
43
|
+
var showHelpIcon = props.Help !== undefined;
|
|
44
|
+
React.useEffect(function () {
|
|
45
|
+
setHelpID((0, helper_functions_1.CreateGuid)());
|
|
46
|
+
setSwitchID((0, helper_functions_1.CreateGuid)());
|
|
47
|
+
}, []);
|
|
48
|
+
return (React.createElement("div", { className: "custom-control custom-switch", "data-help": helpID },
|
|
49
|
+
React.createElement("input", { type: "checkbox", className: "custom-control-input", onChange: function (evt) {
|
|
50
|
+
var record = __assign({}, props.Record);
|
|
51
|
+
record[props.Field] = evt.target.checked;
|
|
52
|
+
props.Setter(record);
|
|
53
|
+
}, value: props.Record[props.Field] ? 'on' : 'off', checked: props.Record[props.Field], disabled: props.Disabled == null ? false : props.Disabled, id: switchID }),
|
|
54
|
+
React.createElement("label", { className: "custom-control-label", htmlFor: switchID }, props.Label == null ? props.Field : props.Label),
|
|
55
|
+
showHelpIcon ?
|
|
56
|
+
React.createElement(React.Fragment, null,
|
|
57
|
+
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); } }, "?"),
|
|
58
|
+
React.createElement(HelperMessage_1.default, { Show: showHelp, Target: helpID, Zindex: 9999 }, props.Help))
|
|
59
|
+
: null));
|
|
60
|
+
}
|
|
61
|
+
exports.default = ToggleSwitch;
|
package/lib/index.d.ts
CHANGED
|
@@ -13,4 +13,6 @@ import TimePicker from './TimePicker';
|
|
|
13
13
|
import StylableSelect from './StylableSelect';
|
|
14
14
|
import ColorPicker from './ColorPicker';
|
|
15
15
|
import SearchableSelect from './SearchableSelect';
|
|
16
|
-
|
|
16
|
+
import ToggleSwitch from './ToggleSwitch';
|
|
17
|
+
import InputWithButton from './InputWithButton';
|
|
18
|
+
export { CheckBox, Input, DatePicker, Select, TextArea, DateRangePicker, EnumCheckBoxes, ArrayMultiSelect, ArrayCheckBoxes, MultiCheckBoxSelect, DoubleInput, TimePicker, StylableSelect, ColorPicker, SearchableSelect, ToggleSwitch, InputWithButton };
|
package/lib/index.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
//
|
|
23
23
|
// ******************************************************************************************************
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
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.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");
|
|
@@ -53,3 +53,7 @@ var ColorPicker_1 = require("./ColorPicker");
|
|
|
53
53
|
exports.ColorPicker = ColorPicker_1.default;
|
|
54
54
|
var SearchableSelect_1 = require("./SearchableSelect");
|
|
55
55
|
exports.SearchableSelect = SearchableSelect_1.default;
|
|
56
|
+
var ToggleSwitch_1 = require("./ToggleSwitch");
|
|
57
|
+
exports.ToggleSwitch = ToggleSwitch_1.default;
|
|
58
|
+
var InputWithButton_1 = require("./InputWithButton");
|
|
59
|
+
exports.InputWithButton = InputWithButton_1.default;
|