@antscorp/antsomi-ui 1.3.3-beta.91 → 1.3.3-beta.92
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/molecules/DatePicker/components/AdvancedPicker/AdvancedPicker.js +22 -11
- package/es/components/molecules/DatePicker/components/DropdownLabel/DropdownLabel.d.ts +2 -1
- package/es/components/molecules/DatePicker/components/DropdownLabel/DropdownLabel.js +5 -3
- package/es/hooks/useOutsideClick.d.ts +4 -0
- package/es/hooks/useOutsideClick.js +18 -0
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ import { DatePickerCustomInput, DatePickerHeader, DropdownContent, DropdownHeade
|
|
|
22
22
|
// Constants
|
|
23
23
|
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';
|
|
24
24
|
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
25
|
+
import { useOutsideClick } from '@antscorp/antsomi-ui/es/hooks/useOutsideClick';
|
|
25
26
|
const PATH = '@antscorp/antsomi-ui/es/components/molecules/DatePicker/components/Advanced/DatePickerAdvanced.tsx';
|
|
26
27
|
const { useToken } = theme;
|
|
27
28
|
const { Text } = Typography;
|
|
@@ -177,9 +178,11 @@ export const AdvancedPicker = props => {
|
|
|
177
178
|
date: newDate,
|
|
178
179
|
option: {
|
|
179
180
|
dateType: newDateType.value,
|
|
180
|
-
calculationDate: newDateType.value === '
|
|
181
|
-
calculationType: newDateType.value === '
|
|
182
|
-
|
|
181
|
+
calculationDate: newDateType.value === 'fixed' ? '' : newCalculationDate.value,
|
|
182
|
+
calculationType: newDateType.value === 'fixed'
|
|
183
|
+
? ''
|
|
184
|
+
: newCalculationType.value,
|
|
185
|
+
value: newDateType.value === 'fixed' ? 0 : value,
|
|
183
186
|
},
|
|
184
187
|
});
|
|
185
188
|
}
|
|
@@ -196,9 +199,11 @@ export const AdvancedPicker = props => {
|
|
|
196
199
|
}, [propsOption, newCalculationDates, propsDate, format]);
|
|
197
200
|
// Handlers
|
|
198
201
|
const disableDate = current => current > dayjs(disableAfterDate, format) || current < dayjs(disableBeforeDate, format);
|
|
199
|
-
const toggleOpenDropdown = () => {
|
|
202
|
+
const toggleOpenDropdown = (isOpen) => {
|
|
200
203
|
try {
|
|
201
|
-
setState(() => (Object.assign(Object.assign({}, state), {
|
|
204
|
+
setState(() => (Object.assign(Object.assign({}, state), {
|
|
205
|
+
// isOpen: !state.isOpen,
|
|
206
|
+
isOpen: isOpen != null ? isOpen : !state.isOpen })));
|
|
202
207
|
}
|
|
203
208
|
catch (error) {
|
|
204
209
|
handleError(error, {
|
|
@@ -208,6 +213,7 @@ export const AdvancedPicker = props => {
|
|
|
208
213
|
});
|
|
209
214
|
}
|
|
210
215
|
};
|
|
216
|
+
const { ref } = useOutsideClick(() => toggleOpenDropdown(false));
|
|
211
217
|
const onClickApply = () => {
|
|
212
218
|
try {
|
|
213
219
|
const draftOption = {
|
|
@@ -253,9 +259,9 @@ export const AdvancedPicker = props => {
|
|
|
253
259
|
React.createElement(DropdownFooter, null,
|
|
254
260
|
React.createElement(Space, null,
|
|
255
261
|
React.createElement(Button, { type: "primary", onClick: () => onClickApply() }, "Apply"),
|
|
256
|
-
React.createElement(Button, { type: "default", onClick: () => toggleOpenDropdown() }, "Cancel")),
|
|
262
|
+
React.createElement(Button, { type: "default", onClick: () => toggleOpenDropdown(false) }, "Cancel")),
|
|
257
263
|
option.dateType.value === 'fixed' && React.createElement(Button, { onClick: () => onClickNow() }, "Now"))));
|
|
258
|
-
const renderDateTypeOptions = () => (React.createElement(Select, { options: newDateTypes, value: option.dateType.value, onChange: value => {
|
|
264
|
+
const renderDateTypeOptions = () => (React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newDateTypes, value: option.dateType.value, onChange: value => {
|
|
259
265
|
const dateType = newDateTypes.find(dateType => dateType.value === value);
|
|
260
266
|
onChangeOption({ dateType });
|
|
261
267
|
// toggleOpenDropdown(true);
|
|
@@ -299,9 +305,9 @@ export const AdvancedPicker = props => {
|
|
|
299
305
|
return dayjs(date);
|
|
300
306
|
}
|
|
301
307
|
};
|
|
302
|
-
return (React.createElement("div", { style: contentStyle },
|
|
308
|
+
return (React.createElement("div", { style: contentStyle, ref: ref },
|
|
303
309
|
React.createElement(DropdownHeader, { className: "dropdown-header" },
|
|
304
|
-
React.createElement(DropdownLabel, { valueType: valueType, date: date, format: format, type: type, showTime: showTime, operatorKey: operatorKey, formatInputDisplay: formatInputDisplay })),
|
|
310
|
+
React.createElement(DropdownLabel, { valueType: valueType, date: date, format: format, type: type, showTime: showTime, operatorKey: operatorKey, formatInputDisplay: formatInputDisplay, dateType: option.dateType.value })),
|
|
305
311
|
React.createElement(DropdownContent, { className: "dropdown-content" },
|
|
306
312
|
renderDateTypeOptions(),
|
|
307
313
|
option.dateType.value === 'fixed' ? (React.createElement(React.Fragment, null,
|
|
@@ -371,7 +377,7 @@ export const AdvancedPicker = props => {
|
|
|
371
377
|
onChangeDatePicker(current);
|
|
372
378
|
} }, getCellRender(current, valueType, info)));
|
|
373
379
|
}, [valueType, format, date]);
|
|
374
|
-
return (React.createElement(Space, { direction: "vertical", size: 5, className: "antsomi-advanced-picker-container" },
|
|
380
|
+
return (React.createElement(Space, { direction: "vertical", size: 5, className: "antsomi-advanced-picker-container", ref: ref },
|
|
375
381
|
!!label && typeof label === 'string' ? (React.createElement(Text, { style: { color: '#666666' } }, label)) : (label),
|
|
376
382
|
option.dateType.value === 'fixed' &&
|
|
377
383
|
!['WEEK', 'DAY_OF_WEEK', 'MONTH_DAY', 'DAY'].includes(valueType) ? (React.createElement(Tooltip, { title: selectedDateTitle },
|
|
@@ -400,7 +406,12 @@ export const AdvancedPicker = props => {
|
|
|
400
406
|
: undefined, suffixIcon: React.createElement(CalendarIconWrapper, { style: {
|
|
401
407
|
pointerEvents: disabled ? 'none' : 'all',
|
|
402
408
|
}, onClick: () => toggleOpenDropdown() },
|
|
403
|
-
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 }))) : (React.createElement(Dropdown, { disabled: disabled, open: !disabled && isOpen, dropdownRender: dropdownRender, trigger: ['click'],
|
|
409
|
+
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 }))) : (React.createElement(Dropdown, { disabled: disabled, open: !disabled && isOpen, dropdownRender: dropdownRender, trigger: ['click'],
|
|
410
|
+
// onOpenChange={(open, info) => {
|
|
411
|
+
// console.log('🚀🚀🚀 ', 4, { open, info });
|
|
412
|
+
// toggleOpenDropdown();
|
|
413
|
+
// }}
|
|
414
|
+
overlayStyle: { width: 'fit-content', minWidth: 'auto' } },
|
|
404
415
|
React.createElement(Tooltip, { title: selectedDateTitle },
|
|
405
416
|
React.createElement(Input, { disabled: disabled, onClick: () => toggleOpenDropdown(), readOnly: true, suffix: React.createElement(CalendarIconWrapper, { style: {
|
|
406
417
|
pointerEvents: disabled ? 'none' : 'all',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { TAdvancedType, TOperatorKey, ValueTypes } from '../AdvancedPicker/types';
|
|
2
|
+
import { TAdvancedType, TDateType, TOperatorKey, ValueTypes } from '../AdvancedPicker/types';
|
|
3
3
|
interface DropdownLabelProps {
|
|
4
4
|
valueType?: ValueTypes;
|
|
5
5
|
date?: string;
|
|
@@ -8,6 +8,7 @@ interface DropdownLabelProps {
|
|
|
8
8
|
showTime?: boolean;
|
|
9
9
|
operatorKey?: TOperatorKey;
|
|
10
10
|
formatInputDisplay?: string;
|
|
11
|
+
dateType?: TDateType;
|
|
11
12
|
}
|
|
12
13
|
export declare const DropdownLabel: React.FC<DropdownLabelProps>;
|
|
13
14
|
export {};
|
|
@@ -8,7 +8,7 @@ import { ADVANCED_PICKER_TYPE, DEFAULT_DATE_FORMAT, HIDE_TIME_LABEL_ARR, QUARTER
|
|
|
8
8
|
// Instance
|
|
9
9
|
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
10
10
|
import { getFormatDisplay, getLabelQuarterRange } from '../AdvancedPicker/utils';
|
|
11
|
-
export const DropdownLabel = React.memo(({ valueType, date, format, type, showTime, operatorKey, formatInputDisplay }) => {
|
|
11
|
+
export const DropdownLabel = React.memo(({ valueType, date, format, type, showTime, operatorKey, formatInputDisplay, dateType }) => {
|
|
12
12
|
var _a;
|
|
13
13
|
const { t } = i18nInstance;
|
|
14
14
|
const title = (_a = Object.values(ADVANCED_PICKER_TYPE).find(({ value }) => value === type)) === null || _a === void 0 ? void 0 : _a.label;
|
|
@@ -31,8 +31,10 @@ export const DropdownLabel = React.memo(({ valueType, date, format, type, showTi
|
|
|
31
31
|
const dayObj = dayjs(date || new Date(), format).locale('en');
|
|
32
32
|
// const dayObj = dayjs(date || new Date(), format).locale(locale || 'en');
|
|
33
33
|
formatLabel = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
34
|
-
subLabel = `${dayjs(dayObj)
|
|
35
|
-
.day(
|
|
34
|
+
subLabel = `${dayjs(dayObj)
|
|
35
|
+
.day(['today', 'first_day_of_week_mon_sun'].includes(dateType || '') ? 1 : 0)
|
|
36
|
+
.format('MMMM DD, YYYY')} - ${dayjs(dayObj)
|
|
37
|
+
.day(['today', 'first_day_of_week_mon_sun'].includes(dateType || '') ? 7 : 6)
|
|
36
38
|
.format('MMMM DD, YYYY')}`;
|
|
37
39
|
break;
|
|
38
40
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export const useOutsideClick = callback => {
|
|
3
|
+
const ref = useRef(null);
|
|
4
|
+
const handleClickOutside = event => {
|
|
5
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
6
|
+
if (callback && typeof callback === 'function') {
|
|
7
|
+
callback();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
document.addEventListener('click', handleClickOutside, true);
|
|
13
|
+
return () => {
|
|
14
|
+
document.removeEventListener('click', handleClickOutside, true);
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
return { ref };
|
|
18
|
+
};
|