@gpa-gemstone/react-forms 1.1.59 → 1.1.61

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.
Files changed (47) hide show
  1. package/lib/ArrayCheckBoxes.d.ts +33 -11
  2. package/lib/ArrayCheckBoxes.js +81 -79
  3. package/lib/ArrayMultiSelect.d.ts +47 -13
  4. package/lib/ArrayMultiSelect.js +49 -47
  5. package/lib/CheckBox.d.ts +37 -11
  6. package/lib/CheckBox.js +62 -60
  7. package/lib/ColorPicker.d.ts +59 -15
  8. package/lib/ColorPicker.js +114 -114
  9. package/lib/DatePicker.d.ts +23 -21
  10. package/lib/DatePicker.js +221 -214
  11. package/lib/DateRangePicker.d.ts +64 -13
  12. package/lib/DateRangePicker.js +143 -132
  13. package/lib/DateTimeUI/Calender.d.ts +7 -8
  14. package/lib/DateTimeUI/Calender.js +180 -180
  15. package/lib/DateTimeUI/Clock.d.ts +9 -10
  16. package/lib/DateTimeUI/Clock.js +153 -153
  17. package/lib/DateTimeUI/DateTimePopup.d.ts +16 -17
  18. package/lib/DateTimeUI/DateTimePopup.js +59 -59
  19. package/lib/DoubleInput.d.ts +58 -12
  20. package/lib/DoubleInput.js +55 -51
  21. package/lib/EnumCheckBoxes.d.ts +41 -9
  22. package/lib/EnumCheckBoxes.js +65 -58
  23. package/lib/HelperMessage.d.ts +37 -10
  24. package/lib/HelperMessage.js +93 -83
  25. package/lib/Input.d.ts +80 -18
  26. package/lib/Input.js +111 -106
  27. package/lib/InputWithButton.d.ts +109 -23
  28. package/lib/InputWithButton.js +107 -107
  29. package/lib/MutliCheckBoxSelect.d.ts +42 -18
  30. package/lib/MutliCheckBoxSelect.js +110 -104
  31. package/lib/RadioButtons.d.ts +15 -0
  32. package/lib/RadioButtons.js +62 -0
  33. package/lib/SearchableSelect.d.ts +60 -18
  34. package/lib/SearchableSelect.js +84 -85
  35. package/lib/Select.d.ts +57 -17
  36. package/lib/Select.js +84 -80
  37. package/lib/StylableSelect.d.ts +53 -17
  38. package/lib/StylableSelect.js +106 -100
  39. package/lib/TextArea.d.ts +54 -14
  40. package/lib/TextArea.js +76 -72
  41. package/lib/TimePicker.d.ts +50 -11
  42. package/lib/TimePicker.js +60 -51
  43. package/lib/ToggleSwitch.d.ts +44 -12
  44. package/lib/ToggleSwitch.js +57 -61
  45. package/lib/index.d.ts +19 -18
  46. package/lib/index.js +61 -59
  47. package/package.json +4 -3
@@ -1,132 +1,143 @@
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
- var moment = require("moment");
38
- function DateRangePicker(props) {
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];
42
- // Tracks weather or not props.Record changes are due to internal input boxes or externally
43
- var _c = React.useState(false), internal = _c[0], setInternal = _c[1];
44
- // Adds a buffer between the outside props and what the box is reading to prevent box overwriting every render with a keystroke
45
- var _d = React.useState(ParseRecord()), boxRecord = _d[0], setBoxRecord = _d[1];
46
- // Formats that will be used for dateBoxes
47
- var boxFormat = "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]hh:mm:ss");
48
- var recordFormat = props.Format !== undefined ? props.Format : "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]hh:mm:ss.SSS[Z]");
49
- React.useEffect(function () {
50
- setRange(ToRange(moment(props.Record[props.ToField], recordFormat).diff(moment(props.Record[props.FromField], recordFormat), 'days')));
51
- if (!internal)
52
- setBoxRecord(ParseRecord());
53
- setInternal(false);
54
- }, [props.Record]);
55
- React.useEffect(function () {
56
- var _a, _b;
57
- setRange(formRange);
58
- var toTime = moment(props.Record[props.FromField], recordFormat).add(GetDays(formRange), 'days');
59
- props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.ToField] = toTime.format(recordFormat), _a)));
60
- setBoxRecord(__assign(__assign({}, boxRecord), (_b = {}, _b[props.ToField] = toTime.format(boxFormat), _b)));
61
- }, [formRange]);
62
- function ParseRecord() {
63
- var record = __assign({}, props.Record);
64
- var ParseExternalField = function (field) { return props.Record[field] === null ? '' : moment(props.Record[field], recordFormat).format(boxFormat); };
65
- record[props.ToField] = ParseExternalField(props.ToField);
66
- record[props.FromField] = ParseExternalField(props.FromField);
67
- return record;
68
- }
69
- function GetDays(val) {
70
- if (val === '1 Day')
71
- return 1;
72
- if (val === '7 Days')
73
- return 7;
74
- if (val === '30 Days')
75
- return 30;
76
- if (val === '90 Days')
77
- return 90;
78
- if (val === '180 Days')
79
- return 180;
80
- if (val === '365 Days')
81
- return 365;
82
- return 0;
83
- }
84
- function ToRange(days) {
85
- if (days === 1)
86
- return ('1 Day');
87
- else if (days === 7)
88
- return ('7 Days');
89
- else if (days === 30)
90
- return ('30 Days');
91
- else if (days === 90)
92
- return ('90 Days');
93
- else if (days === 180)
94
- return ('180 Days');
95
- else if (days === 365)
96
- return ('365 Days');
97
- else
98
- return ('Custom');
99
- }
100
- function dateBox(field) {
101
- return React.createElement("div", { className: "col" },
102
- React.createElement("input", { className: "form-control" + (props.Valid(props.FromField, props.ToField) ? '' : ' is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
103
- var _a;
104
- var record = __assign({}, props.Record);
105
- if (evt.target.value !== '')
106
- record[field] = moment(evt.target.value, boxFormat).format(recordFormat);
107
- else
108
- record[field] = null;
109
- // These two updates should be batched together
110
- props.Setter(record);
111
- setBoxRecord(__assign(__assign({}, boxRecord), (_a = {}, _a[field] = evt.target.value, _a)));
112
- setInternal(true);
113
- }, value: boxRecord[field], disabled: props.Disabled === undefined ? false : props.Disabled }),
114
- field !== props.FromField ? null :
115
- React.createElement("div", { className: "invalid-feedback" }, props.Feedback === undefined ? 'From and to dates required, and from must be before to.' : props.Feedback));
116
- }
117
- return (React.createElement("div", { className: "form-group" },
118
- props.Label === "" ? null : React.createElement("label", null, props.Label),
119
- React.createElement("div", { className: "row" },
120
- React.createElement("div", { className: "col" },
121
- React.createElement("select", { className: "form-control", value: range, onChange: function (evt) { return setFormRange(evt.target.value); } },
122
- React.createElement("option", { value: "Custom" }, "Custom"),
123
- React.createElement("option", { value: "1 Day" }, "1 Day"),
124
- React.createElement("option", { value: "7 Days" }, "7 Days"),
125
- React.createElement("option", { value: "30 Days" }, "30 Days"),
126
- React.createElement("option", { value: "90 Days" }, "90 Days"),
127
- React.createElement("option", { value: "180 Days" }, "180 Days"),
128
- React.createElement("option", { value: "365 Days" }, "365 Days"))),
129
- dateBox(props.FromField),
130
- dateBox(props.ToField))));
131
- }
132
- 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
+ exports.default = DateRangePicker;
37
+ var React = require("react");
38
+ var moment = require("moment");
39
+ /**
40
+ * DateRangePicker Component.
41
+ * Allows users to select a date range either by choosing predefined durations or by specifying custom dates.
42
+ */
43
+ function DateRangePicker(props) {
44
+ // Range box vars, need a secondary var to avoid looping react hooks
45
+ var _a = React.useState('Custom'), formRange = _a[0], setFormRange = _a[1];
46
+ var _b = React.useState('Custom'), range = _b[0], setRange = _b[1];
47
+ // Tracks weather or not props.Record changes are due to internal input boxes or externally
48
+ var _c = React.useState(false), internal = _c[0], setInternal = _c[1];
49
+ // Adds a buffer between the outside props and what the box is reading to prevent box overwriting every render with a keystroke
50
+ var _d = React.useState(ParseRecord()), boxRecord = _d[0], setBoxRecord = _d[1];
51
+ // Formats that will be used for dateBoxes
52
+ var boxFormat = "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]hh:mm:ss");
53
+ var recordFormat = props.Format !== undefined ? props.Format : "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]hh:mm:ss.SSS[Z]");
54
+ // Effect for handling changes to the props.Record.
55
+ React.useEffect(function () {
56
+ setRange(ToRange(moment(props.Record[props.ToField], recordFormat).diff(moment(props.Record[props.FromField], recordFormat), 'days')));
57
+ if (!internal)
58
+ setBoxRecord(ParseRecord());
59
+ setInternal(false);
60
+ }, [props.Record]);
61
+ // Effect for handling changes to the formRange state.
62
+ React.useEffect(function () {
63
+ var _a, _b;
64
+ setRange(formRange);
65
+ var toTime = moment(props.Record[props.FromField], recordFormat).add(GetDays(formRange), 'days');
66
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.ToField] = toTime.format(recordFormat), _a)));
67
+ setBoxRecord(__assign(__assign({}, boxRecord), (_b = {}, _b[props.ToField] = toTime.format(boxFormat), _b)));
68
+ }, [formRange]);
69
+ // Parses the record for display in the date boxes.
70
+ function ParseRecord() {
71
+ var record = __assign({}, props.Record);
72
+ var ParseExternalField = function (field) { return props.Record[field] === null ? '' : moment(props.Record[field], recordFormat).format(boxFormat); };
73
+ record[props.ToField] = ParseExternalField(props.ToField);
74
+ record[props.FromField] = ParseExternalField(props.FromField);
75
+ return record;
76
+ }
77
+ // Converts the selected duration to a number of days.
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
+ // Maps a number of days to a Duration value.
94
+ function ToRange(days) {
95
+ if (days === 1)
96
+ return ('1 Day');
97
+ else if (days === 7)
98
+ return ('7 Days');
99
+ else if (days === 30)
100
+ return ('30 Days');
101
+ else if (days === 90)
102
+ return ('90 Days');
103
+ else if (days === 180)
104
+ return ('180 Days');
105
+ else if (days === 365)
106
+ return ('365 Days');
107
+ else
108
+ return ('Custom');
109
+ }
110
+ // Renders a date input box.
111
+ function dateBox(field) {
112
+ return React.createElement("div", { className: "col" },
113
+ React.createElement("input", { className: "form-control" + (props.Valid(props.FromField, props.ToField) ? '' : ' is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
114
+ var _a;
115
+ var record = __assign({}, props.Record);
116
+ if (evt.target.value !== '')
117
+ record[field] = moment(evt.target.value, boxFormat).format(recordFormat);
118
+ else
119
+ record[field] = null;
120
+ // These two updates should be batched together
121
+ props.Setter(record);
122
+ setBoxRecord(__assign(__assign({}, boxRecord), (_a = {}, _a[field] = evt.target.value, _a)));
123
+ setInternal(true);
124
+ }, value: boxRecord[field], disabled: props.Disabled === undefined ? false : props.Disabled }),
125
+ field !== props.FromField ? null :
126
+ React.createElement("div", { className: "invalid-feedback" }, props.Feedback === undefined ? 'From and to dates required, and from must be before to.' : props.Feedback));
127
+ }
128
+ // Main render method for the component.
129
+ return (React.createElement("div", { className: "form-group" },
130
+ props.Label === "" ? null : React.createElement("label", null, props.Label),
131
+ React.createElement("div", { className: "row" },
132
+ React.createElement("div", { className: "col" },
133
+ React.createElement("select", { className: "form-control", value: range, onChange: function (evt) { return setFormRange(evt.target.value); } },
134
+ React.createElement("option", { value: "Custom" }, "Custom"),
135
+ React.createElement("option", { value: "1 Day" }, "1 Day"),
136
+ React.createElement("option", { value: "7 Days" }, "7 Days"),
137
+ React.createElement("option", { value: "30 Days" }, "30 Days"),
138
+ React.createElement("option", { value: "90 Days" }, "90 Days"),
139
+ React.createElement("option", { value: "180 Days" }, "180 Days"),
140
+ React.createElement("option", { value: "365 Days" }, "365 Days"))),
141
+ dateBox(props.FromField),
142
+ dateBox(props.ToField))));
143
+ }
@@ -1,8 +1,7 @@
1
- /// <reference types="react" />
2
- import * as moment from 'moment';
3
- interface IProps {
4
- DateTime: moment.Moment | undefined;
5
- Setter: (record: moment.Moment) => void;
6
- }
7
- export default function Calender(props: IProps): JSX.Element;
8
- export {};
1
+ import * as moment from 'moment';
2
+ interface IProps {
3
+ DateTime: moment.Moment | undefined;
4
+ Setter: (record: moment.Moment) => void;
5
+ }
6
+ export default function Calender(props: IProps): JSX.Element;
7
+ export {};