@gpa-gemstone/react-forms 1.1.56 → 1.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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
- setPickerRecord(parse(props.Record));
62
- setBoxRecord(parse(props.Record).format(boxFormat));
63
- recordChange.current = false;
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
- setFeedbackMessage("");
65
+ setPickerRecord(undefined);
66
+ setBoxRecord('');
85
67
  }
86
- if (((_c = props.AllowEmpty) !== null && _c !== void 0 ? _c : false) && boxRecord.length === 0 && !valid && props.Record !== null)
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.Field.toString() + " is a required field.";
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
- var _a;
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) { setPickerRecord(d); recordChange.current = true; if (props.Type === 'date')
189
- setShowOverlay(false); }, Show: showOverlay, DateTime: pickerRecord, Valid: props.Valid(props.Field), Top: top, Center: left, Type: props.Type === undefined ? 'date' : props.Type, Accuracy: props.Accuracy })));
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;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import * as moment from 'moment';
3
3
  interface IProps {
4
- DateTime: moment.Moment;
4
+ DateTime: moment.Moment | undefined;
5
5
  Setter: (record: moment.Moment) => void;
6
6
  }
7
7
  export default function Calender(props: IProps): JSX.Element;
@@ -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 = React.useState([]), weeks = _a[0], setWeeks = _a[1];
29
- var _b = React.useState(props.DateTime.month()), month = _b[0], setMonth = _b[1];
30
- var _c = React.useState(props.DateTime.year()), year = _c[0], setYear = _c[1];
31
- var _d = React.useState('month'), mode = _d[0], setMode = _d[1];
32
- var _e = React.useState('None'), hover = _e[0], setHover = _e[1];
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
- setMonth(isNaN(props.DateTime.month()) ? 0 : props.DateTime.month());
35
- setYear(isNaN(props.DateTime.year()) ? moment.utc().year() : props.DateTime.year());
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) { return React.createElement("tr", { key: w.sunday.isoWeek(), style: { height: 20, lineHeight: '20px' } },
117
- React.createElement(DayCell, { date: w.sunday, month: month, day: props.DateTime.date(), onClick: function (evt) { evt.stopPropagation(); setDate(w.sunday); } }),
118
- React.createElement(DayCell, { date: w.monday, month: month, day: props.DateTime.date(), onClick: function (evt) { evt.stopPropagation(); setDate(w.monday); } }),
119
- React.createElement(DayCell, { date: w.tuesday, month: month, day: props.DateTime.date(), onClick: function (evt) { evt.stopPropagation(); setDate(w.tuesday); } }),
120
- React.createElement(DayCell, { date: w.wednesday, month: month, day: props.DateTime.date(), onClick: function (evt) { evt.stopPropagation(); setDate(w.wednesday); } }),
121
- React.createElement(DayCell, { date: w.thursday, month: month, day: props.DateTime.date(), onClick: function (evt) { evt.stopPropagation(); setDate(w.thursday); } }),
122
- React.createElement(DayCell, { date: w.friday, month: month, day: props.DateTime.date(), onClick: function (evt) { evt.stopPropagation(); setDate(w.friday); } }),
123
- React.createElement(DayCell, { date: w.saturday, month: month, day: props.DateTime.date(), onClick: function (evt) { evt.stopPropagation(); setDate(w.saturday); } })); }) : null,
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); } }),
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import * as moment from 'moment';
3
3
  interface IProps {
4
- DateTime: moment.Moment;
4
+ DateTime: moment.Moment | undefined;
5
5
  Setter: (record: moment.Moment) => void;
6
6
  Accuracy?: Accuracy;
7
7
  }
@@ -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 = React.useState(props.DateTime.format("HH")), hour = _a[0], setHour = _a[1];
30
- var _b = React.useState(props.DateTime.format("mm")), minute = _b[0], setMinute = _b[1];
31
- var _c = React.useState(props.DateTime.format("ss")), second = _c[0], setSecond = _c[1];
32
- var _d = React.useState(props.DateTime.format("SSS")), millisecond = _d[0], setMilliSecond = _d[1];
33
- var _e = React.useState('none'), hover = _e[0], setHover = _e[1];
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
- setHour(props.DateTime.format("HH"));
36
- setMinute(props.DateTime.format("mm"));
37
- setSecond(props.DateTime.format("ss"));
38
- setMilliSecond(props.DateTime.format("SSS"));
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(false), internal = _c[0], setInternal = _c[1];
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
- setInternal(false);
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
- setInternal(false);
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
- setInternal(true);
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,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,5 @@ import TimePicker from './TimePicker';
13
13
  import StylableSelect from './StylableSelect';
14
14
  import ColorPicker from './ColorPicker';
15
15
  import SearchableSelect from './SearchableSelect';
16
- export { CheckBox, Input, DatePicker, Select, TextArea, DateRangePicker, EnumCheckBoxes, ArrayMultiSelect, ArrayCheckBoxes, MultiCheckBoxSelect, DoubleInput, TimePicker, StylableSelect, ColorPicker, SearchableSelect };
16
+ import ToggleSwitch from './ToggleSwitch';
17
+ export { CheckBox, Input, DatePicker, Select, TextArea, DateRangePicker, EnumCheckBoxes, ArrayMultiSelect, ArrayCheckBoxes, MultiCheckBoxSelect, DoubleInput, TimePicker, StylableSelect, ColorPicker, SearchableSelect, ToggleSwitch };
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.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,5 @@ 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.56",
3
+ "version": "1.1.57",
4
4
  "description": "React Form modules for gpa webapps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",