@antscorp/antsomi-ui 1.3.3-beta.74 → 1.3.3-beta.75
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/es/components/common/ConfigProvider/GlobalStyle.js +4 -0
- package/es/components/molecules/DatePicker/components/AdvancedPicker/AdvancedPicker.js +28 -181
- package/es/components/molecules/DatePicker/components/AdvancedPicker/constants.d.ts +12 -0
- package/es/components/molecules/DatePicker/components/AdvancedPicker/constants.js +12 -0
- package/es/components/molecules/DatePicker/components/AdvancedPicker/styled.js +1 -1
- package/es/components/molecules/DatePicker/components/AdvancedPicker/utils.d.ts +5 -1
- package/es/components/molecules/DatePicker/components/AdvancedPicker/utils.js +70 -38
- package/es/components/molecules/DatePicker/components/DropdownLabel/DropdownLabel.d.ts +13 -0
- package/es/components/molecules/DatePicker/components/DropdownLabel/DropdownLabel.js +82 -0
- package/es/components/molecules/DatePicker/components/ErrorMessage/ErrorMessage.d.ts +6 -0
- package/es/components/molecules/DatePicker/components/ErrorMessage/ErrorMessage.js +12 -0
- package/package.json +1 -1
|
@@ -312,6 +312,10 @@ export const GlobalStyle = () => {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
.antsomi-picker-time-panel {
|
|
315
|
+
.antsomi-picker-time-panel-column:after {
|
|
316
|
+
height: 8px;
|
|
317
|
+
}
|
|
318
|
+
|
|
315
319
|
.antsomi-picker-time-panel-cell-selected {
|
|
316
320
|
background-color: ${(_8 = THEME.token) === null || _8 === void 0 ? void 0 : _8.colorPrimary};
|
|
317
321
|
color: #fff;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/no-unused-prop-types */
|
|
2
2
|
// Libraries
|
|
3
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
4
|
-
import { Tooltip, theme } from 'antd';
|
|
3
|
+
import React, { useEffect, useMemo, useCallback, useState } from 'react';
|
|
4
|
+
import { Tooltip, theme, DatePicker } from 'antd';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
// Hooks
|
|
@@ -9,20 +9,21 @@ import { useDeepCompareEffect } from '../../../../../hooks';
|
|
|
9
9
|
// Icons
|
|
10
10
|
import Icon from '@antscorp/icons';
|
|
11
11
|
import { EventIcon } from '../../../../icons';
|
|
12
|
-
//
|
|
12
|
+
// Components
|
|
13
13
|
import { Input, InputNumber, Divider, Space, Button, Typography, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
14
|
-
|
|
15
|
-
import {
|
|
14
|
+
import { Select, Dropdown } from '@antscorp/antsomi-ui/es/components';
|
|
15
|
+
import { ErrorMessage } from '../ErrorMessage/ErrorMessage';
|
|
16
16
|
// Utils
|
|
17
17
|
import { handleError, reorder } from '@antscorp/antsomi-ui/es/utils';
|
|
18
|
-
import { calculationDateAdvanced, getCellRender,
|
|
18
|
+
import { calculationDateAdvanced, getCellRender, getFormatDisplay, getPickerRender, getTimePickerRender, } from './utils';
|
|
19
19
|
// Styled
|
|
20
20
|
import { DatePickerCustomInput, DatePickerHeader, DropdownContent, DropdownHeader, DatePickerFooter, DropdownFooter, CalendarIconWrapper, } from './styled';
|
|
21
21
|
// Constants
|
|
22
|
-
import { CALCULATION_DATES, CALCULATION_TYPES, DATE_TYPES, DEFAULT_DATE_FORMAT, VALUE_TYPES, ADVANCED_PICKER_TYPE, WEEK_ARR, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, DAY_LABEL_SHORT,
|
|
23
|
-
import { THEME } from '
|
|
22
|
+
import { CALCULATION_DATES, CALCULATION_TYPES, DATE_TYPES, DEFAULT_DATE_FORMAT, VALUE_TYPES, ADVANCED_PICKER_TYPE, WEEK_ARR, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, DAY_LABEL_SHORT, MONTH_LABEL_FULL, DAY_OF_MONTH, ANCHOR_LEAP_YEAR, GRANULARITY_MAPPING, } from './constants';
|
|
23
|
+
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
24
24
|
// Instance
|
|
25
25
|
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
26
|
+
import { DropdownLabel } from '../DropdownLabel/DropdownLabel';
|
|
26
27
|
const PATH = '@antscorp/antsomi-ui/es/components/molecules/DatePicker/components/Advanced/DatePickerAdvanced.tsx';
|
|
27
28
|
const { useToken } = theme;
|
|
28
29
|
const { Text } = Typography;
|
|
@@ -48,79 +49,7 @@ export const AdvancedPicker = props => {
|
|
|
48
49
|
const granularityKey = GRANULARITY_MAPPING[valueType || 'YEAR_MONTH_DAY'].reverse();
|
|
49
50
|
return CALCULATION_DATES.filter(calculationDate => granularityKey.includes(calculationDate.value));
|
|
50
51
|
}, [valueType]);
|
|
51
|
-
const
|
|
52
|
-
let formatDisplay = '';
|
|
53
|
-
let timeFormatDisplay = '';
|
|
54
|
-
let isStartDate = false;
|
|
55
|
-
// Handle detect day is start or end
|
|
56
|
-
if (operatorKey === 'between') {
|
|
57
|
-
isStartDate = type === 'startDate';
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
isStartDate = operatorKey === 'after';
|
|
61
|
-
}
|
|
62
|
-
switch (valueType) {
|
|
63
|
-
case 'YEAR':
|
|
64
|
-
formatDisplay = 'YYYY';
|
|
65
|
-
break;
|
|
66
|
-
case 'YEAR_QUARTER':
|
|
67
|
-
formatDisplay = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
68
|
-
break;
|
|
69
|
-
case 'YEAR_MONTH':
|
|
70
|
-
formatDisplay = 'MMMM, YYYY';
|
|
71
|
-
break;
|
|
72
|
-
case 'YEAR_WEEK':
|
|
73
|
-
formatDisplay = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
74
|
-
break;
|
|
75
|
-
case 'YEAR_MONTH_DAY':
|
|
76
|
-
formatDisplay = 'MMMM DD, YYYY';
|
|
77
|
-
break;
|
|
78
|
-
case 'YEAR_MONTH_DAY_HOUR':
|
|
79
|
-
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:00:00' : 'HH:59:59'}`;
|
|
80
|
-
timeFormatDisplay = isStartDate ? 'HH:00:00' : 'HH:59:59';
|
|
81
|
-
break;
|
|
82
|
-
case 'YEAR_MONTH_DAY_MINUTE':
|
|
83
|
-
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:mm:00' : 'HH:mm:59'}`;
|
|
84
|
-
timeFormatDisplay = isStartDate ? 'HH:mm:00' : 'HH:mm:59';
|
|
85
|
-
break;
|
|
86
|
-
case 'YEAR_MONTH_DAY_SECOND':
|
|
87
|
-
formatDisplay = 'MMMM DD, YYYY HH:mm:ss';
|
|
88
|
-
timeFormatDisplay = 'HH:mm:ss';
|
|
89
|
-
break;
|
|
90
|
-
case 'QUARTER':
|
|
91
|
-
formatDisplay = `${QUARTER_PLACEHOLDER}Q`;
|
|
92
|
-
break;
|
|
93
|
-
case 'MONTH':
|
|
94
|
-
formatDisplay = 'MMMM';
|
|
95
|
-
break;
|
|
96
|
-
case 'WEEK':
|
|
97
|
-
formatDisplay = `${WEEK_PLACEHOLDER}W`;
|
|
98
|
-
break;
|
|
99
|
-
case 'MONTH_DAY':
|
|
100
|
-
formatDisplay = 'MMMM DD';
|
|
101
|
-
break;
|
|
102
|
-
case 'DAY_OF_WEEK':
|
|
103
|
-
formatDisplay = 'dddd';
|
|
104
|
-
break;
|
|
105
|
-
case 'DAY':
|
|
106
|
-
formatDisplay = 'DD';
|
|
107
|
-
break;
|
|
108
|
-
case 'HOUR':
|
|
109
|
-
formatDisplay = 'HH';
|
|
110
|
-
break;
|
|
111
|
-
case 'MINUTE':
|
|
112
|
-
formatDisplay = 'mm';
|
|
113
|
-
break;
|
|
114
|
-
default:
|
|
115
|
-
formatDisplay = `DD/MM/YYYY - ${isStartDate ? '00:00:00' : '23:59:59'}`;
|
|
116
|
-
timeFormatDisplay = isStartDate ? '00:00:00' : '23:59:59';
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
if (formatInputDisplay) {
|
|
120
|
-
formatDisplay = formatInputDisplay;
|
|
121
|
-
}
|
|
122
|
-
return [formatDisplay, timeFormatDisplay];
|
|
123
|
-
}, [valueType, operatorKey, type, formatInputDisplay]);
|
|
52
|
+
const { formatDisplay } = getFormatDisplay(operatorKey, type, valueType, formatInputDisplay);
|
|
124
53
|
// State
|
|
125
54
|
const [state, setState] = useState({
|
|
126
55
|
isOpen: false,
|
|
@@ -168,6 +97,10 @@ export const AdvancedPicker = props => {
|
|
|
168
97
|
borderRadius: token.borderRadius,
|
|
169
98
|
boxShadow: token.boxShadowSecondary,
|
|
170
99
|
};
|
|
100
|
+
const selectedDateTitle = dayjs(dateDisplay, format)
|
|
101
|
+
.format(formatDisplay)
|
|
102
|
+
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
103
|
+
.replace(WEEK_PLACEHOLDER, 'Week ');
|
|
171
104
|
// Effects
|
|
172
105
|
useEffect(() => {
|
|
173
106
|
try {
|
|
@@ -243,69 +176,6 @@ export const AdvancedPicker = props => {
|
|
|
243
176
|
}, [propsOption, propsDate, format]);
|
|
244
177
|
// Handlers
|
|
245
178
|
const disableDate = current => current > dayjs(disableAfterDate, format) || current < dayjs(disableBeforeDate, format);
|
|
246
|
-
const renderLabel = (date, locale = 'en') => {
|
|
247
|
-
let formatLabel = 'dddd, MMMM DD, YYYY';
|
|
248
|
-
let subLabel = '';
|
|
249
|
-
switch (valueType) {
|
|
250
|
-
case 'YEAR':
|
|
251
|
-
formatLabel = 'YYYY';
|
|
252
|
-
break;
|
|
253
|
-
case 'YEAR_QUARTER':
|
|
254
|
-
formatLabel = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
255
|
-
subLabel = getLabelQuarterRange(date, format || DEFAULT_DATE_FORMAT, locale);
|
|
256
|
-
break;
|
|
257
|
-
case 'YEAR_MONTH':
|
|
258
|
-
formatLabel = 'MMMM, YYYY';
|
|
259
|
-
break;
|
|
260
|
-
case 'YEAR_WEEK': {
|
|
261
|
-
const dayObj = dayjs(date || new Date(), format).locale(locale || 'en');
|
|
262
|
-
formatLabel = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
263
|
-
subLabel = `${dayjs(dayObj).day(0).format('MMMM DD, YYYY')} - ${dayjs(dayObj)
|
|
264
|
-
.day(6)
|
|
265
|
-
.format('MMMM DD, YYYY')}`;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
case 'YEAR_MONTH_DAY_HOUR':
|
|
269
|
-
formatLabel = 'dddd, MMMM DD, YYYY';
|
|
270
|
-
break;
|
|
271
|
-
case 'QUARTER':
|
|
272
|
-
formatLabel = `${QUARTER_PLACEHOLDER}Q`;
|
|
273
|
-
break;
|
|
274
|
-
case 'MONTH':
|
|
275
|
-
formatLabel = 'MMMM';
|
|
276
|
-
break;
|
|
277
|
-
case 'WEEK':
|
|
278
|
-
formatLabel = `${WEEK_PLACEHOLDER}W`;
|
|
279
|
-
break;
|
|
280
|
-
case 'MONTH_DAY':
|
|
281
|
-
formatLabel = 'MMMM DD';
|
|
282
|
-
break;
|
|
283
|
-
case 'DAY_OF_WEEK':
|
|
284
|
-
formatLabel = 'dddd';
|
|
285
|
-
break;
|
|
286
|
-
case 'DAY':
|
|
287
|
-
formatLabel = 'DD';
|
|
288
|
-
break;
|
|
289
|
-
case 'HOUR':
|
|
290
|
-
formatLabel = 'HH:00:00';
|
|
291
|
-
break;
|
|
292
|
-
case 'MINUTE':
|
|
293
|
-
formatLabel = '00:mm:00';
|
|
294
|
-
break;
|
|
295
|
-
default:
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
return (React.createElement(React.Fragment, null,
|
|
299
|
-
React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
300
|
-
.locale(locale || 'en')
|
|
301
|
-
.format(formatLabel)
|
|
302
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
303
|
-
.replace(WEEK_PLACEHOLDER, 'Week ')),
|
|
304
|
-
subLabel ? React.createElement("div", null, subLabel) : null,
|
|
305
|
-
!HIDE_TIME_LABEL_ARR.includes(valueType || '') && showTime && !subLabel ? (React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
306
|
-
.locale(locale || 'en')
|
|
307
|
-
.format(timeFormatDisplay))) : null));
|
|
308
|
-
};
|
|
309
179
|
const toggleOpenDropdown = (isOpen) => {
|
|
310
180
|
try {
|
|
311
181
|
setState(() => (Object.assign(Object.assign({}, state), { isOpen: isOpen != null ? isOpen : !state.isOpen })));
|
|
@@ -370,13 +240,6 @@ export const AdvancedPicker = props => {
|
|
|
370
240
|
});
|
|
371
241
|
}
|
|
372
242
|
};
|
|
373
|
-
const renderDropdownLabel = () => {
|
|
374
|
-
var _a;
|
|
375
|
-
const title = (_a = Object.values(ADVANCED_PICKER_TYPE).find(({ value }) => value === type)) === null || _a === void 0 ? void 0 : _a.label;
|
|
376
|
-
return (React.createElement("div", { style: { textAlign: 'center' } },
|
|
377
|
-
title && operatorKey === 'between' && (React.createElement(Text, { className: "__title", style: { color: '#666666' } }, t(title))),
|
|
378
|
-
renderLabel(date, 'en')));
|
|
379
|
-
};
|
|
380
243
|
const renderDropdownFooter = () => (React.createElement(React.Fragment, null,
|
|
381
244
|
React.createElement(Divider, null),
|
|
382
245
|
React.createElement(DropdownFooter, null,
|
|
@@ -391,19 +254,13 @@ export const AdvancedPicker = props => {
|
|
|
391
254
|
onChangeOption({ dateType });
|
|
392
255
|
}, 100);
|
|
393
256
|
} }));
|
|
394
|
-
const renderErrorMessage = () => {
|
|
395
|
-
var _a;
|
|
396
|
-
return errorMessage ? (React.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: 5 } },
|
|
397
|
-
React.createElement(Icon, { type: "icon-ants-remove-circle", style: { color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorError } }),
|
|
398
|
-
React.createElement(Text, { type: "danger" }, errorMessage))) : null;
|
|
399
|
-
};
|
|
400
257
|
// NOTE: valueType: 'WEEK'; 'DAY_OF_WEEK'; 'MONTH_DAY'; 'DAY'
|
|
401
|
-
const customPickerArr =
|
|
258
|
+
const customPickerArr = {
|
|
402
259
|
WEEK: WEEK_ARR,
|
|
403
260
|
DAY_OF_WEEK: DAY_LABEL_SHORT,
|
|
404
261
|
MONTH_DAY: DAY_OF_MONTH[currMonthSelected],
|
|
405
262
|
DAY: DAY_OF_MONTH[0],
|
|
406
|
-
}
|
|
263
|
+
};
|
|
407
264
|
const dropdownRender = () => {
|
|
408
265
|
// const customPickerArr = valueType === 'WEEK' ? WEEK_ARR : DAY_LABEL_SHORT;
|
|
409
266
|
const currWeek = dayjs(date, format).isoWeek();
|
|
@@ -439,7 +296,8 @@ export const AdvancedPicker = props => {
|
|
|
439
296
|
}
|
|
440
297
|
};
|
|
441
298
|
return (React.createElement("div", { style: contentStyle },
|
|
442
|
-
React.createElement(DropdownHeader, { className: "dropdown-header" },
|
|
299
|
+
React.createElement(DropdownHeader, { className: "dropdown-header" },
|
|
300
|
+
React.createElement(DropdownLabel, { valueType: valueType, date: date, format: format, type: type, showTime: showTime, operatorKey: operatorKey, formatInputDisplay: formatInputDisplay })),
|
|
443
301
|
React.createElement(DropdownContent, { className: "dropdown-content" },
|
|
444
302
|
renderDateTypeOptions(),
|
|
445
303
|
option.dateType.value === 'fixed' ? (React.createElement(React.Fragment, null,
|
|
@@ -460,15 +318,15 @@ export const AdvancedPicker = props => {
|
|
|
460
318
|
const calculationType = CALCULATION_TYPES.find(calculationType => calculationType.value === value);
|
|
461
319
|
onChangeOption({ calculationType });
|
|
462
320
|
} }),
|
|
463
|
-
React.createElement(InputNumber, { value: option.value, style: { width: '100%' }, min: 0, showHandler: false, onChange: value => onChangeOption({ value }) }),
|
|
321
|
+
React.createElement(InputNumber, { value: option.value, style: { width: '100%' }, min: 0, showHandler: false, onChange: value => onChangeOption({ value: Math.floor(value) }) }),
|
|
464
322
|
React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationDates.map(calculationDate => (Object.assign(Object.assign({}, calculationDate), { label: t(calculationDate.label) }))), value: option.calculationDate.value, onChange: value => {
|
|
465
323
|
const calculationDate = newCalculationDates.find(calculationDate => calculationDate.value === value);
|
|
466
324
|
onChangeOption({ calculationDate });
|
|
467
325
|
} }))),
|
|
468
|
-
|
|
326
|
+
React.createElement(ErrorMessage, { errorMessage: errorMessage })),
|
|
469
327
|
renderDropdownFooter()));
|
|
470
328
|
};
|
|
471
|
-
const cellRender =
|
|
329
|
+
const cellRender = useCallback((current, info) => {
|
|
472
330
|
const onChangeDatePicker = (value) => {
|
|
473
331
|
try {
|
|
474
332
|
setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(value).format(format) })));
|
|
@@ -516,14 +374,8 @@ export const AdvancedPicker = props => {
|
|
|
516
374
|
return (React.createElement(Space, { direction: "vertical", size: 5, className: "antsomi-advanced-picker-container" },
|
|
517
375
|
!!label && typeof label === 'string' ? (React.createElement(Text, { style: { color: '#666666' } }, label)) : (label),
|
|
518
376
|
option.dateType.value === 'fixed' &&
|
|
519
|
-
!['WEEK', 'DAY_OF_WEEK', 'MONTH_DAY', 'DAY'].includes(valueType || 'YEAR_MONTH_DAY') ? (React.createElement(Tooltip, { title:
|
|
520
|
-
|
|
521
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
522
|
-
.replace(WEEK_PLACEHOLDER, 'Week ') },
|
|
523
|
-
React.createElement(DatePicker, { disabled: disabled, open: !disabled && isOpen, allowClear: false, inputReadOnly: true, status: errorMessage ? 'error' : '', inputRender: () => (React.createElement(DatePickerCustomInput, { readOnly: true, placeholder: "Select Date", value: dayjs(dateDisplay, format)
|
|
524
|
-
.format(formatDisplay)
|
|
525
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
526
|
-
.replace(WEEK_PLACEHOLDER, 'Week '), onClick: () => toggleOpenDropdown() })), value: dayjs(date, format), style: {
|
|
377
|
+
!['WEEK', 'DAY_OF_WEEK', 'MONTH_DAY', 'DAY'].includes(valueType || 'YEAR_MONTH_DAY') ? (React.createElement(Tooltip, { title: selectedDateTitle },
|
|
378
|
+
React.createElement(DatePicker, { disabled: disabled, open: !disabled && isOpen, allowClear: false, inputReadOnly: true, status: errorMessage ? 'error' : '', inputRender: () => (React.createElement(DatePickerCustomInput, { readOnly: true, placeholder: "Select Date", value: selectedDateTitle, onClick: () => toggleOpenDropdown() })), value: dayjs(date, format), style: {
|
|
527
379
|
width: 120,
|
|
528
380
|
}, disabledDate: disableDate, format: formatDisplay, showToday: false, popupClassName: clsx('antsomi-picker-dropdown__advanced', {
|
|
529
381
|
'--error': errorMessage,
|
|
@@ -533,10 +385,11 @@ export const AdvancedPicker = props => {
|
|
|
533
385
|
'is-hours-picker': valueType === 'HOUR',
|
|
534
386
|
}), renderExtraFooter: () => (React.createElement(React.Fragment, null,
|
|
535
387
|
React.createElement(DatePickerHeader, null,
|
|
536
|
-
|
|
388
|
+
React.createElement(DropdownLabel, { valueType: valueType, date: date, format: format, type: type, showTime: showTime, operatorKey: operatorKey, formatInputDisplay: formatInputDisplay }),
|
|
537
389
|
renderDateTypeOptions()),
|
|
538
390
|
React.createElement(DatePickerFooter, null,
|
|
539
|
-
React.createElement("div", { style: { padding: '0 10px' } },
|
|
391
|
+
React.createElement("div", { style: { padding: '0 10px' } },
|
|
392
|
+
React.createElement(ErrorMessage, { errorMessage: errorMessage })),
|
|
540
393
|
renderDropdownFooter()),
|
|
541
394
|
React.createElement(Divider, null))), picker: getPickerRender(valueType || 'YEAR_MONTH_DAY'), showTime: getTimePickerRender(valueType || 'YEAR_MONTH_DAY')
|
|
542
395
|
? {
|
|
@@ -546,17 +399,11 @@ export const AdvancedPicker = props => {
|
|
|
546
399
|
pointerEvents: disabled ? 'none' : 'all',
|
|
547
400
|
}, onClick: () => toggleOpenDropdown() },
|
|
548
401
|
React.createElement(EventIcon, { width: 20, height: 20, fill: errorMessage ? (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorError : (_b = THEME.token) === null || _b === void 0 ? void 0 : _b.bw10 })), cellRender: cellRender, onOpenChange: () => toggleOpenDropdown() }))) : (React.createElement(Dropdown, { disabled: disabled, open: !disabled && isOpen, dropdownRender: dropdownRender, trigger: ['click'], onOpenChange: () => toggleOpenDropdown(), overlayStyle: { width: 'fit-content', minWidth: 'auto' } },
|
|
549
|
-
React.createElement(Tooltip, { title:
|
|
550
|
-
.format(formatDisplay)
|
|
551
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
552
|
-
.replace(WEEK_PLACEHOLDER, 'Week ') },
|
|
402
|
+
React.createElement(Tooltip, { title: selectedDateTitle },
|
|
553
403
|
React.createElement(Input, { disabled: disabled, onClick: () => toggleOpenDropdown(), readOnly: true, suffix: React.createElement(CalendarIconWrapper, { style: {
|
|
554
404
|
pointerEvents: disabled ? 'none' : 'all',
|
|
555
405
|
}, onClick: () => toggleOpenDropdown() },
|
|
556
|
-
React.createElement(EventIcon, { width: 19, height: 19 })), style: inputStyle, value:
|
|
557
|
-
.format(formatDisplay)
|
|
558
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
559
|
-
.replace(WEEK_PLACEHOLDER, 'Week '), status: errorMessage ? 'error' : '' }))))));
|
|
406
|
+
React.createElement(EventIcon, { width: 19, height: 19 })), style: inputStyle, value: selectedDateTitle, status: errorMessage ? 'error' : '' }))))));
|
|
560
407
|
};
|
|
561
408
|
AdvancedPicker.defaultProps = {
|
|
562
409
|
label: '',
|
|
@@ -3,6 +3,18 @@ export declare const DATE_TYPES: {
|
|
|
3
3
|
value: string;
|
|
4
4
|
label: string;
|
|
5
5
|
}[];
|
|
6
|
+
export declare const DATE_TYPE_MAPPING: {
|
|
7
|
+
first_day_of_week_mon_sun: string;
|
|
8
|
+
first_day_of_week_sun_sat: string;
|
|
9
|
+
first_day_of_month: string;
|
|
10
|
+
first_day_of_quarter: string;
|
|
11
|
+
first_day_of_year: string;
|
|
12
|
+
last_day_of_week_mon_sun: string;
|
|
13
|
+
last_day_of_week_sun_sat: string;
|
|
14
|
+
last_day_of_month: string;
|
|
15
|
+
last_day_of_quarter: string;
|
|
16
|
+
last_day_of_year: string;
|
|
17
|
+
};
|
|
6
18
|
export declare const CALCULATION_TYPES: {
|
|
7
19
|
value: string;
|
|
8
20
|
label: string;
|
|
@@ -12,6 +12,18 @@ export const DATE_TYPES = [
|
|
|
12
12
|
{ value: 'last_day_of_year', label: 'datePicker.dateTypes.lastDayOfYear' },
|
|
13
13
|
{ value: 'fixed', label: 'datePicker.dateTypes.fixed' },
|
|
14
14
|
];
|
|
15
|
+
export const DATE_TYPE_MAPPING = {
|
|
16
|
+
first_day_of_week_mon_sun: 'isoWeek',
|
|
17
|
+
first_day_of_week_sun_sat: 'week',
|
|
18
|
+
first_day_of_month: 'month',
|
|
19
|
+
first_day_of_quarter: 'quarter',
|
|
20
|
+
first_day_of_year: 'year',
|
|
21
|
+
last_day_of_week_mon_sun: 'isoWeek',
|
|
22
|
+
last_day_of_week_sun_sat: 'week',
|
|
23
|
+
last_day_of_month: 'month',
|
|
24
|
+
last_day_of_quarter: 'quarter',
|
|
25
|
+
last_day_of_year: 'year',
|
|
26
|
+
};
|
|
15
27
|
export const CALCULATION_TYPES = [
|
|
16
28
|
{ value: 'minus', label: 'global.minus' },
|
|
17
29
|
{ value: 'plus', label: 'global.plus' },
|
|
@@ -3,7 +3,7 @@ var _a, _b, _c, _d, _e;
|
|
|
3
3
|
import { THEME } from '../../../../../constants';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
export const DropdownContent = styled.div `
|
|
6
|
-
width:
|
|
6
|
+
width: 250px;
|
|
7
7
|
padding: 10px 10px 0px 10px;
|
|
8
8
|
display: flex;
|
|
9
9
|
flex-direction: column;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Dayjs } from 'dayjs';
|
|
2
2
|
import type { CellRenderInfo } from 'rc-picker/es/interface';
|
|
3
|
-
import { ValueTypes } from './types';
|
|
3
|
+
import { TAdvancedType, TOperatorKey, ValueTypes } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Calculates a new date based on the given parameters.
|
|
6
6
|
* @param {string} [dateTypeKey='today'] - Key to determine the type of date to be used as the starting point.
|
|
@@ -33,3 +33,7 @@ export declare const getPickerRender: (valueType: ValueTypes) => 'date' | 'week'
|
|
|
33
33
|
export declare const getTimePickerRender: (valueType: ValueTypes) => "HH" | "HHmm" | "HHmmss" | "mm" | undefined;
|
|
34
34
|
export declare function getLabelQuarterRange(day: string, format: string, locale: string, showYear?: boolean): string;
|
|
35
35
|
export declare function getLabelQuarterRange(quarter: number, year?: number): string;
|
|
36
|
+
export declare const getFormatDisplay: (operatorKey?: TOperatorKey, type?: TAdvancedType, valueType?: ValueTypes, formatInputDisplay?: string) => {
|
|
37
|
+
formatDisplay: string;
|
|
38
|
+
timeFormatDisplay: string;
|
|
39
|
+
};
|
|
@@ -4,7 +4,7 @@ import dayjs from 'dayjs';
|
|
|
4
4
|
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
5
5
|
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
6
6
|
// Constants
|
|
7
|
-
import { DEFAULT_DATE_FORMAT, MONTH_LABEL_SHORT } from './constants';
|
|
7
|
+
import { DATE_TYPE_MAPPING, DEFAULT_DATE_FORMAT, MONTH_LABEL_SHORT, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, } from './constants';
|
|
8
8
|
dayjs.extend(isoWeek);
|
|
9
9
|
dayjs.extend(quarterOfYear);
|
|
10
10
|
/**
|
|
@@ -23,43 +23,12 @@ dayjs.extend(quarterOfYear);
|
|
|
23
23
|
*/
|
|
24
24
|
export const calculationDateAdvanced = (dateTypeKey = 'today', calculationTypeKey = 'minus', calculationDateKey = 'days', value = 0, dateFormat = DEFAULT_DATE_FORMAT) => {
|
|
25
25
|
let date = dayjs();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
date
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
break;
|
|
33
|
-
case 'first_day_of_week_sun_sat':
|
|
34
|
-
date = dayjs().startOf('week');
|
|
35
|
-
break;
|
|
36
|
-
case 'first_day_of_month':
|
|
37
|
-
date = dayjs().startOf('month');
|
|
38
|
-
break;
|
|
39
|
-
case 'first_day_of_quarter':
|
|
40
|
-
date = dayjs().startOf('quarter');
|
|
41
|
-
break;
|
|
42
|
-
case 'first_day_of_year':
|
|
43
|
-
date = dayjs().startOf('year');
|
|
44
|
-
break;
|
|
45
|
-
case 'last_day_of_week_mon_sun':
|
|
46
|
-
date = dayjs().endOf('isoWeek');
|
|
47
|
-
break;
|
|
48
|
-
case 'last_day_of_week_sun_sat':
|
|
49
|
-
date = dayjs().endOf('week');
|
|
50
|
-
break;
|
|
51
|
-
case 'last_day_of_month':
|
|
52
|
-
date = dayjs().endOf('month');
|
|
53
|
-
break;
|
|
54
|
-
case 'last_day_of_quarter':
|
|
55
|
-
date = dayjs().endOf('quarter');
|
|
56
|
-
break;
|
|
57
|
-
case 'last_day_of_year':
|
|
58
|
-
date = dayjs().endOf('year');
|
|
59
|
-
break;
|
|
60
|
-
default:
|
|
61
|
-
date = dayjs();
|
|
62
|
-
break;
|
|
26
|
+
if (DATE_TYPE_MAPPING[dateTypeKey]) {
|
|
27
|
+
date = dateTypeKey.includes('first_day')
|
|
28
|
+
? date.startOf(DATE_TYPE_MAPPING[dateTypeKey])
|
|
29
|
+
: dateTypeKey.includes('last_day')
|
|
30
|
+
? date.endOf(DATE_TYPE_MAPPING[dateTypeKey])
|
|
31
|
+
: dayjs();
|
|
63
32
|
}
|
|
64
33
|
let newDate = '';
|
|
65
34
|
newDate =
|
|
@@ -171,3 +140,66 @@ export function getLabelQuarterRange(quarterOrDay, yearOrFormat, locale, showYea
|
|
|
171
140
|
? `${startMonthQuarter[currQuarter]} 01, ${currYear} - ${endMonthQuarter[currQuarter]} ${endDayQuarter[currQuarter]}, ${currYear}`
|
|
172
141
|
: `${startMonthQuarter[currQuarter]} 01 - ${endMonthQuarter[currQuarter]} ${endDayQuarter[currQuarter]}`;
|
|
173
142
|
}
|
|
143
|
+
export const getFormatDisplay = (operatorKey, type, valueType, formatInputDisplay) => {
|
|
144
|
+
let formatDisplay = '';
|
|
145
|
+
let timeFormatDisplay = '';
|
|
146
|
+
const isStartDate = operatorKey === 'between' ? type === 'startDate' : operatorKey === 'after';
|
|
147
|
+
switch (valueType) {
|
|
148
|
+
case 'YEAR':
|
|
149
|
+
formatDisplay = 'YYYY';
|
|
150
|
+
break;
|
|
151
|
+
case 'YEAR_QUARTER':
|
|
152
|
+
formatDisplay = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
153
|
+
break;
|
|
154
|
+
case 'YEAR_MONTH':
|
|
155
|
+
formatDisplay = 'MMMM, YYYY';
|
|
156
|
+
break;
|
|
157
|
+
case 'YEAR_WEEK':
|
|
158
|
+
formatDisplay = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
159
|
+
break;
|
|
160
|
+
case 'YEAR_MONTH_DAY':
|
|
161
|
+
formatDisplay = 'MMMM DD, YYYY';
|
|
162
|
+
break;
|
|
163
|
+
case 'YEAR_MONTH_DAY_HOUR':
|
|
164
|
+
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:00:00' : 'HH:59:59'}`;
|
|
165
|
+
timeFormatDisplay = isStartDate ? 'HH:00:00' : 'HH:59:59';
|
|
166
|
+
break;
|
|
167
|
+
case 'YEAR_MONTH_DAY_MINUTE':
|
|
168
|
+
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:mm:00' : 'HH:mm:59'}`;
|
|
169
|
+
timeFormatDisplay = isStartDate ? 'HH:mm:00' : 'HH:mm:59';
|
|
170
|
+
break;
|
|
171
|
+
case 'YEAR_MONTH_DAY_SECOND':
|
|
172
|
+
formatDisplay = 'MMMM DD, YYYY HH:mm:ss';
|
|
173
|
+
timeFormatDisplay = 'HH:mm:ss';
|
|
174
|
+
break;
|
|
175
|
+
case 'QUARTER':
|
|
176
|
+
formatDisplay = `${QUARTER_PLACEHOLDER}Q`;
|
|
177
|
+
break;
|
|
178
|
+
case 'MONTH':
|
|
179
|
+
formatDisplay = 'MMMM';
|
|
180
|
+
break;
|
|
181
|
+
case 'WEEK':
|
|
182
|
+
formatDisplay = `${WEEK_PLACEHOLDER}W`;
|
|
183
|
+
break;
|
|
184
|
+
case 'MONTH_DAY':
|
|
185
|
+
formatDisplay = 'MMMM DD';
|
|
186
|
+
break;
|
|
187
|
+
case 'DAY_OF_WEEK':
|
|
188
|
+
formatDisplay = 'dddd';
|
|
189
|
+
break;
|
|
190
|
+
case 'DAY':
|
|
191
|
+
formatDisplay = 'DD';
|
|
192
|
+
break;
|
|
193
|
+
case 'HOUR':
|
|
194
|
+
formatDisplay = 'HH';
|
|
195
|
+
break;
|
|
196
|
+
case 'MINUTE':
|
|
197
|
+
formatDisplay = 'mm';
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
formatDisplay = `DD/MM/YYYY - ${isStartDate ? '00:00:00' : '23:59:59'}`;
|
|
201
|
+
timeFormatDisplay = isStartDate ? '00:00:00' : '23:59:59';
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
return { formatDisplay: formatInputDisplay || formatDisplay, timeFormatDisplay };
|
|
205
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TAdvancedType, TOperatorKey, ValueTypes } from '../AdvancedPicker/types';
|
|
3
|
+
interface DropdownLabelProps {
|
|
4
|
+
valueType?: ValueTypes;
|
|
5
|
+
date?: string;
|
|
6
|
+
format?: string;
|
|
7
|
+
type?: TAdvancedType;
|
|
8
|
+
showTime?: boolean;
|
|
9
|
+
operatorKey?: TOperatorKey;
|
|
10
|
+
formatInputDisplay?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const DropdownLabel: React.FC<DropdownLabelProps>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
// Components
|
|
5
|
+
import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
6
|
+
// Constants
|
|
7
|
+
import { ADVANCED_PICKER_TYPE, DEFAULT_DATE_FORMAT, HIDE_TIME_LABEL_ARR, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, } from '../AdvancedPicker/constants';
|
|
8
|
+
// Instance
|
|
9
|
+
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
10
|
+
import { getFormatDisplay, getLabelQuarterRange } from '../AdvancedPicker/utils';
|
|
11
|
+
export const DropdownLabel = React.memo(({ valueType, date, format, type, showTime, operatorKey, formatInputDisplay }) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const { t } = i18nInstance;
|
|
14
|
+
const title = (_a = Object.values(ADVANCED_PICKER_TYPE).find(({ value }) => value === type)) === null || _a === void 0 ? void 0 : _a.label;
|
|
15
|
+
const { timeFormatDisplay } = getFormatDisplay(operatorKey, type, valueType, formatInputDisplay);
|
|
16
|
+
let formatLabel = 'dddd, MMMM DD, YYYY';
|
|
17
|
+
let subLabel = '';
|
|
18
|
+
switch (valueType) {
|
|
19
|
+
case 'YEAR':
|
|
20
|
+
formatLabel = 'YYYY';
|
|
21
|
+
break;
|
|
22
|
+
case 'YEAR_QUARTER':
|
|
23
|
+
formatLabel = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
24
|
+
subLabel = getLabelQuarterRange(date, format || DEFAULT_DATE_FORMAT, 'en');
|
|
25
|
+
// subLabel = getLabelQuarterRange(date!, format || DEFAULT_DATE_FORMAT, locale);
|
|
26
|
+
break;
|
|
27
|
+
case 'YEAR_MONTH':
|
|
28
|
+
formatLabel = 'MMMM, YYYY';
|
|
29
|
+
break;
|
|
30
|
+
case 'YEAR_WEEK': {
|
|
31
|
+
const dayObj = dayjs(date || new Date(), format).locale('en');
|
|
32
|
+
// const dayObj = dayjs(date || new Date(), format).locale(locale || 'en');
|
|
33
|
+
formatLabel = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
34
|
+
subLabel = `${dayjs(dayObj).day(0).format('MMMM DD, YYYY')} - ${dayjs(dayObj)
|
|
35
|
+
.day(6)
|
|
36
|
+
.format('MMMM DD, YYYY')}`;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 'YEAR_MONTH_DAY_HOUR':
|
|
40
|
+
formatLabel = 'dddd, MMMM DD, YYYY';
|
|
41
|
+
break;
|
|
42
|
+
case 'QUARTER':
|
|
43
|
+
formatLabel = `${QUARTER_PLACEHOLDER}Q`;
|
|
44
|
+
break;
|
|
45
|
+
case 'MONTH':
|
|
46
|
+
formatLabel = 'MMMM';
|
|
47
|
+
break;
|
|
48
|
+
case 'WEEK':
|
|
49
|
+
formatLabel = `${WEEK_PLACEHOLDER}W`;
|
|
50
|
+
break;
|
|
51
|
+
case 'MONTH_DAY':
|
|
52
|
+
formatLabel = 'MMMM DD';
|
|
53
|
+
break;
|
|
54
|
+
case 'DAY_OF_WEEK':
|
|
55
|
+
formatLabel = 'dddd';
|
|
56
|
+
break;
|
|
57
|
+
case 'DAY':
|
|
58
|
+
formatLabel = 'DD';
|
|
59
|
+
break;
|
|
60
|
+
case 'HOUR':
|
|
61
|
+
formatLabel = 'HH:00:00';
|
|
62
|
+
break;
|
|
63
|
+
case 'MINUTE':
|
|
64
|
+
formatLabel = '00:mm:00';
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return (React.createElement("div", { style: { textAlign: 'center' } },
|
|
70
|
+
title && operatorKey === 'between' && (React.createElement(Typography.Text, { className: "__title", style: { color: '#666666' } }, t(title))),
|
|
71
|
+
React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
72
|
+
.locale('en')
|
|
73
|
+
// .locale(locale || 'en')
|
|
74
|
+
.format(formatLabel)
|
|
75
|
+
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
76
|
+
.replace(WEEK_PLACEHOLDER, 'Week ')),
|
|
77
|
+
subLabel ? React.createElement("div", null, subLabel) : null,
|
|
78
|
+
!HIDE_TIME_LABEL_ARR.includes(valueType || '') && showTime && !subLabel ? (React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
79
|
+
.locale('en')
|
|
80
|
+
// .locale(locale || 'en')
|
|
81
|
+
.format(timeFormatDisplay))) : null));
|
|
82
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Icon from '@antscorp/icons';
|
|
3
|
+
import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
4
|
+
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
5
|
+
export const ErrorMessage = React.memo(({ errorMessage }) => {
|
|
6
|
+
var _a;
|
|
7
|
+
if (!errorMessage)
|
|
8
|
+
return null;
|
|
9
|
+
return (React.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: 5 } },
|
|
10
|
+
React.createElement(Icon, { type: "icon-ants-remove-circle", style: { color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorError } }),
|
|
11
|
+
React.createElement(Typography.Text, { type: "danger" }, errorMessage)));
|
|
12
|
+
});
|