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