hrm_ui_lib 2.5.4 → 2.5.5

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.
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { useRef } from 'react';
13
+ import { useRef, useState } from 'react';
14
14
  import dayjs from 'dayjs';
15
15
  import DatePicker from 'react-datepicker';
16
16
  import { Input } from '../../Input';
@@ -19,6 +19,7 @@ import { useImportFilesDynamically } from '../hooks';
19
19
  import IconClock from '../../SVGIcons/IconClock';
20
20
  export const TimePickerDesktop = (props) => {
21
21
  const { value, currentTime, name, setFieldValue, label, size, dataId, changeHandler, required, format = 'HH:mm', locale = 'hy', hasError } = props, rest = __rest(props, ["value", "currentTime", "name", "setFieldValue", "label", "size", "dataId", "changeHandler", "required", "format", "locale", "hasError"]);
22
+ const [time, setTime] = useState();
22
23
  const dateInitialValue = value !== undefined && Object.prototype.toString.call(value) === '[object Date]'
23
24
  ? value
24
25
  : currentTime;
@@ -39,7 +40,31 @@ export const TimePickerDesktop = (props) => {
39
40
  (_b = calendarRef.current) === null || _b === void 0 ? void 0 : _b.setOpen(!isOpen);
40
41
  }
41
42
  };
43
+ const formatAndSetTime = () => {
44
+ const _date = new Date();
45
+ _date.setHours(0, 0);
46
+ if (!time) {
47
+ onChange(_date);
48
+ return;
49
+ }
50
+ if (time.includes(':') && time[2] !== ':') {
51
+ onChange(_date);
52
+ return;
53
+ }
54
+ const t = time.replace(':', '');
55
+ if (t.length === 4) {
56
+ const hours = Number(t.slice(0, 2));
57
+ const minutes = Number(t.slice(2, 4));
58
+ if (hours < 24 && minutes < 60) {
59
+ _date.setHours(hours, minutes);
60
+ }
61
+ }
62
+ onChange(_date);
63
+ };
64
+ const onInputChange = (e) => {
65
+ setTime(e.target.value);
66
+ };
42
67
  return (_jsxs("div", { className: "picker-container input__inner", children: [_jsx(Label, { text: label, required: required, invalid: hasError }), _jsx(DatePicker, Object.assign({ selected: dayjs(dateInitialValue).isValid() ? dateInitialValue : null, locale: locale, showTimeSelect: true, showTimeSelectOnly: true, dateFormat: format,
43
68
  // @ts-ignore
44
- ref: calendarRef }, rest, { onChange: onChange, customInput: _jsx(Input, { disabled: rest.disabled, dataId: dataId, size: size, rightIconProps: { Component: IconClock, onClick: openDatepicker } }) }))] }));
69
+ ref: calendarRef }, rest, { onChange: onChange, customInput: _jsx(Input, { handleChange: onInputChange, handleBlurEvent: formatAndSetTime, disabled: rest.disabled, dataId: dataId, size: size, rightIconProps: { Component: IconClock, onClick: openDatepicker } }) }))] }));
45
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hrm_ui_lib",
3
- "version": "2.5.4",
3
+ "version": "2.5.5",
4
4
  "description": "UI library for Dino",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",