@widergy/energy-ui 3.59.2 → 3.59.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.59.3](https://github.com/widergy/energy-ui/compare/v3.59.2...v3.59.3) (2025-02-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * [UGMC-907] date range and validations ([#571](https://github.com/widergy/energy-ui/issues/571)) ([9163212](https://github.com/widergy/energy-ui/commit/9163212229edd036516d94038eb49200e1b177c5))
7
+
1
8
  ## [3.59.2](https://github.com/widergy/energy-ui/compare/v3.59.1...v3.59.2) (2025-02-13)
2
9
 
3
10
 
@@ -54,7 +54,7 @@ class CustomUtils extends _dayjs.default {
54
54
  }
55
55
  }
56
56
  const UTDatePicker = _ref => {
57
- var _field$configuration, _field$configuration2;
57
+ var _field$configuration, _field$configuration2, _field$configuration3;
58
58
  let {
59
59
  classes: themeClasses,
60
60
  classNames,
@@ -81,16 +81,22 @@ const UTDatePicker = _ref => {
81
81
  const classes = (0, _react.useMemo)(() => (0, _classesUtils.mergeClasses)(themeClasses, classNames), [classNames]);
82
82
  const configMask = (field === null || field === void 0 || (_field$configuration = field.configuration) === null || _field$configuration === void 0 ? void 0 : _field$configuration.date_mask) || _constants.OUTPUT_LABEL_MASK;
83
83
  const onlyPastMonth = ((_field$configuration2 = field.configuration) === null || _field$configuration2 === void 0 || (_field$configuration2 = _field$configuration2.customDateValidations) === null || _field$configuration2 === void 0 || (_field$configuration2 = _field$configuration2.onlyPastMonth) === null || _field$configuration2 === void 0 ? void 0 : _field$configuration2.active) || false;
84
+ const avoidFutureDates = ((_field$configuration3 = field.configuration) === null || _field$configuration3 === void 0 || (_field$configuration3 = _field$configuration3.customDateValidations) === null || _field$configuration3 === void 0 || (_field$configuration3 = _field$configuration3.avoidFutureDates) === null || _field$configuration3 === void 0 ? void 0 : _field$configuration3.active) || false;
84
85
  const {
85
- minDate = undefined,
86
- maxDate = undefined
87
- } = (onlyPastMonth ? (0, _utils.getPastMonthDates)() : range) || {};
86
+ minDate,
87
+ maxDate
88
+ } = (onlyPastMonth ? (0, _utils.getPastMonthDates)() : avoidFutureDates ? (0, _utils.getMaxDate)() : range) || {};
88
89
  const [pickedDate, setPickedDate] = (0, _react.useState)(null);
89
90
  const [internalError, setInternalError] = (0, _react.useState)(null);
90
91
  const handleChange = date => {
91
92
  setPickedDate(date);
92
93
  const newValue = (0, _dayjs2.default)(date, _constants.OUTPUT_LABEL_MASK, true);
93
- if (newValue.isValid()) input.onChange(newValue.format(configMask));else input.onChange('');
94
+ if ((0, _utils.isValidDate)({
95
+ avoidFutureDates,
96
+ newValue,
97
+ onlyPastMonth,
98
+ range
99
+ })) input.onChange(newValue.format(configMask));else input.onChange('');
94
100
  };
95
101
  (0, _react.useEffect)(() => {
96
102
  if (!input.value && pickedDate !== null && pickedDate !== void 0 && pickedDate.isValid()) setPickedDate(null);else if ((0, _utils.dateMatchesFormat)(input.value, configMask)) setPickedDate((0, _dayjs2.default)(input.value, configMask));
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isSelected = exports.getPastMonthDates = exports.dateMatchesFormat = void 0;
6
+ exports.isValidDate = exports.isSelected = exports.getPastMonthDates = exports.getMaxDate = exports.dateMatchesFormat = void 0;
7
7
  var _dayjs = _interopRequireDefault(require("dayjs"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  const isSelected = (date, selectedDate) => selectedDate && date.isSame(selectedDate, 'day');
@@ -19,4 +19,32 @@ const getPastMonthDates = () => {
19
19
  maxDate: new Date(currentYear, currentMonth, 0)
20
20
  };
21
21
  };
22
- exports.getPastMonthDates = getPastMonthDates;
22
+ exports.getPastMonthDates = getPastMonthDates;
23
+ const getMaxDate = () => {
24
+ const currentDate = new Date();
25
+ return {
26
+ maxDate: currentDate
27
+ };
28
+ };
29
+ exports.getMaxDate = getMaxDate;
30
+ const avoidFutureDatesValidation = date => !(0, _dayjs.default)().isBefore(date);
31
+ const rangeValidation = (date, range) => {
32
+ const {
33
+ minDate,
34
+ maxDate
35
+ } = range;
36
+ return date.isBetween(minDate, maxDate, null, '[]');
37
+ };
38
+ const isValidDate = _ref => {
39
+ let {
40
+ avoidFutureDates,
41
+ newValue,
42
+ onlyPastMonth,
43
+ range
44
+ } = _ref;
45
+ if (avoidFutureDates && !avoidFutureDatesValidation(newValue)) return false;
46
+ if (onlyPastMonth && !rangeValidation(newValue, getPastMonthDates())) return false;
47
+ if (range && !rangeValidation(newValue, range)) return false;
48
+ return newValue.isValid();
49
+ };
50
+ exports.isValidDate = isValidDate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "3.59.2",
3
+ "version": "3.59.3",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",