wini-web-components 2.2.8 → 2.3.2

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 (63) hide show
  1. package/dist/component/button/button.d.ts +16 -16
  2. package/dist/component/button/button.js +39 -39
  3. package/dist/component/calendar/calendar.d.ts +30 -46
  4. package/dist/component/calendar/calendar.js +437 -432
  5. package/dist/component/checkbox/checkbox.d.ts +24 -22
  6. package/dist/component/checkbox/checkbox.js +120 -81
  7. package/dist/component/component-status.d.ts +8 -8
  8. package/dist/component/component-status.js +39 -39
  9. package/dist/component/date-picker/date-picker.d.ts +25 -36
  10. package/dist/component/date-picker/date-picker.js +362 -359
  11. package/dist/component/dialog/dialog.d.ts +36 -34
  12. package/dist/component/dialog/dialog.js +99 -97
  13. package/dist/component/import-file/import-file.d.ts +24 -36
  14. package/dist/component/import-file/import-file.js +154 -119
  15. package/dist/component/infinite-scroll/infinite-scroll.d.ts +17 -17
  16. package/dist/component/infinite-scroll/infinite-scroll.js +103 -103
  17. package/dist/component/input-multi-select/input-multi-select.d.ts +21 -38
  18. package/dist/component/input-multi-select/input-multi-select.js +334 -323
  19. package/dist/component/input-opt/input-opt.d.ts +21 -21
  20. package/dist/component/input-opt/input-opt.js +157 -147
  21. package/dist/component/number-picker/number-picker.d.ts +19 -19
  22. package/dist/component/number-picker/number-picker.js +137 -127
  23. package/dist/component/pagination/pagination.d.ts +13 -13
  24. package/dist/component/pagination/pagination.js +93 -82
  25. package/dist/component/popup/popup.d.ts +33 -33
  26. package/dist/component/popup/popup.js +138 -105
  27. package/dist/component/progress-bar/progress-bar.d.ts +16 -16
  28. package/dist/component/progress-bar/progress-bar.js +35 -36
  29. package/dist/component/progress-circle/progress-circle.d.ts +14 -14
  30. package/dist/component/progress-circle/progress-circle.js +30 -31
  31. package/dist/component/radio-button/radio-button.d.ts +20 -20
  32. package/dist/component/radio-button/radio-button.js +64 -64
  33. package/dist/component/rating/rating.d.ts +23 -23
  34. package/dist/component/rating/rating.js +73 -74
  35. package/dist/component/select1/select1.d.ts +31 -50
  36. package/dist/component/select1/select1.js +320 -309
  37. package/dist/component/slider/slider.d.ts +31 -31
  38. package/dist/component/slider/slider.js +80 -81
  39. package/dist/component/switch/switch.d.ts +23 -23
  40. package/dist/component/switch/switch.js +80 -81
  41. package/dist/component/table/table.d.ts +51 -51
  42. package/dist/component/table/table.js +119 -119
  43. package/dist/component/tag/tag.d.ts +17 -17
  44. package/dist/component/tag/tag.js +39 -39
  45. package/dist/component/text/text.d.ts +16 -16
  46. package/dist/component/text/text.js +51 -51
  47. package/dist/component/text-area/text-area.d.ts +28 -28
  48. package/dist/component/text-area/text-area.js +83 -73
  49. package/dist/component/text-field/text-field.d.ts +33 -33
  50. package/dist/component/text-field/text-field.js +107 -97
  51. package/dist/component/toast-noti/toast-noti.d.ts +5 -5
  52. package/dist/component/toast-noti/toast-noti.js +28 -28
  53. package/dist/component/wini-icon/winicon.d.ts +16 -16
  54. package/dist/component/wini-icon/winicon.js +121 -112
  55. package/dist/form/login/view.d.ts +40 -40
  56. package/dist/form/login/view.js +66 -65
  57. package/dist/i18n.d.ts +2 -0
  58. package/dist/i18n.js +125 -0
  59. package/dist/index.d.ts +32 -31
  60. package/dist/index.js +1 -1
  61. package/dist/language/i18n.d.ts +2 -0
  62. package/dist/language/i18n.js +125 -0
  63. package/package.json +5 -3
@@ -1,359 +1,362 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.DatePicker = void 0;
33
- /* eslint-disable react-hooks/exhaustive-deps */
34
- var react_1 = __importDefault(require("react"));
35
- var react_dom_1 = __importDefault(require("react-dom"));
36
- require("./date-picker.css");
37
- var index_1 = require("../../index");
38
- var calendar_1 = require("../calendar/calendar");
39
- var date_fns_1 = require("date-fns");
40
- var dateToString = function (x, y) {
41
- if (y === void 0) { y = "dd/mm/yyyy"; }
42
- var splitDateTime = y.split(" ");
43
- var dateFormat = splitDateTime[0];
44
- var timeFormat = splitDateTime[1];
45
- if (dateFormat.includes('hh')) {
46
- dateFormat = splitDateTime[1];
47
- timeFormat = splitDateTime[0];
48
- }
49
- var dateConvert = dateFormat.split(y.includes("/") ? "/" : "-").map(function (type) {
50
- switch (type.toLowerCase()) {
51
- case "dd":
52
- return x.getDate() < 10 ? "0".concat(x.getDate()) : "".concat(x.getDate());
53
- case "mm":
54
- return (x.getMonth() + 1) < 10 ? "0".concat((x.getMonth() + 1)) : "".concat((x.getMonth() + 1));
55
- case "yyyy":
56
- return "".concat(x.getFullYear());
57
- default:
58
- return '';
59
- }
60
- }).join(y.includes("/") ? "/" : "-");
61
- if (timeFormat) {
62
- var timeConvert = timeFormat.split(":").map(function (type) {
63
- switch (type) {
64
- case "hh":
65
- return x.getHours() < 10 ? "0".concat(x.getHours()) : "".concat(x.getHours());
66
- case "mm":
67
- return x.getMinutes() < 10 ? "0".concat(x.getMinutes()) : "".concat(x.getMinutes());
68
- case "ss":
69
- return x.getSeconds() < 10 ? "0".concat(x.getSeconds()) : "".concat(x.getSeconds());
70
- default:
71
- return 'D';
72
- }
73
- }).join(":");
74
- return dateConvert + " " + timeConvert;
75
- }
76
- return dateConvert;
77
- };
78
- var stringToDate = function (_date, _format, _delimiter) {
79
- var _a, _b, _c, _d, _e;
80
- if (_format === void 0) { _format = "dd/MM/yyyy"; }
81
- if (_delimiter === void 0) { _delimiter = "/"; }
82
- var dayformat = _format;
83
- var hourformat = '';
84
- var day = _date;
85
- var hours = '';
86
- var isHour = false;
87
- if (_format.trim().indexOf(" ") > -1) {
88
- dayformat = _format.trim().split(" ")[0];
89
- hourformat = _format.trim().split(" ")[1];
90
- day = _date.trim().split(" ")[0];
91
- hours = (_a = _date.trim().split(" ")[1]) !== null && _a !== void 0 ? _a : '00:00:00';
92
- isHour = true;
93
- }
94
- var formatLowerCase = dayformat.toLowerCase();
95
- var formatItems = formatLowerCase.split(_delimiter);
96
- var dateItems = day.split(_delimiter);
97
- var monthIndex = formatItems.indexOf("mm");
98
- var dayIndex = formatItems.indexOf("dd");
99
- var yearIndex = formatItems.indexOf("yyyy");
100
- var hour = 0;
101
- var min = 0;
102
- var sec = 0;
103
- if (isHour) {
104
- var tmpHour = hourformat.split(":");
105
- var hourindex = tmpHour.indexOf("HH");
106
- if (hourindex < 0) {
107
- hourindex = tmpHour.indexOf("hh");
108
- }
109
- var mmindex = tmpHour.indexOf("mm");
110
- var ssindex = tmpHour.indexOf("ss");
111
- var time = hours.split(":");
112
- hour = parseInt((_b = time[hourindex]) !== null && _b !== void 0 ? _b : '0');
113
- min = parseInt((_c = time[mmindex]) !== null && _c !== void 0 ? _c : '0');
114
- sec = parseInt((_d = time[ssindex]) !== null && _d !== void 0 ? _d : '0');
115
- }
116
- var month = parseInt(dateItems[monthIndex]);
117
- month -= 1;
118
- var formatedDate = new Date(parseInt(dateItems[yearIndex]), month, parseInt((_e = dateItems[dayIndex]) !== null && _e !== void 0 ? _e : '0'), hour, min, sec);
119
- return formatedDate;
120
- };
121
- var DatePicker = /** @class */ (function (_super) {
122
- __extends(DatePicker, _super);
123
- function DatePicker(props) {
124
- var _this = _super.call(this, props) || this;
125
- _this.getNewValue = function (value) {
126
- var _a, _b, _c, _d, _e, _f;
127
- var params = (_b = value !== null && value !== void 0 ? value : (_a = _this.state) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
128
- if ((_c = params.trim()) === null || _c === void 0 ? void 0 : _c.length) {
129
- switch (_this.props.pickerType) {
130
- case index_1.CalendarType.YEAR:
131
- return new Date(parseInt(params), 1, 1);
132
- case index_1.CalendarType.MONTH:
133
- var splitParams = params.includes('/') ? params.split('/') : params.split('-');
134
- return new Date(parseInt((_d = splitParams[1]) !== null && _d !== void 0 ? _d : "".concat(calendar_1.today.getFullYear())), parseInt((_e = splitParams[0]) !== null && _e !== void 0 ? _e : "".concat(calendar_1.today.getMonth())), 1);
135
- case index_1.CalendarType.DATETIME:
136
- return stringToDate(params, (_f = _this.props.formatDate) !== null && _f !== void 0 ? _f : 'dd/mm/yyyy hh:mm');
137
- default:
138
- return stringToDate(params);
139
- }
140
- }
141
- return undefined;
142
- };
143
- _this.onOpenCalendar = function (ev) {
144
- if (!_this.state.isOpen) {
145
- _this.setState(__assign(__assign({}, _this.state), { isOpen: true, style: undefined, offset: ev.target.closest('.date-picker-container').getBoundingClientRect() }));
146
- }
147
- };
148
- _this.state = {
149
- value: props.value,
150
- offset: {
151
- x: 0,
152
- y: 0,
153
- height: 0,
154
- width: 0,
155
- bottom: 0,
156
- left: 0,
157
- right: 0,
158
- top: 0,
159
- toJSON: function () {
160
- throw new Error('Function not implemented.');
161
- }
162
- },
163
- isOpen: false,
164
- };
165
- return _this;
166
- }
167
- DatePicker.prototype.componentDidUpdate = function (prevProps, prevState) {
168
- var _a;
169
- if (prevProps.value !== this.props.value) {
170
- this.setState(__assign(__assign({}, this.state), { value: this.props.value }));
171
- }
172
- if (prevState.isOpen !== this.state.isOpen && this.state.isOpen) {
173
- var thisPopupRect = (_a = document.body.querySelector('.date-picker-popup-container')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
174
- if (thisPopupRect) {
175
- var style = void 0;
176
- if (thisPopupRect.right > document.body.offsetWidth) {
177
- style = {
178
- top: this.state.offset.y + this.state.offset.height + 2 + 'px',
179
- right: document.body.offsetWidth - this.state.offset.left + 'px'
180
- };
181
- }
182
- if ((thisPopupRect.bottom - 12) > document.body.offsetHeight) {
183
- style = style ? __assign(__assign({}, style), { top: undefined, bottom: document.body.offsetHeight - this.state.offset.top + 'px' }) : {
184
- left: this.state.offset.x + 'px',
185
- bottom: document.body.offsetHeight - this.state.offset.top + 'px'
186
- };
187
- }
188
- if (style)
189
- this.setState(__assign(__assign({}, this.state), { style: style }));
190
- }
191
- }
192
- };
193
- DatePicker.prototype.render = function () {
194
- var _this = this;
195
- var _a, _b, _c, _d, _e, _f, _g;
196
- var maxLength = 10;
197
- switch (this.props.pickerType) {
198
- case index_1.CalendarType.YEAR:
199
- maxLength = 4;
200
- break;
201
- case index_1.CalendarType.MONTH:
202
- maxLength = 7;
203
- break;
204
- case index_1.CalendarType.DATETIME:
205
- maxLength = 19;
206
- break;
207
- default:
208
- break;
209
- }
210
- return react_1.default.createElement("div", { id: this.props.id, className: "date-picker-container row ".concat((_a = this.props.className) !== null && _a !== void 0 ? _a : 'body-3', " ").concat(this.props.disabled ? 'disabled' : '', " ").concat(((_b = this.props.helperText) === null || _b === void 0 ? void 0 : _b.length) && 'helper-text'), "helper-text": this.props.helperText, style: this.props.style ? __assign(__assign({}, { '--helper-text-color': (_c = this.props.helperTextColor) !== null && _c !== void 0 ? _c : '#e14337' }), this.props.style) : { '--helper-text-color': (_d = this.props.helperTextColor) !== null && _d !== void 0 ? _d : '#e14337' } },
211
- react_1.default.createElement("div", { className: 'input-field-value row', style: { height: '4rem' } },
212
- react_1.default.createElement("input", { autoComplete: 'off', value: (_e = this.state.value) !== null && _e !== void 0 ? _e : '', onChange: function (ev) { return _this.setState(__assign(__assign({}, _this.state), { value: ev.target.value })); }, placeholder: this.props.placeholder, maxLength: maxLength, readOnly: this.props.pickOnly, onFocus: this.props.pickOnly ? function (ev) {
213
- _this.onOpenCalendar(ev);
214
- if (_this.props.onFocus)
215
- _this.props.onFocus(ev);
216
- } : this.props.onFocus, onKeyDown: this.props.onComplete ? function (ev) {
217
- if (_this.props.onComplete) {
218
- switch (ev.key.toLowerCase()) {
219
- case "enter":
220
- _this.props.onComplete(ev);
221
- break;
222
- default:
223
- break;
224
- }
225
- }
226
- } : undefined, onBlur: this.props.pickOnly ? undefined : function (ev) {
227
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
228
- var inputValue = ev.target.value.trim();
229
- switch (_this.props.pickerType) {
230
- case index_1.CalendarType.YEAR:
231
- var minYear = ((_a = _this.props.min) !== null && _a !== void 0 ? _a : calendar_1.startDate).getFullYear();
232
- var maxYear = ((_b = _this.props.min) !== null && _b !== void 0 ? _b : calendar_1.endDate).getFullYear();
233
- if (!isNaN(parseInt(inputValue)) && parseInt(inputValue) <= maxYear && parseInt(inputValue) >= minYear) {
234
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: inputValue }));
235
- if (_this.props.onChange)
236
- _this.props.onChange(inputValue);
237
- }
238
- else {
239
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: undefined }));
240
- if (_this.props.onChange)
241
- _this.props.onChange(undefined);
242
- }
243
- break;
244
- case index_1.CalendarType.MONTH:
245
- if (inputValue.match(/[0-9]{1,2}(\/|-)[0-9]{4}/g)) {
246
- var dateValue_1 = stringToDate("1/".concat(inputValue), 'dd/MM/yyyy', '/');
247
- if ((0, calendar_1.inRangeTime)(dateValue_1, (_d = (_c = _this.props.min) !== null && _c !== void 0 ? _c : calendar_1.startDate) !== null && _d !== void 0 ? _d : calendar_1.startDate, (_f = (_e = _this.props.min) !== null && _e !== void 0 ? _e : calendar_1.endDate) !== null && _f !== void 0 ? _f : calendar_1.endDate)) {
248
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: dateToString(dateValue_1) }));
249
- if (_this.props.onChange)
250
- _this.props.onChange(dateToString(dateValue_1));
251
- }
252
- else {
253
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: undefined }));
254
- if (_this.props.onChange)
255
- _this.props.onChange(undefined);
256
- }
257
- }
258
- else {
259
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: undefined }));
260
- if (_this.props.onChange)
261
- _this.props.onChange(undefined);
262
- }
263
- break;
264
- case index_1.CalendarType.DATETIME:
265
- var dateTimeValue = undefined;
266
- if (inputValue.match(/[0-9]{1,2}(\/|-)[0-9]{1,2}(\/|-)[0-9]{4}/g)) {
267
- dateTimeValue = stringToDate(inputValue, (_g = _this.props.formatDate) !== null && _g !== void 0 ? _g : 'dd/mm/yyyy hh:mm', '/');
268
- if ((0, calendar_1.inRangeTime)(dateTimeValue, (_h = _this.props.min) !== null && _h !== void 0 ? _h : calendar_1.startDate, (_j = _this.props.min) !== null && _j !== void 0 ? _j : calendar_1.endDate)) {
269
- }
270
- else if ((0, date_fns_1.differenceInCalendarDays)((_k = _this.props.min) !== null && _k !== void 0 ? _k : calendar_1.startDate, dateTimeValue) > -1) {
271
- dateTimeValue = (_l = _this.props.min) !== null && _l !== void 0 ? _l : calendar_1.startDate;
272
- }
273
- else if ((0, date_fns_1.differenceInCalendarDays)(dateTimeValue, (_m = _this.props.min) !== null && _m !== void 0 ? _m : calendar_1.endDate) > -1) {
274
- dateTimeValue = (_o = _this.props.min) !== null && _o !== void 0 ? _o : calendar_1.startDate;
275
- }
276
- else {
277
- dateTimeValue = undefined;
278
- }
279
- }
280
- var stateDateTimeValue = dateTimeValue ? dateToString(dateTimeValue, (_p = _this.props.formatDate) !== null && _p !== void 0 ? _p : 'dd/mm/yyyy hh:mm') : dateTimeValue;
281
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: stateDateTimeValue }));
282
- if (_this.props.onChange)
283
- _this.props.onChange(stateDateTimeValue);
284
- break;
285
- default:
286
- var dateValue = undefined;
287
- if (inputValue.match(/[0-9]{1,2}(\/|-)[0-9]{1,2}(\/|-)[0-9]{4}/g)) {
288
- dateValue = stringToDate(inputValue, 'dd/MM/yyyy', '/');
289
- if ((0, calendar_1.inRangeTime)(dateValue, (_q = _this.props.min) !== null && _q !== void 0 ? _q : calendar_1.startDate, (_r = _this.props.min) !== null && _r !== void 0 ? _r : calendar_1.endDate)) {
290
- }
291
- else if ((0, date_fns_1.differenceInCalendarDays)((_s = _this.props.min) !== null && _s !== void 0 ? _s : calendar_1.startDate, dateValue) > -1) {
292
- dateValue = (_t = _this.props.min) !== null && _t !== void 0 ? _t : calendar_1.startDate;
293
- }
294
- else if ((0, date_fns_1.differenceInCalendarDays)(dateValue, (_u = _this.props.min) !== null && _u !== void 0 ? _u : calendar_1.endDate) > -1) {
295
- dateValue = (_v = _this.props.max) !== null && _v !== void 0 ? _v : calendar_1.endDate;
296
- }
297
- else {
298
- dateValue = undefined;
299
- }
300
- }
301
- var stateDateValue = dateValue ? dateToString(dateValue) : dateValue;
302
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: stateDateValue }));
303
- if (_this.props.onChange)
304
- _this.props.onChange(stateDateValue);
305
- break;
306
- }
307
- } })),
308
- react_1.default.createElement(index_1.Winicon, { src: "outline/user interface/".concat(this.props.pickerType === index_1.CalendarType.DATETIME ? "opening-times" : "calendar-date-2"), size: '1.6rem', onClick: this.onOpenCalendar }),
309
- this.state.isOpen &&
310
- react_dom_1.default.createPortal(react_1.default.createElement("div", { className: "popup-overlay hidden-overlay", onClick: function (ev) {
311
- if (ev.target.classList.contains('popup-overlay'))
312
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false }));
313
- } },
314
- react_1.default.createElement(index_1.Calendar, { min: this.props.min, max: this.props.max, value: this.getNewValue(), type: (_f = this.props.pickerType) !== null && _f !== void 0 ? _f : index_1.CalendarType.DATE, className: 'date-picker-popup-container', style: (_g = this.state.style) !== null && _g !== void 0 ? _g : { top: this.state.offset.y + this.state.offset.height + 2 + 'px', left: this.state.offset.x + 'px', border: 'none', boxShadow: '-20px 20px 40px -4px rgba(145, 158, 171, 0.24), 0px 0px 2px 0px rgba(145, 158, 171, 0.24)' }, onSelect: function (dateValue) {
315
- var _a;
316
- switch (_this.props.pickerType) {
317
- case index_1.CalendarType.YEAR:
318
- _this.setState(__assign(__assign({}, _this.state), { value: dateValue.getFullYear().toString(), isOpen: false }));
319
- if (_this.props.onChange)
320
- _this.props.onChange(dateValue.getFullYear().toString());
321
- break;
322
- case index_1.CalendarType.MONTH:
323
- var newValue = dateToString(dateValue);
324
- _this.setState(__assign(__assign({}, _this.state), { value: newValue.split('/').slice(1).join('/'), isOpen: false }));
325
- if (_this.props.onChange)
326
- _this.props.onChange(newValue.split('/').slice(1).join('/'));
327
- break;
328
- case index_1.CalendarType.DATETIME:
329
- var newValue = dateToString(dateValue, (_a = _this.props.formatDate) !== null && _a !== void 0 ? _a : 'dd/mm/yyyy hh:mm');
330
- _this.setState(__assign(__assign({}, _this.state), { value: newValue }));
331
- break;
332
- default:
333
- var newValue = dateToString(dateValue);
334
- _this.setState(__assign(__assign({}, _this.state), { value: newValue, isOpen: false }));
335
- if (_this.props.onChange)
336
- _this.props.onChange(newValue);
337
- break;
338
- }
339
- }, footer: (this.props.pickerType === index_1.CalendarType.DATETIME || !this.props.hideButtonToday) && react_1.default.createElement("div", { className: 'row picker-popup-footer' },
340
- this.props.pickerType === undefined || this.props.pickerType === index_1.CalendarType.DATE || this.props.pickerType === index_1.CalendarType.DATETIME ?
341
- react_1.default.createElement("button", { type: 'button', className: 'row button-text-3', style: { color: 'var(--infor-main-color)', width: 'fit-content' }, onClick: function () {
342
- var _a;
343
- var format = (_a = _this.props.formatDate) !== null && _a !== void 0 ? _a : (_this.props.pickerType === index_1.CalendarType.DATETIME ? 'dd/mm/yyyy hh:mm' : 'dd/mm/yyyy');
344
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: dateToString(calendar_1.today, format) }));
345
- if (_this.props.onChange)
346
- _this.props.onChange(dateToString(calendar_1.today, format));
347
- } }, "Today") : null,
348
- this.props.pickerType === index_1.CalendarType.DATETIME ? react_1.default.createElement(react_1.default.Fragment, null,
349
- react_1.default.createElement("div", { style: { flex: 1 } }),
350
- react_1.default.createElement("button", { type: 'button', className: 'row button-primary', style: { padding: '0.6rem 0.8rem' }, onClick: function () {
351
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false }));
352
- if (_this.props.onChange)
353
- _this.props.onChange(_this.state.value);
354
- } },
355
- react_1.default.createElement("div", { className: 'button-text-3' }, "Apply"))) : null) })), document.body));
356
- };
357
- return DatePicker;
358
- }(react_1.default.Component));
359
- exports.DatePicker = DatePicker;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.DatePicker = void 0;
33
+ /* eslint-disable react-hooks/exhaustive-deps */
34
+ var react_1 = __importDefault(require("react"));
35
+ var react_dom_1 = __importDefault(require("react-dom"));
36
+ require("./date-picker.css");
37
+ var index_1 = require("../../index");
38
+ var calendar_1 = require("../calendar/calendar");
39
+ var date_fns_1 = require("date-fns");
40
+ var react_i18next_1 = require("react-i18next");
41
+ var dateToString = function (x, y) {
42
+ if (y === void 0) { y = "dd/mm/yyyy"; }
43
+ var splitDateTime = y.split(" ");
44
+ var dateFormat = splitDateTime[0];
45
+ var timeFormat = splitDateTime[1];
46
+ if (dateFormat.includes('hh')) {
47
+ dateFormat = splitDateTime[1];
48
+ timeFormat = splitDateTime[0];
49
+ }
50
+ var dateConvert = dateFormat.split(y.includes("/") ? "/" : "-").map(function (type) {
51
+ switch (type.toLowerCase()) {
52
+ case "dd":
53
+ return x.getDate() < 10 ? "0".concat(x.getDate()) : "".concat(x.getDate());
54
+ case "mm":
55
+ return (x.getMonth() + 1) < 10 ? "0".concat((x.getMonth() + 1)) : "".concat((x.getMonth() + 1));
56
+ case "yyyy":
57
+ return "".concat(x.getFullYear());
58
+ default:
59
+ return '';
60
+ }
61
+ }).join(y.includes("/") ? "/" : "-");
62
+ if (timeFormat) {
63
+ var timeConvert = timeFormat.split(":").map(function (type) {
64
+ switch (type) {
65
+ case "hh":
66
+ return x.getHours() < 10 ? "0".concat(x.getHours()) : "".concat(x.getHours());
67
+ case "mm":
68
+ return x.getMinutes() < 10 ? "0".concat(x.getMinutes()) : "".concat(x.getMinutes());
69
+ case "ss":
70
+ return x.getSeconds() < 10 ? "0".concat(x.getSeconds()) : "".concat(x.getSeconds());
71
+ default:
72
+ return 'D';
73
+ }
74
+ }).join(":");
75
+ return dateConvert + " " + timeConvert;
76
+ }
77
+ return dateConvert;
78
+ };
79
+ var stringToDate = function (_date, _format, _delimiter) {
80
+ var _a, _b, _c, _d, _e;
81
+ if (_format === void 0) { _format = "dd/MM/yyyy"; }
82
+ if (_delimiter === void 0) { _delimiter = "/"; }
83
+ var dayformat = _format;
84
+ var hourformat = '';
85
+ var day = _date;
86
+ var hours = '';
87
+ var isHour = false;
88
+ if (_format.trim().indexOf(" ") > -1) {
89
+ dayformat = _format.trim().split(" ")[0];
90
+ hourformat = _format.trim().split(" ")[1];
91
+ day = _date.trim().split(" ")[0];
92
+ hours = (_a = _date.trim().split(" ")[1]) !== null && _a !== void 0 ? _a : '00:00:00';
93
+ isHour = true;
94
+ }
95
+ var formatLowerCase = dayformat.toLowerCase();
96
+ var formatItems = formatLowerCase.split(_delimiter);
97
+ var dateItems = day.split(_delimiter);
98
+ var monthIndex = formatItems.indexOf("mm");
99
+ var dayIndex = formatItems.indexOf("dd");
100
+ var yearIndex = formatItems.indexOf("yyyy");
101
+ var hour = 0;
102
+ var min = 0;
103
+ var sec = 0;
104
+ if (isHour) {
105
+ var tmpHour = hourformat.split(":");
106
+ var hourindex = tmpHour.indexOf("HH");
107
+ if (hourindex < 0) {
108
+ hourindex = tmpHour.indexOf("hh");
109
+ }
110
+ var mmindex = tmpHour.indexOf("mm");
111
+ var ssindex = tmpHour.indexOf("ss");
112
+ var time = hours.split(":");
113
+ hour = parseInt((_b = time[hourindex]) !== null && _b !== void 0 ? _b : '0');
114
+ min = parseInt((_c = time[mmindex]) !== null && _c !== void 0 ? _c : '0');
115
+ sec = parseInt((_d = time[ssindex]) !== null && _d !== void 0 ? _d : '0');
116
+ }
117
+ var month = parseInt(dateItems[monthIndex]);
118
+ month -= 1;
119
+ var formatedDate = new Date(parseInt(dateItems[yearIndex]), month, parseInt((_e = dateItems[dayIndex]) !== null && _e !== void 0 ? _e : '0'), hour, min, sec);
120
+ return formatedDate;
121
+ };
122
+ var TDatePicker = /** @class */ (function (_super) {
123
+ __extends(TDatePicker, _super);
124
+ function TDatePicker(props) {
125
+ var _this = _super.call(this, props) || this;
126
+ _this.getNewValue = function (value) {
127
+ var _a, _b, _c, _d, _e, _f;
128
+ var params = (_b = value !== null && value !== void 0 ? value : (_a = _this.state) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
129
+ if ((_c = params.trim()) === null || _c === void 0 ? void 0 : _c.length) {
130
+ switch (_this.props.pickerType) {
131
+ case index_1.CalendarType.YEAR:
132
+ return new Date(parseInt(params), 1, 1);
133
+ case index_1.CalendarType.MONTH:
134
+ var splitParams = params.includes('/') ? params.split('/') : params.split('-');
135
+ return new Date(parseInt((_d = splitParams[1]) !== null && _d !== void 0 ? _d : "".concat(calendar_1.today.getFullYear())), parseInt((_e = splitParams[0]) !== null && _e !== void 0 ? _e : "".concat(calendar_1.today.getMonth())), 1);
136
+ case index_1.CalendarType.DATETIME:
137
+ return stringToDate(params, (_f = _this.props.formatDate) !== null && _f !== void 0 ? _f : 'dd/mm/yyyy hh:mm');
138
+ default:
139
+ return stringToDate(params);
140
+ }
141
+ }
142
+ return undefined;
143
+ };
144
+ _this.onOpenCalendar = function (ev) {
145
+ if (!_this.state.isOpen) {
146
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: true, style: undefined, offset: ev.target.closest('.date-picker-container').getBoundingClientRect() }));
147
+ }
148
+ };
149
+ _this.state = {
150
+ value: props.value,
151
+ offset: {
152
+ x: 0,
153
+ y: 0,
154
+ height: 0,
155
+ width: 0,
156
+ bottom: 0,
157
+ left: 0,
158
+ right: 0,
159
+ top: 0,
160
+ toJSON: function () {
161
+ throw new Error('Function not implemented.');
162
+ }
163
+ },
164
+ isOpen: false,
165
+ };
166
+ _this.getNewValue = _this.getNewValue.bind(_this);
167
+ return _this;
168
+ }
169
+ TDatePicker.prototype.componentDidUpdate = function (prevProps, prevState) {
170
+ var _a;
171
+ if (prevProps.value !== this.props.value) {
172
+ this.setState(__assign(__assign({}, this.state), { value: this.props.value }));
173
+ }
174
+ if (prevState.isOpen !== this.state.isOpen && this.state.isOpen) {
175
+ var thisPopupRect = (_a = document.body.querySelector('.date-picker-popup-container')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
176
+ if (thisPopupRect) {
177
+ var style = void 0;
178
+ if (thisPopupRect.right > document.body.offsetWidth) {
179
+ style = {
180
+ top: this.state.offset.y + this.state.offset.height + 2 + 'px',
181
+ right: document.body.offsetWidth - this.state.offset.left + 'px'
182
+ };
183
+ }
184
+ if ((thisPopupRect.bottom - 12) > document.body.offsetHeight) {
185
+ style = style ? __assign(__assign({}, style), { top: undefined, bottom: document.body.offsetHeight - this.state.offset.top + 'px' }) : {
186
+ left: this.state.offset.x + 'px',
187
+ bottom: document.body.offsetHeight - this.state.offset.top + 'px'
188
+ };
189
+ }
190
+ if (style)
191
+ this.setState(__assign(__assign({}, this.state), { style: style }));
192
+ }
193
+ }
194
+ };
195
+ TDatePicker.prototype.render = function () {
196
+ var _this = this;
197
+ var _a, _b, _c, _d, _e, _f, _g;
198
+ var t = this.props.t;
199
+ var maxLength = 10;
200
+ switch (this.props.pickerType) {
201
+ case index_1.CalendarType.YEAR:
202
+ maxLength = 4;
203
+ break;
204
+ case index_1.CalendarType.MONTH:
205
+ maxLength = 7;
206
+ break;
207
+ case index_1.CalendarType.DATETIME:
208
+ maxLength = 19;
209
+ break;
210
+ default:
211
+ break;
212
+ }
213
+ return react_1.default.createElement("div", { id: this.props.id, className: "date-picker-container row ".concat((_a = this.props.className) !== null && _a !== void 0 ? _a : 'body-3', " ").concat(this.props.disabled ? 'disabled' : '', " ").concat(((_b = this.props.helperText) === null || _b === void 0 ? void 0 : _b.length) && 'helper-text'), "helper-text": this.props.helperText, style: this.props.style ? __assign(__assign({}, { '--helper-text-color': (_c = this.props.helperTextColor) !== null && _c !== void 0 ? _c : '#e14337' }), this.props.style) : { '--helper-text-color': (_d = this.props.helperTextColor) !== null && _d !== void 0 ? _d : '#e14337' } },
214
+ react_1.default.createElement("div", { className: 'input-field-value row', style: { height: '4rem' } },
215
+ react_1.default.createElement("input", { autoComplete: 'off', value: (_e = this.state.value) !== null && _e !== void 0 ? _e : '', onChange: function (ev) { return _this.setState(__assign(__assign({}, _this.state), { value: ev.target.value })); }, placeholder: this.props.placeholder, maxLength: maxLength, readOnly: this.props.pickOnly, onFocus: this.props.pickOnly ? function (ev) {
216
+ _this.onOpenCalendar(ev);
217
+ if (_this.props.onFocus)
218
+ _this.props.onFocus(ev);
219
+ } : this.props.onFocus, onKeyDown: this.props.onComplete ? function (ev) {
220
+ if (_this.props.onComplete) {
221
+ switch (ev.key.toLowerCase()) {
222
+ case "enter":
223
+ _this.props.onComplete(ev);
224
+ break;
225
+ default:
226
+ break;
227
+ }
228
+ }
229
+ } : undefined, onBlur: this.props.pickOnly ? undefined : function (ev) {
230
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
231
+ var inputValue = ev.target.value.trim();
232
+ switch (_this.props.pickerType) {
233
+ case index_1.CalendarType.YEAR:
234
+ var minYear = ((_a = _this.props.min) !== null && _a !== void 0 ? _a : calendar_1.startDate).getFullYear();
235
+ var maxYear = ((_b = _this.props.min) !== null && _b !== void 0 ? _b : calendar_1.endDate).getFullYear();
236
+ if (!isNaN(parseInt(inputValue)) && parseInt(inputValue) <= maxYear && parseInt(inputValue) >= minYear) {
237
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: inputValue }));
238
+ if (_this.props.onChange)
239
+ _this.props.onChange(inputValue);
240
+ }
241
+ else {
242
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: undefined }));
243
+ if (_this.props.onChange)
244
+ _this.props.onChange(undefined);
245
+ }
246
+ break;
247
+ case index_1.CalendarType.MONTH:
248
+ if (inputValue.match(/[0-9]{1,2}(\/|-)[0-9]{4}/g)) {
249
+ var dateValue_1 = stringToDate("1/".concat(inputValue), 'dd/MM/yyyy', '/');
250
+ if ((0, calendar_1.inRangeTime)(dateValue_1, (_d = (_c = _this.props.min) !== null && _c !== void 0 ? _c : calendar_1.startDate) !== null && _d !== void 0 ? _d : calendar_1.startDate, (_f = (_e = _this.props.min) !== null && _e !== void 0 ? _e : calendar_1.endDate) !== null && _f !== void 0 ? _f : calendar_1.endDate)) {
251
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: dateToString(dateValue_1) }));
252
+ if (_this.props.onChange)
253
+ _this.props.onChange(dateToString(dateValue_1));
254
+ }
255
+ else {
256
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: undefined }));
257
+ if (_this.props.onChange)
258
+ _this.props.onChange(undefined);
259
+ }
260
+ }
261
+ else {
262
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: undefined }));
263
+ if (_this.props.onChange)
264
+ _this.props.onChange(undefined);
265
+ }
266
+ break;
267
+ case index_1.CalendarType.DATETIME:
268
+ var dateTimeValue = undefined;
269
+ if (inputValue.match(/[0-9]{1,2}(\/|-)[0-9]{1,2}(\/|-)[0-9]{4}/g)) {
270
+ dateTimeValue = stringToDate(inputValue, (_g = _this.props.formatDate) !== null && _g !== void 0 ? _g : 'dd/mm/yyyy hh:mm', '/');
271
+ if ((0, calendar_1.inRangeTime)(dateTimeValue, (_h = _this.props.min) !== null && _h !== void 0 ? _h : calendar_1.startDate, (_j = _this.props.min) !== null && _j !== void 0 ? _j : calendar_1.endDate)) {
272
+ }
273
+ else if ((0, date_fns_1.differenceInCalendarDays)((_k = _this.props.min) !== null && _k !== void 0 ? _k : calendar_1.startDate, dateTimeValue) > -1) {
274
+ dateTimeValue = (_l = _this.props.min) !== null && _l !== void 0 ? _l : calendar_1.startDate;
275
+ }
276
+ else if ((0, date_fns_1.differenceInCalendarDays)(dateTimeValue, (_m = _this.props.min) !== null && _m !== void 0 ? _m : calendar_1.endDate) > -1) {
277
+ dateTimeValue = (_o = _this.props.min) !== null && _o !== void 0 ? _o : calendar_1.startDate;
278
+ }
279
+ else {
280
+ dateTimeValue = undefined;
281
+ }
282
+ }
283
+ var stateDateTimeValue = dateTimeValue ? dateToString(dateTimeValue, (_p = _this.props.formatDate) !== null && _p !== void 0 ? _p : 'dd/mm/yyyy hh:mm') : dateTimeValue;
284
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: stateDateTimeValue }));
285
+ if (_this.props.onChange)
286
+ _this.props.onChange(stateDateTimeValue);
287
+ break;
288
+ default:
289
+ var dateValue = undefined;
290
+ if (inputValue.match(/[0-9]{1,2}(\/|-)[0-9]{1,2}(\/|-)[0-9]{4}/g)) {
291
+ dateValue = stringToDate(inputValue, 'dd/MM/yyyy', '/');
292
+ if ((0, calendar_1.inRangeTime)(dateValue, (_q = _this.props.min) !== null && _q !== void 0 ? _q : calendar_1.startDate, (_r = _this.props.min) !== null && _r !== void 0 ? _r : calendar_1.endDate)) {
293
+ }
294
+ else if ((0, date_fns_1.differenceInCalendarDays)((_s = _this.props.min) !== null && _s !== void 0 ? _s : calendar_1.startDate, dateValue) > -1) {
295
+ dateValue = (_t = _this.props.min) !== null && _t !== void 0 ? _t : calendar_1.startDate;
296
+ }
297
+ else if ((0, date_fns_1.differenceInCalendarDays)(dateValue, (_u = _this.props.min) !== null && _u !== void 0 ? _u : calendar_1.endDate) > -1) {
298
+ dateValue = (_v = _this.props.max) !== null && _v !== void 0 ? _v : calendar_1.endDate;
299
+ }
300
+ else {
301
+ dateValue = undefined;
302
+ }
303
+ }
304
+ var stateDateValue = dateValue ? dateToString(dateValue) : dateValue;
305
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: stateDateValue }));
306
+ if (_this.props.onChange)
307
+ _this.props.onChange(stateDateValue);
308
+ break;
309
+ }
310
+ } })),
311
+ react_1.default.createElement(index_1.Winicon, { src: "outline/user interface/".concat(this.props.pickerType === index_1.CalendarType.DATETIME ? "opening-times" : "calendar-date-2"), size: '1.6rem', onClick: this.onOpenCalendar }),
312
+ this.state.isOpen &&
313
+ react_dom_1.default.createPortal(react_1.default.createElement("div", { className: "popup-overlay hidden-overlay", onClick: function (ev) {
314
+ if (ev.target.classList.contains('popup-overlay'))
315
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false }));
316
+ } },
317
+ react_1.default.createElement(index_1.Calendar, { min: this.props.min, max: this.props.max, value: this.getNewValue(), type: (_f = this.props.pickerType) !== null && _f !== void 0 ? _f : index_1.CalendarType.DATE, className: 'date-picker-popup-container', style: (_g = this.state.style) !== null && _g !== void 0 ? _g : { top: this.state.offset.y + this.state.offset.height + 2 + 'px', left: this.state.offset.x + 'px', border: 'none', boxShadow: '-20px 20px 40px -4px rgba(145, 158, 171, 0.24), 0px 0px 2px 0px rgba(145, 158, 171, 0.24)' }, onSelect: function (dateValue) {
318
+ var _a;
319
+ switch (_this.props.pickerType) {
320
+ case index_1.CalendarType.YEAR:
321
+ _this.setState(__assign(__assign({}, _this.state), { value: dateValue.getFullYear().toString(), isOpen: false }));
322
+ if (_this.props.onChange)
323
+ _this.props.onChange(dateValue.getFullYear().toString());
324
+ break;
325
+ case index_1.CalendarType.MONTH:
326
+ var newValue = dateToString(dateValue);
327
+ _this.setState(__assign(__assign({}, _this.state), { value: newValue.split('/').slice(1).join('/'), isOpen: false }));
328
+ if (_this.props.onChange)
329
+ _this.props.onChange(newValue.split('/').slice(1).join('/'));
330
+ break;
331
+ case index_1.CalendarType.DATETIME:
332
+ var newValue = dateToString(dateValue, (_a = _this.props.formatDate) !== null && _a !== void 0 ? _a : 'dd/mm/yyyy hh:mm');
333
+ _this.setState(__assign(__assign({}, _this.state), { value: newValue }));
334
+ break;
335
+ default:
336
+ var newValue = dateToString(dateValue);
337
+ _this.setState(__assign(__assign({}, _this.state), { value: newValue, isOpen: false }));
338
+ if (_this.props.onChange)
339
+ _this.props.onChange(newValue);
340
+ break;
341
+ }
342
+ }, footer: (this.props.pickerType === index_1.CalendarType.DATETIME || !this.props.hideButtonToday) && react_1.default.createElement("div", { className: 'row picker-popup-footer' },
343
+ this.props.pickerType === undefined || this.props.pickerType === index_1.CalendarType.DATE || this.props.pickerType === index_1.CalendarType.DATETIME ?
344
+ react_1.default.createElement("button", { type: 'button', className: 'row button-text-3', style: { color: 'var(--infor-main-color)', width: 'fit-content' }, onClick: function () {
345
+ var _a;
346
+ var format = (_a = _this.props.formatDate) !== null && _a !== void 0 ? _a : (_this.props.pickerType === index_1.CalendarType.DATETIME ? 'dd/mm/yyyy hh:mm' : 'dd/mm/yyyy');
347
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, value: dateToString(calendar_1.today, format) }));
348
+ if (_this.props.onChange)
349
+ _this.props.onChange(dateToString(calendar_1.today, format));
350
+ } }, this.props.t('today')) : null,
351
+ this.props.pickerType === index_1.CalendarType.DATETIME ? react_1.default.createElement(react_1.default.Fragment, null,
352
+ react_1.default.createElement("div", { style: { flex: 1 } }),
353
+ react_1.default.createElement("button", { type: 'button', className: 'row', style: { padding: '0.6rem 1.2rem', backgroundColor: "var(--primary-main-color)", borderRadius: "0.8rem" }, onClick: function () {
354
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false }));
355
+ if (_this.props.onChange)
356
+ _this.props.onChange(_this.state.value);
357
+ } },
358
+ react_1.default.createElement(index_1.Text, { className: 'button-text-3', style: { color: "var(--neutral-text-stable-color)" } }, t("apply")))) : null) })), document.body));
359
+ };
360
+ return TDatePicker;
361
+ }(react_1.default.Component));
362
+ exports.DatePicker = (0, react_i18next_1.withTranslation)()(TDatePicker);