@antscorp/antsomi-ui 1.3.3-beta.83 → 1.3.3-beta.84

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.
@@ -16,6 +16,9 @@ import dayjs from 'dayjs';
16
16
  import React, { useEffect } from 'react';
17
17
  import weekday from 'dayjs/plugin/weekday';
18
18
  import localeData from 'dayjs/plugin/localeData';
19
+ /** dayjs plugins for timezone */
20
+ import utc from 'dayjs/plugin/utc';
21
+ import timezone from 'dayjs/plugin/timezone';
19
22
  // Constants
20
23
  import { THEME } from '@antscorp/antsomi-ui/es/constants';
21
24
  // Style
@@ -27,6 +30,8 @@ import i18next from '@antscorp/antsomi-ui/es/locales/i18n';
27
30
  // NOTE: HOT fix DatePicker Advanced
28
31
  dayjs.extend(weekday);
29
32
  dayjs.extend(localeData);
33
+ dayjs.extend(utc);
34
+ dayjs.extend(timezone);
30
35
  const ConfigProvider = props => {
31
36
  // Props
32
37
  const { children, locale } = props, restOfProps = __rest(props, ["children", "locale"]);
@@ -19,6 +19,7 @@ export interface AdvancedPickerProps {
19
19
  disableBeforeDate?: string;
20
20
  errorMessage?: string;
21
21
  showTime?: boolean;
22
+ timezone?: string;
22
23
  onUpdatedNewDate?: ({ date, option }: {
23
24
  date: string;
24
25
  option: TOption;
@@ -28,7 +28,7 @@ const { Text } = Typography;
28
28
  export const AdvancedPicker = props => {
29
29
  var _a, _b;
30
30
  // Props
31
- const { label, inputStyle, dateTypeKeysShow, calculationTypeKeysShow, showCalculationTypeCondition, defaultDateTypeKey, valueType, option: propsOption, operatorKey, type, date: propsDate, format, formatInputDisplay, errorMessage, disableAfterDate, disableBeforeDate, showTime, disabled, onUpdatedNewDate, onApply, } = props;
31
+ const { label, inputStyle, dateTypeKeysShow, calculationTypeKeysShow, showCalculationTypeCondition, defaultDateTypeKey, valueType, option: propsOption, operatorKey, type, date: propsDate, format, formatInputDisplay, errorMessage, disableAfterDate, disableBeforeDate, showTime, disabled, timezone, onUpdatedNewDate, onApply, } = props;
32
32
  // Memo
33
33
  const newDateTypes = useMemo(() => {
34
34
  if (dateTypeKeysShow && dateTypeKeysShow.length) {
@@ -60,11 +60,11 @@ export const AdvancedPicker = props => {
60
60
  calculationDate: newCalculationDates[0],
61
61
  value: 0,
62
62
  },
63
- date: dayjs().format(format),
64
- dateDisplay: dayjs().format(format),
63
+ date: dayjs().tz(timezone).format(format),
64
+ dateDisplay: dayjs().tz(timezone).format(format),
65
65
  });
66
66
  const { isOpen, option, date, dateDisplay } = state;
67
- const currDate = dayjs(date, format);
67
+ const currDate = dayjs(date, format).tz(timezone);
68
68
  const currWeek = currDate.isoWeek();
69
69
  const currDay = currDate.day();
70
70
  const currDayOfMonth = currDate.date();
@@ -97,9 +97,10 @@ export const AdvancedPicker = props => {
97
97
  boxShadow: token.boxShadowSecondary,
98
98
  };
99
99
  const selectedDateTitle = useMemo(() => dayjs(dateDisplay, format)
100
+ .tz(timezone)
100
101
  .format(formatDisplay)
101
102
  .replace(QUARTER_PLACEHOLDER, 'Quarter ')
102
- .replace(WEEK_PLACEHOLDER, 'Week '), [dateDisplay, format, formatDisplay]);
103
+ .replace(WEEK_PLACEHOLDER, 'Week '), [dateDisplay, format, formatDisplay, timezone]);
103
104
  const onChangeOption = (params) => {
104
105
  try {
105
106
  setState(state => (Object.assign(Object.assign({}, state), { option: Object.assign(Object.assign({}, state.option), params) })));
@@ -154,8 +155,8 @@ export const AdvancedPicker = props => {
154
155
  let newDate = '';
155
156
  if (newDateType) {
156
157
  if (newDateType.value === 'fixed') {
157
- newDate = dayjs(propsDate, format, true).isValid()
158
- ? dayjs(propsDate, format).format(format)
158
+ newDate = dayjs(propsDate, format, true).tz(timezone).isValid()
159
+ ? dayjs(propsDate, format).tz(timezone).format(format)
159
160
  : propsDate;
160
161
  setState(state => (Object.assign(Object.assign({}, state), { date: newDate, dateDisplay: newDate, optionSelected: Object.assign(Object.assign({}, option), { dateType: newDateType }) })));
161
162
  }
@@ -195,7 +196,8 @@ export const AdvancedPicker = props => {
195
196
  // eslint-disable-next-line react-hooks/exhaustive-deps
196
197
  }, [propsOption, newCalculationDates, propsDate, format]);
197
198
  // Handlers
198
- const disableDate = current => current > dayjs(disableAfterDate, format) || current < dayjs(disableBeforeDate, format);
199
+ const disableDate = current => current > dayjs(disableAfterDate, format).tz(timezone) ||
200
+ current < dayjs(disableBeforeDate, format).tz(timezone);
199
201
  const toggleOpenDropdown = () => {
200
202
  try {
201
203
  setState(() => (Object.assign(Object.assign({}, state), { isOpen: !state.isOpen })));
@@ -238,7 +240,7 @@ export const AdvancedPicker = props => {
238
240
  };
239
241
  const onClickNow = () => {
240
242
  try {
241
- setState(state => (Object.assign(Object.assign({}, state), { date: dayjs().format(format) })));
243
+ setState(state => (Object.assign(Object.assign({}, state), { date: dayjs().tz(timezone).format(format) })));
242
244
  }
243
245
  catch (error) {
244
246
  handleError(error, {
@@ -288,15 +290,19 @@ export const AdvancedPicker = props => {
288
290
  const getNewDate = (item, index) => {
289
291
  switch (valueType) {
290
292
  case 'WEEK':
291
- return dayjs(date).isoWeek(item);
293
+ return dayjs(date).tz(timezone).isoWeek(item);
292
294
  case 'DAY_OF_WEEK':
293
- return dayjs(date).day(index);
295
+ return dayjs(date).tz(timezone).day(index);
294
296
  case 'MONTH_DAY':
295
- return dayjs(date).year(ANCHOR_LEAP_YEAR).month(currMonthSelected).date(item);
297
+ return dayjs(date)
298
+ .tz(timezone)
299
+ .year(ANCHOR_LEAP_YEAR)
300
+ .month(currMonthSelected)
301
+ .date(item);
296
302
  case 'DAY':
297
- return dayjs(date).year(ANCHOR_LEAP_YEAR).month(0).date(item);
303
+ return dayjs(date).tz(timezone).year(ANCHOR_LEAP_YEAR).month(0).date(item);
298
304
  default:
299
- return dayjs(date);
305
+ return dayjs(date).tz(timezone);
300
306
  }
301
307
  };
302
308
  return (React.createElement("div", { style: contentStyle },
@@ -313,7 +319,7 @@ export const AdvancedPicker = props => {
313
319
  'custom-picker-item-selected': getCellSelected(item, index),
314
320
  }), onClick: () => {
315
321
  const newDate = getNewDate(item, index);
316
- setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(newDate).format(format) })));
322
+ setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(newDate).tz(timezone).format(format) })));
317
323
  } }, item)))))) : (React.createElement(React.Fragment, null,
318
324
  React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationTypes, value: option.calculationType.value, onChange: value => {
319
325
  const calculationType = CALCULATION_TYPES.find(calculationType => calculationType.value === value);
@@ -330,7 +336,7 @@ export const AdvancedPicker = props => {
330
336
  const cellRender = useCallback((current, info) => {
331
337
  const onChangeDatePicker = (value) => {
332
338
  try {
333
- setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(value).format(format) })));
339
+ setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(value).tz(timezone).format(format) })));
334
340
  }
335
341
  catch (error) {
336
342
  handleError(error, {
@@ -347,13 +353,13 @@ export const AdvancedPicker = props => {
347
353
  let newDate;
348
354
  switch (info.subType) {
349
355
  case 'hour':
350
- newDate = dayjs(date).hour(current);
356
+ newDate = dayjs(date).tz(timezone).hour(current);
351
357
  break;
352
358
  case 'minute':
353
- newDate = dayjs(date).minute(current);
359
+ newDate = dayjs(date).tz(timezone).minute(current);
354
360
  break;
355
361
  case 'second':
356
- newDate = dayjs(date).second(current);
362
+ newDate = dayjs(date).tz(timezone).second(current);
357
363
  break;
358
364
  default:
359
365
  break;
@@ -370,14 +376,16 @@ export const AdvancedPicker = props => {
370
376
  e.stopPropagation();
371
377
  onChangeDatePicker(current);
372
378
  } }, getCellRender(current, valueType, info)));
373
- }, [valueType, format, date]);
379
+ }, [valueType, format, date, timezone]);
374
380
  return (React.createElement(Space, { direction: "vertical", size: 5, className: "antsomi-advanced-picker-container" },
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 },
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: currDate, style: {
379
- width: 120,
380
- }, disabledDate: disableDate, format: formatDisplay, showToday: false, popupClassName: clsx('antsomi-picker-dropdown__advanced', {
384
+ 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: currDate,
385
+ // style={{
386
+ // width: 120,
387
+ // }}
388
+ disabledDate: disableDate, format: formatDisplay, showToday: false, popupClassName: clsx('antsomi-picker-dropdown__advanced', {
381
389
  '--error': errorMessage,
382
390
  'hide-picker-header': ['QUARTER', 'MONTH'].includes(valueType),
383
391
  'only-show-time-picker': ['HOUR', 'MINUTE'].includes(valueType),
@@ -3,10 +3,15 @@
3
3
  import dayjs from 'dayjs';
4
4
  import isoWeek from 'dayjs/plugin/isoWeek';
5
5
  import quarterOfYear from 'dayjs/plugin/quarterOfYear';
6
+ /** dayjs plugins for timezone */
7
+ import utc from 'dayjs/plugin/utc';
8
+ import timezone from 'dayjs/plugin/timezone';
6
9
  // Constants
7
10
  import { DATE_TYPE_MAPPING, DEFAULT_DATE_FORMAT, MONTH_LABEL_SHORT, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, } from './constants';
8
11
  dayjs.extend(isoWeek);
9
12
  dayjs.extend(quarterOfYear);
13
+ dayjs.extend(utc);
14
+ dayjs.extend(timezone);
10
15
  /**
11
16
  * Calculates a new date based on the given parameters.
12
17
  * @param {string} [dateTypeKey='today'] - Key to determine the type of date to be used as the starting point.
@@ -11,6 +11,7 @@ export interface AdvancedRangePickerProps {
11
11
  errorMessage?: string;
12
12
  showLabel?: boolean;
13
13
  showTime?: boolean;
14
+ timezone?: string;
14
15
  onChange?: ({ timeRange, mode }: TOnChangePayload) => void;
15
16
  }
16
17
  export declare const AdvancedRangePicker: React.FC<AdvancedRangePickerProps>;
@@ -19,7 +19,7 @@ const PATH = '@antscorp/antsomi-ui/es/components/molecules/DatePicker/components
19
19
  export const AdvancedRangePicker = props => {
20
20
  const { t } = i18nInstance;
21
21
  // Props
22
- const { valueType, timeRange, errorMessage, showLabel, startDateConfig, endDateConfig, showTime, showCalculationTypeCondition, disabled, onChange, } = props;
22
+ const { valueType, timeRange, errorMessage, showLabel, startDateConfig, endDateConfig, showTime, showCalculationTypeCondition, disabled, timezone, onChange, } = props;
23
23
  const [timeRangeState, setTimeRange] = useState(timeRange);
24
24
  useDeepCompareEffect(() => {
25
25
  if (typeof onChange === 'function') {
@@ -55,8 +55,8 @@ export const AdvancedRangePicker = props => {
55
55
  }
56
56
  };
57
57
  return (React.createElement(Space, { size: 20 },
58
- React.createElement(AdvancedPicker, { valueType: valueType, disabled: disabled, label: showLabel ? t(translations.datePicker.startDate) || '' : '', date: timeRange.startDate.date, option: omit(timeRange.startDate, 'date'), operatorKey: "between", type: "startDate", format: ADVANCED_RANGE_PICKER_FORMAT.startDate, errorMessage: errorMessage, disableAfterDate: timeRange.endDate.date, showTime: showTime, calculationTypeKeysShow: startDateConfig === null || startDateConfig === void 0 ? void 0 : startDateConfig.calculationTypeKeysShow, showCalculationTypeCondition: showCalculationTypeCondition, onUpdatedNewDate: ({ date }) => onUpdateTimeRange('startDate', { date }, 'system'), onApply: ({ date, option }) => onUpdateTimeRange('startDate', Object.assign({ date }, option), 'user') }),
59
- React.createElement(AdvancedPicker, { valueType: valueType, disabled: disabled, label: showLabel ? t(translations.datePicker.endDate) || '' : '', date: timeRange.endDate.date, option: omit(timeRange.endDate, 'date'), operatorKey: "between", type: "endDate", format: ADVANCED_RANGE_PICKER_FORMAT.endDate, errorMessage: errorMessage, showTime: showTime, calculationTypeKeysShow: endDateConfig === null || endDateConfig === void 0 ? void 0 : endDateConfig.calculationTypeKeysShow, showCalculationTypeCondition: showCalculationTypeCondition, onUpdatedNewDate: ({ date }) => onUpdateTimeRange('endDate', { date }, 'system'), onApply: ({ date, option }) => onUpdateTimeRange('endDate', Object.assign({ date }, option), 'user') })));
58
+ React.createElement(AdvancedPicker, { valueType: valueType, disabled: disabled, label: showLabel ? t(translations.datePicker.startDate) || '' : '', date: timeRange.startDate.date, option: omit(timeRange.startDate, 'date'), operatorKey: "between", type: "startDate", format: ADVANCED_RANGE_PICKER_FORMAT.startDate, errorMessage: errorMessage, disableAfterDate: timeRange.endDate.date, showTime: showTime, calculationTypeKeysShow: startDateConfig === null || startDateConfig === void 0 ? void 0 : startDateConfig.calculationTypeKeysShow, showCalculationTypeCondition: showCalculationTypeCondition, timezone: timezone, onUpdatedNewDate: ({ date }) => onUpdateTimeRange('startDate', { date }, 'system'), onApply: ({ date, option }) => onUpdateTimeRange('startDate', Object.assign({ date }, option), 'user') }),
59
+ React.createElement(AdvancedPicker, { valueType: valueType, disabled: disabled, label: showLabel ? t(translations.datePicker.endDate) || '' : '', date: timeRange.endDate.date, option: omit(timeRange.endDate, 'date'), operatorKey: "between", type: "endDate", format: ADVANCED_RANGE_PICKER_FORMAT.endDate, errorMessage: errorMessage, showTime: showTime, calculationTypeKeysShow: endDateConfig === null || endDateConfig === void 0 ? void 0 : endDateConfig.calculationTypeKeysShow, showCalculationTypeCondition: showCalculationTypeCondition, timezone: timezone, onUpdatedNewDate: ({ date }) => onUpdateTimeRange('endDate', { date }, 'system'), onApply: ({ date, option }) => onUpdateTimeRange('endDate', Object.assign({ date }, option), 'user') })));
60
60
  };
61
61
  AdvancedRangePicker.defaultProps = {
62
62
  timeRange: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.3-beta.83",
3
+ "version": "1.3.3-beta.84",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",