@ozen-ui/kit 0.74.0 → 0.75.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/__inner__/cjs/components/Calendar/Calendar.js +26 -2
- package/__inner__/cjs/components/Calendar/CalendarContext.d.ts +8 -1
- package/__inner__/cjs/components/Calendar/CalendarContext.js +10 -1
- package/__inner__/cjs/components/Calendar/__tests__/utils.d.ts +11 -0
- package/__inner__/cjs/components/Calendar/__tests__/utils.js +58 -0
- package/__inner__/cjs/components/Calendar/components/CalendarGrid/CalendarGrid.js +4 -3
- package/__inner__/cjs/components/Calendar/components/CalendarItem/CalendarItem.js +25 -2
- package/__inner__/cjs/components/Calendar/components/CalendarItem/CalendarItemContext.d.ts +1 -0
- package/__inner__/cjs/components/Calendar/components/CalendarItem/CalendarItemContext.js +1 -0
- package/__inner__/cjs/components/Calendar/components/CalendarModeRange/CalendarModeRange.js +68 -13
- package/__inner__/cjs/components/Calendar/components/CalendarModeSingle/CalendarModeSingle.js +62 -16
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/CalendarSwitcher.js +6 -7
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/CalendarSwitcherText.d.ts +3 -0
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/CalendarSwitcherText.js +13 -0
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/index.d.ts +2 -0
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/index.js +5 -0
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/types.d.ts +4 -0
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/types.js +2 -0
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/index.d.ts +1 -0
- package/__inner__/cjs/components/Calendar/components/CalendarSwitcher/components/index.js +4 -0
- package/__inner__/cjs/components/Calendar/constants.d.ts +2 -0
- package/__inner__/cjs/components/Calendar/constants.js +7 -1
- package/__inner__/cjs/components/Calendar/index.d.ts +1 -0
- package/__inner__/cjs/components/Calendar/index.js +1 -0
- package/__inner__/cjs/components/Calendar/types.d.ts +13 -5
- package/__inner__/cjs/components/Calendar/utils.d.ts +10 -1
- package/__inner__/cjs/components/Calendar/utils.js +12 -1
- package/__inner__/cjs/components/DatePicker/components/DateInput/DateInput.js +4 -3
- package/__inner__/cjs/components/DatePicker/components/DateInput/types.d.ts +6 -2
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.d.ts +2 -1
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.js +67 -7
- package/__inner__/cjs/components/DatePicker/components/DatePickerModeDate/DatePickerModeDate.js +32 -20
- package/__inner__/cjs/components/DatePicker/components/DatePickerModeDateRange/DatePickerModeDateRange.js +74 -51
- package/__inner__/cjs/components/DatePicker/constants.d.ts +2 -0
- package/__inner__/cjs/components/DatePicker/constants.js +4 -1
- package/__inner__/cjs/components/DatePicker/types.d.ts +10 -6
- package/__inner__/cjs/components/DatePicker/types.js +3 -1
- package/__inner__/cjs/components/DatePicker/utils/formatDateToString/formatDateToString.d.ts +2 -1
- package/__inner__/cjs/components/DatePicker/utils/formatDateToString/formatDateToString.js +18 -5
- package/__inner__/cjs/components/DatePicker/utils/formatStringToDate/formatStringToDate.d.ts +2 -1
- package/__inner__/cjs/components/DatePicker/utils/formatStringToDate/formatStringToDate.js +6 -5
- package/__inner__/cjs/components/DatePicker/utils/getCommonCalendarProps/getCommonCalendarProps.js +2 -2
- package/__inner__/cjs/components/DatePicker/utils/index.d.ts +2 -0
- package/__inner__/cjs/components/DatePicker/utils/index.js +2 -0
- package/__inner__/cjs/components/DatePicker/utils/isValidDateString/isValidDateString.d.ts +2 -1
- package/__inner__/cjs/components/DatePicker/utils/isValidDateString/isValidDateString.js +9 -8
- package/__inner__/cjs/components/DatePicker/utils/maskPastedDate/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/maskPastedDate/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/utils/maskPastedDate/maskPastedDate.d.ts +6 -0
- package/__inner__/cjs/components/DatePicker/utils/maskPastedDate/maskPastedDate.js +43 -0
- package/__inner__/cjs/components/DatePicker/utils/parseDateString/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/parseDateString/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/utils/parseDateString/parseDateString.d.ts +6 -0
- package/__inner__/cjs/components/DatePicker/utils/parseDateString/parseDateString.js +66 -0
- package/__inner__/cjs/components/ListCardItem/hooks/useListCardItemRatio.js +10 -14
- package/__inner__/cjs/components/OzenProvider/providers/theme/tokens/color/b-business-dark/color-b-business-dark.css +1 -1
- package/__inner__/cjs/components/OzenProvider/providers/theme/tokens/color/b-business-default/color-b-business-default.css +1 -1
- package/__inner__/cjs/components/OzenProvider/providers/theme/tokens/color/ozen-dark/color-ozen-dark.css +1 -1
- package/__inner__/cjs/components/OzenProvider/providers/theme/tokens/color/ozen-default/color-ozen-default.css +1 -1
- package/__inner__/cjs/components/OzenProvider/providers/theme/tokens/color/vip-dark/color-vip-dark.css +1 -1
- package/__inner__/cjs/components/OzenProvider/providers/theme/tokens/color/vip-default/color-vip-default.css +1 -1
- package/__inner__/cjs/components/OzenProvider/providers/theme/tokens/shadow/ozen-default/shadow-ozen-default.css +1 -1
- package/__inner__/cjs/components/Stack/Stack.css +3 -0
- package/__inner__/cjs/components/Stack/Stack.js +2 -1
- package/__inner__/cjs/components/Stack/constants.d.ts +1 -0
- package/__inner__/cjs/components/Stack/constants.js +2 -1
- package/__inner__/cjs/components/Stack/types.d.ts +4 -0
- package/__inner__/cjs/components/Stack/types.js +2 -1
- package/__inner__/cjs/hooks/useDevEffect/index.d.ts +1 -0
- package/__inner__/cjs/hooks/useDevEffect/index.js +4 -0
- package/__inner__/cjs/hooks/useDevEffect/useDevEffect.d.ts +3 -0
- package/__inner__/cjs/hooks/useDevEffect/useDevEffect.js +13 -0
- package/__inner__/cjs/hooks/useIntersectionObserver/useIntersectionObserver.js +3 -2
- package/__inner__/cjs/locale/locale.js +39 -3
- package/__inner__/cjs/utils/array/createFilled/createFilledArray.d.ts +1 -1
- package/__inner__/cjs/utils/array/createFilled/createFilledArray.js +6 -1
- package/__inner__/esm/components/Calendar/Calendar.js +27 -3
- package/__inner__/esm/components/Calendar/CalendarContext.d.ts +8 -1
- package/__inner__/esm/components/Calendar/CalendarContext.js +10 -1
- package/__inner__/esm/components/Calendar/__tests__/utils.d.ts +11 -0
- package/__inner__/esm/components/Calendar/__tests__/utils.js +45 -0
- package/__inner__/esm/components/Calendar/components/CalendarGrid/CalendarGrid.js +4 -3
- package/__inner__/esm/components/Calendar/components/CalendarItem/CalendarItem.js +25 -2
- package/__inner__/esm/components/Calendar/components/CalendarItem/CalendarItemContext.d.ts +1 -0
- package/__inner__/esm/components/Calendar/components/CalendarItem/CalendarItemContext.js +1 -0
- package/__inner__/esm/components/Calendar/components/CalendarModeRange/CalendarModeRange.js +70 -15
- package/__inner__/esm/components/Calendar/components/CalendarModeSingle/CalendarModeSingle.js +64 -18
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/CalendarSwitcher.js +6 -7
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/CalendarSwitcherText.d.ts +3 -0
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/CalendarSwitcherText.js +9 -0
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/index.d.ts +2 -0
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/index.js +2 -0
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/types.d.ts +4 -0
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/CalendarSwitcherText/types.js +1 -0
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/index.d.ts +1 -0
- package/__inner__/esm/components/Calendar/components/CalendarSwitcher/components/index.js +1 -0
- package/__inner__/esm/components/Calendar/constants.d.ts +2 -0
- package/__inner__/esm/components/Calendar/constants.js +6 -0
- package/__inner__/esm/components/Calendar/index.d.ts +1 -0
- package/__inner__/esm/components/Calendar/index.js +1 -0
- package/__inner__/esm/components/Calendar/types.d.ts +13 -5
- package/__inner__/esm/components/Calendar/utils.d.ts +10 -1
- package/__inner__/esm/components/Calendar/utils.js +9 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/DateInput.js +3 -2
- package/__inner__/esm/components/DatePicker/components/DateInput/types.d.ts +6 -2
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.d.ts +2 -1
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.js +67 -7
- package/__inner__/esm/components/DatePicker/components/DatePickerModeDate/DatePickerModeDate.js +33 -21
- package/__inner__/esm/components/DatePicker/components/DatePickerModeDateRange/DatePickerModeDateRange.js +68 -45
- package/__inner__/esm/components/DatePicker/constants.d.ts +2 -0
- package/__inner__/esm/components/DatePicker/constants.js +3 -0
- package/__inner__/esm/components/DatePicker/types.d.ts +10 -6
- package/__inner__/esm/components/DatePicker/types.js +2 -0
- package/__inner__/esm/components/DatePicker/utils/formatDateToString/formatDateToString.d.ts +2 -1
- package/__inner__/esm/components/DatePicker/utils/formatDateToString/formatDateToString.js +18 -5
- package/__inner__/esm/components/DatePicker/utils/formatStringToDate/formatStringToDate.d.ts +2 -1
- package/__inner__/esm/components/DatePicker/utils/formatStringToDate/formatStringToDate.js +6 -5
- package/__inner__/esm/components/DatePicker/utils/getCommonCalendarProps/getCommonCalendarProps.js +2 -2
- package/__inner__/esm/components/DatePicker/utils/index.d.ts +2 -0
- package/__inner__/esm/components/DatePicker/utils/index.js +2 -0
- package/__inner__/esm/components/DatePicker/utils/isValidDateString/isValidDateString.d.ts +2 -1
- package/__inner__/esm/components/DatePicker/utils/isValidDateString/isValidDateString.js +8 -7
- package/__inner__/esm/components/DatePicker/utils/maskPastedDate/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/maskPastedDate/index.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/maskPastedDate/maskPastedDate.d.ts +6 -0
- package/__inner__/esm/components/DatePicker/utils/maskPastedDate/maskPastedDate.js +39 -0
- package/__inner__/esm/components/DatePicker/utils/parseDateString/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/parseDateString/index.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/parseDateString/parseDateString.d.ts +6 -0
- package/__inner__/esm/components/DatePicker/utils/parseDateString/parseDateString.js +62 -0
- package/__inner__/esm/components/ListCardItem/hooks/useListCardItemRatio.js +10 -14
- package/__inner__/esm/components/OzenProvider/providers/theme/tokens/color/b-business-dark/color-b-business-dark.css +1 -1
- package/__inner__/esm/components/OzenProvider/providers/theme/tokens/color/b-business-default/color-b-business-default.css +1 -1
- package/__inner__/esm/components/OzenProvider/providers/theme/tokens/color/ozen-dark/color-ozen-dark.css +1 -1
- package/__inner__/esm/components/OzenProvider/providers/theme/tokens/color/ozen-default/color-ozen-default.css +1 -1
- package/__inner__/esm/components/OzenProvider/providers/theme/tokens/color/vip-dark/color-vip-dark.css +1 -1
- package/__inner__/esm/components/OzenProvider/providers/theme/tokens/color/vip-default/color-vip-default.css +1 -1
- package/__inner__/esm/components/OzenProvider/providers/theme/tokens/shadow/ozen-default/shadow-ozen-default.css +1 -1
- package/__inner__/esm/components/Stack/Stack.css +3 -0
- package/__inner__/esm/components/Stack/Stack.js +3 -2
- package/__inner__/esm/components/Stack/constants.d.ts +1 -0
- package/__inner__/esm/components/Stack/constants.js +1 -0
- package/__inner__/esm/components/Stack/types.d.ts +4 -0
- package/__inner__/esm/components/Stack/types.js +1 -0
- package/__inner__/esm/hooks/useDevEffect/index.d.ts +1 -0
- package/__inner__/esm/hooks/useDevEffect/index.js +1 -0
- package/__inner__/esm/hooks/useDevEffect/useDevEffect.d.ts +3 -0
- package/__inner__/esm/hooks/useDevEffect/useDevEffect.js +9 -0
- package/__inner__/esm/hooks/useIntersectionObserver/useIntersectionObserver.js +3 -2
- package/__inner__/esm/locale/locale.js +39 -3
- package/__inner__/esm/utils/array/createFilled/createFilledArray.d.ts +1 -1
- package/__inner__/esm/utils/array/createFilled/createFilledArray.js +6 -1
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MouseEvent, ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { DPExcludeConfig, DPDayInteger } from '@rehookify/datepicker';
|
|
3
|
-
import type { ExtendableComponentPropsWithRef } from '../../types
|
|
3
|
+
import type { WithRequired, ExtendableComponentPropsWithRef } from '../../types';
|
|
4
4
|
import type { WithDisplayName } from '../../types/react';
|
|
5
5
|
import type { CALENDAR_DEFAULT_MODE } from './constants';
|
|
6
6
|
export declare const calendarStepVariant: readonly ["days", "months", "years"];
|
|
@@ -18,6 +18,7 @@ export type CalendarPropRenderAdditionalControls<MODE extends CalendarModeVarian
|
|
|
18
18
|
date?: MODE extends 'range' ? Date[] : Date;
|
|
19
19
|
}) => ReactElement;
|
|
20
20
|
export type CalendarPropCalendars = 1 | 2;
|
|
21
|
+
export type CalendarSteps = CalendarStepVariant[];
|
|
21
22
|
/**
|
|
22
23
|
* @deprecated
|
|
23
24
|
* Use the `CalendarPropOnChange` type to replace it.
|
|
@@ -44,6 +45,9 @@ export type CalendarExclude = CalendarPropExclude;
|
|
|
44
45
|
* */
|
|
45
46
|
export type CalendarStartDay = CalendarPropStartDay;
|
|
46
47
|
export type CalendarRenderAdditionalControls<MODE extends CalendarModeVariant> = CalendarPropRenderAdditionalControls<MODE>;
|
|
48
|
+
export type CalendarOnMonthClick = (event: MouseEvent<HTMLElement>, date: Date) => void;
|
|
49
|
+
export type CalendarOnDayClick = (event: MouseEvent<HTMLElement>, date: Date) => void;
|
|
50
|
+
export type CalendarOnYearClick = (event: MouseEvent<HTMLElement>, date: Date) => void;
|
|
47
51
|
export type CalendarProps<MODE extends CalendarModeVariant = typeof CALENDAR_DEFAULT_MODE> = ExtendableComponentPropsWithRef<{
|
|
48
52
|
/** Способ выбора даты:
|
|
49
53
|
* - `single` — позволяет выбрать одну дату (показывает один календарь).
|
|
@@ -75,11 +79,11 @@ export type CalendarProps<MODE extends CalendarModeVariant = typeof CALENDAR_DEF
|
|
|
75
79
|
/** Ограничение выбора дат по большей дате */
|
|
76
80
|
maxDate?: Date;
|
|
77
81
|
/** Обработчик нажатия на кнопку месяца */
|
|
78
|
-
onMonthClick
|
|
82
|
+
onMonthClick?: CalendarOnMonthClick;
|
|
79
83
|
/** Обработчик нажатия на кнопку дня */
|
|
80
|
-
onDayClick
|
|
84
|
+
onDayClick?: CalendarOnDayClick;
|
|
81
85
|
/** Обработчик нажатия на кнопку года */
|
|
82
|
-
onYearClick
|
|
86
|
+
onYearClick?: CalendarOnYearClick;
|
|
83
87
|
/** Дополнительные контролы — рендер функция */
|
|
84
88
|
renderAdditionalControls?: CalendarPropRenderAdditionalControls<MODE>;
|
|
85
89
|
/** Функция форматирования атрибута `aria-label` для кнопок переключения периодов */
|
|
@@ -89,6 +93,10 @@ export type CalendarProps<MODE extends CalendarModeVariant = typeof CALENDAR_DEF
|
|
|
89
93
|
/** Количество отображаемых календарей в компоненте: один или два */
|
|
90
94
|
calendars?: CalendarPropCalendars;
|
|
91
95
|
children?: never;
|
|
96
|
+
/** Шаги календаря. Определяет порядок и наличие этапов выбора. */
|
|
97
|
+
steps?: CalendarSteps;
|
|
98
|
+
/** Изначальный шаг */
|
|
99
|
+
initialStep?: CalendarStepVariant;
|
|
92
100
|
}, 'div'>;
|
|
93
101
|
export type CalendarComponent = WithDisplayName<(<MODE extends CalendarModeVariant = typeof CALENDAR_DEFAULT_MODE>(props: CalendarProps<MODE>) => ReactNode)>;
|
|
94
|
-
export type CalendarModeComponent<MODE extends CalendarModeVariant> = WithDisplayName<(props: Omit<CalendarProps<MODE>, 'mode'>) => ReactNode>;
|
|
102
|
+
export type CalendarModeComponent<MODE extends CalendarModeVariant> = WithDisplayName<(props: Omit<WithRequired<CalendarProps<MODE>, 'steps' | 'initialStep'>, 'mode'>) => ReactNode>;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import type { CalendarProps } from './index';
|
|
1
|
+
import type { CalendarProps, CalendarSteps } from './index';
|
|
2
2
|
export declare const cnCalendar: import("@bem-react/classname").ClassNameFormatter;
|
|
3
3
|
export declare const getPeriodSwitchAriaLabel: CalendarProps['getPeriodSwitchAriaLabel'];
|
|
4
|
+
export declare const calculateStepsAvailability: (steps: CalendarSteps) => {
|
|
5
|
+
hasDaysStep: boolean;
|
|
6
|
+
hasMonthsStep: boolean;
|
|
7
|
+
hasYearsStep: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const calculateStepsHelpers: (steps: CalendarSteps) => {
|
|
10
|
+
lastStep: "days" | "months" | "years";
|
|
11
|
+
firstStep: "days" | "months" | "years";
|
|
12
|
+
};
|
|
@@ -9,3 +9,12 @@ export var getPeriodSwitchAriaLabel = function (step) {
|
|
|
9
9
|
}
|
|
10
10
|
return ['Previous period', 'Next period'];
|
|
11
11
|
};
|
|
12
|
+
export var calculateStepsAvailability = function (steps) { return ({
|
|
13
|
+
hasDaysStep: steps.includes('days'),
|
|
14
|
+
hasMonthsStep: steps.includes('months'),
|
|
15
|
+
hasYearsStep: steps.includes('years'),
|
|
16
|
+
}); };
|
|
17
|
+
export var calculateStepsHelpers = function (steps) { return ({
|
|
18
|
+
lastStep: steps[steps.length - 1],
|
|
19
|
+
firstStep: steps[0],
|
|
20
|
+
}); };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { __assign, __rest } from "tslib";
|
|
2
2
|
import React, { forwardRef } from 'react';
|
|
3
3
|
import { useMultiRef } from '../../../../hooks/useMultiRef';
|
|
4
|
+
import { isFunction } from '../../../../utils';
|
|
4
5
|
import { Input } from '../../../Input';
|
|
5
6
|
import { dateInputMask } from './utils';
|
|
6
7
|
export var DateInput = forwardRef(function (_a, ref) {
|
|
7
|
-
var valueProp = _a.value, defaultValue = _a.defaultValue, other = __rest(_a, ["value", "defaultValue"]);
|
|
8
|
-
return (React.createElement(Input, __assign({ value: dateInputMask(valueProp), defaultValue: dateInputMask(defaultValue) }, other, { ref: useMultiRef([ref]) })));
|
|
8
|
+
var valueProp = _a.value, defaultValue = _a.defaultValue, steps = _a.steps, placeholder = _a.placeholder, other = __rest(_a, ["value", "defaultValue", "steps", "placeholder"]);
|
|
9
|
+
return (React.createElement(Input, __assign({ value: dateInputMask(valueProp, steps), defaultValue: dateInputMask(defaultValue, steps) }, other, { placeholder: isFunction(placeholder) ? placeholder(steps) : placeholder, ref: useMultiRef([ref]) })));
|
|
9
10
|
});
|
|
10
11
|
DateInput.displayName = 'DateInput';
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { ComponentRef } from 'react';
|
|
2
|
-
import type { ExtendableComponentPropsWithRef } from '../../../../types
|
|
2
|
+
import type { ExtendableComponentPropsWithRef } from '../../../../types';
|
|
3
|
+
import type { CalendarSteps } from '../../../Calendar';
|
|
3
4
|
import type { FIELD_CONTROL_DEFAULT_TAG } from '../../../FieldControl';
|
|
4
5
|
import type { InputProps } from '../../../Input';
|
|
6
|
+
import type { InputPropPlaceholder } from '../../types';
|
|
5
7
|
export type DateInputRef = ComponentRef<typeof FIELD_CONTROL_DEFAULT_TAG>;
|
|
6
8
|
export type DateInputProps = ExtendableComponentPropsWithRef<{
|
|
9
|
+
steps: CalendarSteps;
|
|
7
10
|
value?: string;
|
|
8
11
|
defaultValue?: string;
|
|
9
|
-
|
|
12
|
+
placeholder?: InputPropPlaceholder;
|
|
13
|
+
} & Omit<InputProps, 'value' | 'defaultValue' | 'placeholder'>, typeof FIELD_CONTROL_DEFAULT_TAG>;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { CalendarSteps } from '../../../../../Calendar';
|
|
2
|
+
export declare const dateInputMask: (value: string | undefined, steps: CalendarSteps) => string | undefined;
|
|
@@ -1,14 +1,74 @@
|
|
|
1
|
-
|
|
1
|
+
var onlyOneDot = function (value) {
|
|
2
|
+
// Разрешить только первую точку, остальные убрать
|
|
3
|
+
var firstDotIndex = value.indexOf('.');
|
|
4
|
+
if (firstDotIndex === -1) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
// Сохраняем первую часть и одну точку
|
|
8
|
+
var beforeDot = value.slice(0, firstDotIndex + 1);
|
|
9
|
+
var afterDot = value.slice(firstDotIndex + 1).replace(/\./g, '');
|
|
10
|
+
return beforeDot + afterDot;
|
|
11
|
+
};
|
|
12
|
+
export var dateInputMask = function (value, steps) {
|
|
2
13
|
if (!value) {
|
|
3
14
|
return value;
|
|
4
15
|
}
|
|
16
|
+
var hasDaysStep = steps.includes('days');
|
|
17
|
+
var hasMonthsStep = steps.includes('months');
|
|
18
|
+
var hasYearsStep = steps.includes('years');
|
|
19
|
+
var maxLength = 0;
|
|
5
20
|
var newValue = value.replace(/[^0-9.]/g, ''); // Запрещаем ввод, кроме цифр и точек
|
|
6
21
|
newValue = newValue.replace(/\.\.+/g, '..'); // Удаляем лишние точки
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
// DD
|
|
23
|
+
if (hasDaysStep && !hasMonthsStep && !hasYearsStep) {
|
|
24
|
+
maxLength = 2;
|
|
25
|
+
newValue = newValue.replace('.', '');
|
|
26
|
+
}
|
|
27
|
+
// MM
|
|
28
|
+
if (!hasDaysStep && hasMonthsStep && !hasYearsStep) {
|
|
29
|
+
maxLength = 2;
|
|
30
|
+
newValue = newValue.replace('.', '');
|
|
31
|
+
}
|
|
32
|
+
// YYYY
|
|
33
|
+
if (!hasDaysStep && !hasMonthsStep && hasYearsStep) {
|
|
34
|
+
maxLength = 4;
|
|
35
|
+
newValue = newValue.replace('.', '');
|
|
36
|
+
}
|
|
37
|
+
// DD.MM.YYYY
|
|
38
|
+
if (hasDaysStep && hasMonthsStep && hasYearsStep) {
|
|
39
|
+
newValue = newValue.replace(/^(\d)\.$/g, '0$1.'); // Добавляем 0 в D.
|
|
40
|
+
newValue = newValue.replace(/^(\d\d)(\d)$/g, '$1.$2'); // Добавляем точку в DD.M
|
|
41
|
+
newValue = newValue.replace(/^(\d\d)\.(\d)\.$/g, '$1.0$2.'); // Добавляем 0 в DD.M.
|
|
42
|
+
newValue = newValue.replace(/^(\d\d\.\d\d)(\d)$/g, '$1.$2'); // Добавляем точку в DD.MM.Y
|
|
43
|
+
// + 2, так как одно соединение в виде "."
|
|
44
|
+
maxLength = 8 + 2;
|
|
45
|
+
}
|
|
46
|
+
// DD.MM
|
|
47
|
+
if (hasDaysStep && hasMonthsStep && !hasYearsStep) {
|
|
48
|
+
newValue = newValue.replace(/^(\d)\.$/g, '0$1.'); // Добавляем 0 в D.
|
|
49
|
+
newValue = newValue.replace(/^(\d\d)(\d)$/g, '$1.$2'); // Добавляем точку в DD.M
|
|
50
|
+
newValue = onlyOneDot(newValue); // Разрешаем только одну точку
|
|
51
|
+
// + 1, так как одно соединение в виде "."
|
|
52
|
+
maxLength = 4 + 1;
|
|
53
|
+
}
|
|
54
|
+
// DD.YYYY
|
|
55
|
+
if (hasDaysStep && !hasMonthsStep && hasYearsStep) {
|
|
56
|
+
newValue = newValue.replace(/^(\d)\.$/g, '0$1.'); // Добавляем 0 в D.
|
|
57
|
+
newValue = newValue.replace(/^(\d\d)(\d)$/g, '$1.$2'); // Добавляем точку в DD.Y
|
|
58
|
+
newValue = onlyOneDot(newValue);
|
|
59
|
+
// + 1, так как одно соединение в виде "."
|
|
60
|
+
maxLength = 6 + 1;
|
|
61
|
+
}
|
|
62
|
+
// MM.YYYY
|
|
63
|
+
if (!hasDaysStep && hasMonthsStep && hasYearsStep) {
|
|
64
|
+
newValue = newValue.replace(/^(\d)\.$/g, '0$1.'); // Добавляем 0 в M.
|
|
65
|
+
newValue = newValue.replace(/^(\d\d)(\d)$/g, '$1.$2'); // Добавляем точку в MM.Y
|
|
66
|
+
newValue = onlyOneDot(newValue);
|
|
67
|
+
// + 1, так как одно соединение в виде "."
|
|
68
|
+
maxLength = 6 + 1;
|
|
69
|
+
}
|
|
70
|
+
if (newValue.length > maxLength) {
|
|
71
|
+
newValue = newValue.slice(0, maxLength); // Ограничиваем длину
|
|
72
|
+
}
|
|
13
73
|
return newValue;
|
|
14
74
|
};
|
package/__inner__/esm/components/DatePicker/components/DatePickerModeDate/DatePickerModeDate.js
CHANGED
|
@@ -2,44 +2,47 @@ import { __assign, __read, __rest } from "tslib";
|
|
|
2
2
|
import React, { useEffect, useState, forwardRef, useRef } from 'react';
|
|
3
3
|
import { useControlled } from '../../../../hooks/useControlled';
|
|
4
4
|
import { useMultiRef } from '../../../../hooks/useMultiRef';
|
|
5
|
+
import { useStoredValue } from '../../../../hooks/useStoredValue';
|
|
5
6
|
import { isKeys } from '../../../../utils/isKeys';
|
|
6
7
|
import { Calendar } from '../../../Calendar';
|
|
7
8
|
import { Popover } from '../../../Popover';
|
|
9
|
+
import { DATE_PICKER_DEFAULT_INITIAL_STEP, DATE_PICKER_DEFAULT_STEPS, } from '../../constants';
|
|
8
10
|
import { cnDatePicker } from '../../index';
|
|
9
|
-
import { formatDateToString, formatStringToDate, getCommonCalendarProps, getCommonPopoverProps, isInExclude, isValidDateString, isOutOfRange, useCalendarKeyboard, } from '../../utils';
|
|
11
|
+
import { maskPastedDate, formatDateToString, formatStringToDate, getCommonCalendarProps, getCommonPopoverProps, isInExclude, isValidDateString, isOutOfRange, useCalendarKeyboard, } from '../../utils';
|
|
10
12
|
import { DateInput, DatePickerRenderRight } from '../index';
|
|
11
13
|
export var DatePickerModeDate = forwardRef(function (props, ref) {
|
|
12
|
-
var size = props.size, valueProp = props.value, label = props.label, defaultValue = props.defaultValue, openProp = props.open, onCloseProp = props.onClose, onOpenProp = props.onOpen, onInputChange = props.onInputChange, clearText = props.clearText, defaultOpen = props.defaultOpen, disabled = props.disabled, minDate = props.minDate, maxDate = props.maxDate, exclude = props.exclude, inputProps = props.inputProps, renderRight = props.renderRight, className = props.className, _a = props.calendars, calendars = _a === void 0 ? 1 : _a, disableClearButton = props.disableClearButton, onChange = props.onChange, onKeyDown = props.onKeyDown, autoFocus = props.autoFocus, disableCloseOnSelect = props.disableCloseOnSelect, popoverPropsProp = props.popoverProps, calendarPropsProp = props.calendarProps, onError = props.onError, other = __rest(props, ["size", "value", "label", "defaultValue", "open", "onClose", "onOpen", "onInputChange", "clearText", "defaultOpen", "disabled", "minDate", "maxDate", "exclude", "inputProps", "renderRight", "className", "calendars", "disableClearButton", "onChange", "onKeyDown", "autoFocus", "disableCloseOnSelect", "popoverProps", "calendarProps", "onError"]);
|
|
14
|
+
var size = props.size, valueProp = props.value, label = props.label, defaultValue = props.defaultValue, openProp = props.open, onCloseProp = props.onClose, onOpenProp = props.onOpen, onInputChange = props.onInputChange, clearText = props.clearText, defaultOpen = props.defaultOpen, disabled = props.disabled, minDate = props.minDate, maxDate = props.maxDate, exclude = props.exclude, inputProps = props.inputProps, renderRight = props.renderRight, className = props.className, _a = props.calendars, calendars = _a === void 0 ? 1 : _a, disableClearButton = props.disableClearButton, onChange = props.onChange, onKeyDown = props.onKeyDown, autoFocus = props.autoFocus, disableCloseOnSelect = props.disableCloseOnSelect, popoverPropsProp = props.popoverProps, calendarPropsProp = props.calendarProps, onError = props.onError, _b = props.steps, steps = _b === void 0 ? DATE_PICKER_DEFAULT_STEPS : _b, _c = props.initialStep, initialStep = _c === void 0 ? DATE_PICKER_DEFAULT_INITIAL_STEP : _c, other = __rest(props, ["size", "value", "label", "defaultValue", "open", "onClose", "onOpen", "onInputChange", "clearText", "defaultOpen", "disabled", "minDate", "maxDate", "exclude", "inputProps", "renderRight", "className", "calendars", "disableClearButton", "onChange", "onKeyDown", "autoFocus", "disableCloseOnSelect", "popoverProps", "calendarProps", "onError", "steps", "initialStep"]);
|
|
13
15
|
var anchorRef = useRef(null);
|
|
14
16
|
var calendarInnerRef = useRef(null);
|
|
15
17
|
var calendarRef = useMultiRef([calendarInnerRef, calendarPropsProp === null || calendarPropsProp === void 0 ? void 0 : calendarPropsProp.ref]);
|
|
16
18
|
var lastValidDate = useRef('');
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
+
var _d = __read(useState(null), 2), offsetDate = _d[0], setOffsetDate = _d[1];
|
|
20
|
+
var isWasPaste = useStoredValue(false);
|
|
21
|
+
var _e = __read(useControlled({
|
|
19
22
|
value: undefined,
|
|
20
23
|
defaultValue: '',
|
|
21
24
|
name: 'DatePicker',
|
|
22
25
|
state: 'inputValue',
|
|
23
|
-
}), 2), inputValue =
|
|
24
|
-
var
|
|
26
|
+
}), 2), inputValue = _e[0], setInputValue = _e[1];
|
|
27
|
+
var _f = __read(useControlled({
|
|
25
28
|
value: openProp,
|
|
26
29
|
defaultValue: defaultOpen,
|
|
27
30
|
name: 'DatePicker',
|
|
28
31
|
state: 'open',
|
|
29
|
-
}), 2), open =
|
|
30
|
-
var
|
|
32
|
+
}), 2), open = _f[0], setOpen = _f[1];
|
|
33
|
+
var _g = __read(useControlled({
|
|
31
34
|
value: valueProp,
|
|
32
35
|
defaultValue: defaultValue,
|
|
33
36
|
name: 'DatePicker',
|
|
34
37
|
state: 'value',
|
|
35
|
-
}), 2), value =
|
|
38
|
+
}), 2), value = _g[0], setValue = _g[1];
|
|
36
39
|
var popoverProps = getCommonPopoverProps(__assign(__assign({}, props), { popoverProps: popoverPropsProp }));
|
|
37
40
|
var calendarProps = getCommonCalendarProps(__assign(__assign({}, props), { calendarProps: calendarPropsProp, ref: calendarRef }));
|
|
38
41
|
var onOffsetDateChange = function (date) {
|
|
39
42
|
setOffsetDate(date);
|
|
40
43
|
};
|
|
41
44
|
var callOnChange = function (value) {
|
|
42
|
-
var formattedDate = formatStringToDate(value);
|
|
45
|
+
var formattedDate = formatStringToDate(value, steps);
|
|
43
46
|
setValue(formattedDate);
|
|
44
47
|
onChange === null || onChange === void 0 ? void 0 : onChange(formattedDate);
|
|
45
48
|
lastValidDate.current = value;
|
|
@@ -47,9 +50,9 @@ export var DatePickerModeDate = forwardRef(function (props, ref) {
|
|
|
47
50
|
var changeInputValue = function (e, value) {
|
|
48
51
|
setInputValue(value);
|
|
49
52
|
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(e, value);
|
|
50
|
-
if (isValidDateString(value)) {
|
|
53
|
+
if (isValidDateString(value, steps)) {
|
|
51
54
|
callOnChange(value);
|
|
52
|
-
onOffsetDateChange(formatStringToDate(value));
|
|
55
|
+
onOffsetDateChange(formatStringToDate(value, steps));
|
|
53
56
|
}
|
|
54
57
|
};
|
|
55
58
|
var handleExited = function () {
|
|
@@ -71,7 +74,7 @@ export var DatePickerModeDate = forwardRef(function (props, ref) {
|
|
|
71
74
|
}, [autoFocus]);
|
|
72
75
|
/** Эффект — синхронизируем значение текстового поля со значением в списке */
|
|
73
76
|
useEffect(function () {
|
|
74
|
-
var formattedDate = formatDateToString(value);
|
|
77
|
+
var formattedDate = formatDateToString(value, steps);
|
|
75
78
|
if (formattedDate !== inputValue) {
|
|
76
79
|
setInputValue(formattedDate);
|
|
77
80
|
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(null, formattedDate);
|
|
@@ -127,7 +130,7 @@ export var DatePickerModeDate = forwardRef(function (props, ref) {
|
|
|
127
130
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
128
131
|
if (!inputValue)
|
|
129
132
|
return;
|
|
130
|
-
if (!isValidDateString(inputValue))
|
|
133
|
+
if (!isValidDateString(inputValue, steps))
|
|
131
134
|
changeInputValue(null, lastValidDate.current);
|
|
132
135
|
};
|
|
133
136
|
/** Очистка поля */
|
|
@@ -135,22 +138,31 @@ export var DatePickerModeDate = forwardRef(function (props, ref) {
|
|
|
135
138
|
changeInputValue(null, '');
|
|
136
139
|
};
|
|
137
140
|
/** Событие ввода значения в текстовом поле */
|
|
138
|
-
var handleChangeInput = function (
|
|
141
|
+
var handleChangeInput = function (event) {
|
|
142
|
+
var _a;
|
|
143
|
+
var value = event.target.value.trim();
|
|
144
|
+
var preparedValue = isWasPaste.current
|
|
145
|
+
? maskPastedDate(value, steps)
|
|
146
|
+
: value;
|
|
147
|
+
changeInputValue(event, preparedValue);
|
|
148
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onChange) === null || _a === void 0 ? void 0 : _a.call(inputProps, event);
|
|
149
|
+
isWasPaste.current = false;
|
|
150
|
+
};
|
|
151
|
+
var handlePasteInput = function (event) {
|
|
139
152
|
var _a;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onChange) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
153
|
+
isWasPaste.current = true;
|
|
154
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onPaste) === null || _a === void 0 ? void 0 : _a.call(inputProps, event);
|
|
143
155
|
};
|
|
144
156
|
/** Событие выбора значения из календаря */
|
|
145
157
|
var handleChangeCalendar = function (date) {
|
|
146
|
-
var formattedDate = formatDateToString(date);
|
|
158
|
+
var formattedDate = formatDateToString(date, steps);
|
|
147
159
|
changeInputValue(null, formattedDate);
|
|
148
160
|
if (!disableCloseOnSelect)
|
|
149
161
|
handleClose();
|
|
150
162
|
};
|
|
151
163
|
return (React.createElement(React.Fragment, null,
|
|
152
|
-
React.createElement(DateInput, __assign({ size: size, disabled: disabled, label: label }, other, { className: cnDatePicker({ mode: 'date' }, className), renderRight: React.createElement(DatePickerRenderRight, { size: size, open: open, onClear: handleClear, clearText: clearText, hasValue: !!value, renderRight: renderRight, disableClearButton: disableClearButton }), value: inputValue, inputProps: __assign(__assign({ autoComplete: 'off' }, inputProps), { onBlur: handleBlur, onClick: handleClickOnInput, onChange: handleChangeInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, onKeyDown: handleKeyDown, ref: ref })),
|
|
164
|
+
React.createElement(DateInput, __assign({ size: size, disabled: disabled, label: label }, other, { steps: steps, className: cnDatePicker({ mode: 'date' }, className), renderRight: React.createElement(DatePickerRenderRight, { size: size, open: open, onClear: handleClear, clearText: clearText, hasValue: !!value, renderRight: renderRight, disableClearButton: disableClearButton }), value: inputValue, inputProps: __assign(__assign({ autoComplete: 'off' }, inputProps), { onBlur: handleBlur, onClick: handleClickOnInput, onChange: handleChangeInput, onPaste: handlePasteInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, onKeyDown: handleKeyDown, ref: ref })),
|
|
153
165
|
React.createElement(Popover, __assign({ open: open, anchorRef: anchorRef, onClose: handleClose }, popoverProps, { disableEnforceFocus: !enableEnforceFocus, onExited: handleExited }),
|
|
154
|
-
React.createElement(Calendar, __assign({ calendars: calendars }, calendarProps, { mode: "single", value: value || null, offsetDate: offsetDate, onOffsetDateChange: onOffsetDateChange, onChange: handleChangeCalendar })))));
|
|
166
|
+
React.createElement(Calendar, __assign({ calendars: calendars }, calendarProps, { steps: steps, initialStep: initialStep, mode: "single", value: value || null, offsetDate: offsetDate, onOffsetDateChange: onOffsetDateChange, onChange: handleChangeCalendar })))));
|
|
155
167
|
});
|
|
156
168
|
DatePickerModeDate.displayName = 'DatePickerModeDate';
|
|
@@ -5,13 +5,15 @@ import { useBoolean } from '../../../../hooks/useBoolean';
|
|
|
5
5
|
import { useControlled } from '../../../../hooks/useControlled';
|
|
6
6
|
import { useMultiRef } from '../../../../hooks/useMultiRef';
|
|
7
7
|
import { useMutableRef } from '../../../../hooks/useMutableRef';
|
|
8
|
-
import {
|
|
8
|
+
import { useStoredValue } from '../../../../hooks/useStoredValue';
|
|
9
|
+
import { isKeys } from '../../../../utils';
|
|
9
10
|
import { Calendar } from '../../../Calendar';
|
|
10
11
|
import { FieldHint } from '../../../FieldHint';
|
|
11
12
|
import { Popover } from '../../../Popover';
|
|
12
13
|
import { Stack } from '../../../Stack';
|
|
14
|
+
import { DATE_PICKER_DEFAULT_INITIAL_STEP, DATE_PICKER_DEFAULT_STEPS, } from '../../constants';
|
|
13
15
|
import { cnDatePicker } from '../../index';
|
|
14
|
-
import { formatDateToString, formatStringToDate, getCommonCalendarProps, getCommonPopoverProps, isValidDateString, useCalendarKeyboard, } from '../../utils';
|
|
16
|
+
import { maskPastedDate, formatDateToString, formatStringToDate, getCommonCalendarProps, getCommonPopoverProps, isValidDateString, useCalendarKeyboard, } from '../../utils';
|
|
15
17
|
import { DateInput, DatePickerRenderRight } from '../index';
|
|
16
18
|
import { formatDateForCalendar, getOffsetDateInRange, getValueForDoubleProp, } from './utils';
|
|
17
19
|
export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
@@ -19,13 +21,14 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
19
21
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
22
|
minDate = props.minDate,
|
|
21
23
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
-
maxDate = props.maxDate, other = __rest(props, ["size", "error", "open", "label", "onKeyDown", "onInputChange", "renderLeft", "renderRight", "required", "fullWidth", "placeholder", "hint", "disableStroke", "hintProps", "onChange", "labelProps", "popoverProps", "calendarProps", "defaultOpen", "onClose", "defaultValue", "value", "inputProps", "disabled", "className", "calendars", "onError", "clearText", "disableCloseOnSelect", "disableClearButton", "onOpen", "fieldsProps", "minDate", "maxDate"]);
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
24
|
+
maxDate = props.maxDate, _b = props.steps, steps = _b === void 0 ? DATE_PICKER_DEFAULT_STEPS : _b, _c = props.initialStep, initialStep = _c === void 0 ? DATE_PICKER_DEFAULT_INITIAL_STEP : _c, other = __rest(props, ["size", "error", "open", "label", "onKeyDown", "onInputChange", "renderLeft", "renderRight", "required", "fullWidth", "placeholder", "hint", "disableStroke", "hintProps", "onChange", "labelProps", "popoverProps", "calendarProps", "defaultOpen", "onClose", "defaultValue", "value", "inputProps", "disabled", "className", "calendars", "onError", "clearText", "disableCloseOnSelect", "disableClearButton", "onOpen", "fieldsProps", "minDate", "maxDate", "steps", "initialStep"]);
|
|
25
|
+
var _d = __read(getValueForDoubleProp(label), 2), labelFrom = _d[0], labelTo = _d[1];
|
|
26
|
+
var _e = __read(getValueForDoubleProp(renderLeft), 2), renderLeftFrom = _e[0], renderLeftTo = _e[1];
|
|
27
|
+
var _f = __read(getValueForDoubleProp(renderRight), 2), renderRightFrom = _f[0], renderRightTo = _f[1];
|
|
28
|
+
var _g = __read(getValueForDoubleProp(placeholder), 2), placeholderFrom = _g[0], placeholderTo = _g[1];
|
|
29
|
+
var _h = __read(getValueForDoubleProp(inputProps), 2), inputPropsFrom = _h[0], inputPropsTo = _h[1];
|
|
30
|
+
var _j = __read(getValueForDoubleProp(labelProps), 2), labelPropsFrom = _j[0], labelPropsTo = _j[1];
|
|
31
|
+
var isWasPaste = useStoredValue(false);
|
|
29
32
|
var containerRef = useRef(null);
|
|
30
33
|
var anchorRef = useRef(null);
|
|
31
34
|
var calendarInnerRef = useRef(null);
|
|
@@ -33,32 +36,32 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
33
36
|
var calendarRef = useMultiRef([calendarInnerRef, calendarPropsProp === null || calendarPropsProp === void 0 ? void 0 : calendarPropsProp.ref]);
|
|
34
37
|
var fieldsRef = useMultiRef([anchorRef, fieldsProps === null || fieldsProps === void 0 ? void 0 : fieldsProps.ref]);
|
|
35
38
|
var rootRef = useMultiRef([ref, containerRef]);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
39
|
+
var _k = __read(useState(null), 2), offsetDate = _k[0], setOffsetDate = _k[1];
|
|
40
|
+
var _l = __read(useState(null), 2), calendarPeriod = _l[0], setCalendarPeriod = _l[1];
|
|
38
41
|
var savedCalendarPeriod = useMutableRef(calendarPeriod);
|
|
39
42
|
var lastValidDate = useRef(['', '']);
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
+
var _m = __read(useBoolean(false), 2), focusInputFrom = _m[0], setFocusInputFrom = _m[1];
|
|
44
|
+
var _o = __read(useBoolean(false), 2), focusInputTo = _o[0], setFocusInputTo = _o[1];
|
|
45
|
+
var _p = __read(useControlled({
|
|
43
46
|
value: valueProp,
|
|
44
47
|
defaultValue: defaultValue,
|
|
45
48
|
name: 'DatePicker',
|
|
46
49
|
state: 'value',
|
|
47
|
-
}), 2), value =
|
|
48
|
-
var
|
|
50
|
+
}), 2), value = _p[0], setValue = _p[1];
|
|
51
|
+
var _q = __read(useControlled({
|
|
49
52
|
value: undefined,
|
|
50
53
|
defaultValue: [],
|
|
51
54
|
name: 'DatePicker',
|
|
52
55
|
state: 'inputValue',
|
|
53
|
-
}), 2), inputValue =
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
56
|
+
}), 2), inputValue = _q[0], setInputValue = _q[1];
|
|
57
|
+
var _r = __read(value || [], 2), valueFrom = _r[0], valueTo = _r[1];
|
|
58
|
+
var _s = __read(inputValue || [], 2), _t = _s[0], inputValueFrom = _t === void 0 ? '' : _t, _u = _s[1], inputValueTo = _u === void 0 ? '' : _u;
|
|
59
|
+
var _v = __read(useControlled({
|
|
57
60
|
value: openProp,
|
|
58
61
|
defaultValue: defaultOpen,
|
|
59
62
|
name: 'DatePicker',
|
|
60
63
|
state: 'open',
|
|
61
|
-
}), 2), open =
|
|
64
|
+
}), 2), open = _v[0], setOpen = _v[1];
|
|
62
65
|
var popoverProps = getCommonPopoverProps(__assign(__assign({}, props), { popoverProps: popoverPropsProp }));
|
|
63
66
|
var calendarProps = getCommonCalendarProps(__assign(__assign({}, props), { calendarProps: calendarPropsProp, ref: calendarRef }));
|
|
64
67
|
var onOffsetDateChange = function (date) {
|
|
@@ -76,8 +79,8 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
76
79
|
var disableEnforceFocus = !enableEnforceFocusTo;
|
|
77
80
|
/** Эффект — синхронизируем значение текстового поля со значением в списке */
|
|
78
81
|
useEffect(function () {
|
|
79
|
-
var formattedDateFrom = formatDateToString(valueFrom);
|
|
80
|
-
var formattedDateTo = formatDateToString(valueTo);
|
|
82
|
+
var formattedDateFrom = formatDateToString(valueFrom, steps);
|
|
83
|
+
var formattedDateTo = formatDateToString(valueTo, steps);
|
|
81
84
|
if (formattedDateFrom !== inputValueFrom ||
|
|
82
85
|
formattedDateTo !== inputValueTo) {
|
|
83
86
|
setInputValue([formattedDateFrom, formattedDateTo]);
|
|
@@ -93,13 +96,13 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
93
96
|
}, [onError]);
|
|
94
97
|
/** Calendar offset when interacting with inputs */
|
|
95
98
|
useEffect(function () {
|
|
96
|
-
if (!isValidDateString(inputValueFrom) ||
|
|
97
|
-
!isValidDateString(inputValueTo) ||
|
|
99
|
+
if (!isValidDateString(inputValueFrom, steps) ||
|
|
100
|
+
!isValidDateString(inputValueTo, steps) ||
|
|
98
101
|
!savedCalendarPeriod.current)
|
|
99
102
|
return;
|
|
100
103
|
if ((focusInputFrom || focusInputTo) && open && (calendarPeriod === null || calendarPeriod === void 0 ? void 0 : calendarPeriod.length)) {
|
|
101
|
-
var firstDate = formatStringToDate(inputValueFrom);
|
|
102
|
-
var secondDate = formatStringToDate(inputValueTo);
|
|
104
|
+
var firstDate = formatStringToDate(inputValueFrom, steps);
|
|
105
|
+
var secondDate = formatStringToDate(inputValueTo, steps);
|
|
103
106
|
var offset = getOffsetDateInRange(__assign(__assign({}, (focusInputTo && { type: 'end' })), { calendarPeriod: savedCalendarPeriod.current, value: [firstDate || undefined, secondDate || undefined] }));
|
|
104
107
|
setOffsetDate(offset);
|
|
105
108
|
}
|
|
@@ -125,8 +128,8 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
125
128
|
};
|
|
126
129
|
var callOnChange = function (value) {
|
|
127
130
|
var _a = __read(value || [], 2), dateFrom = _a[0], dateTo = _a[1];
|
|
128
|
-
var formattedDateFrom = formatStringToDate(dateFrom) || undefined;
|
|
129
|
-
var formattedDateTo = formatStringToDate(dateTo) || undefined;
|
|
131
|
+
var formattedDateFrom = formatStringToDate(dateFrom, steps) || undefined;
|
|
132
|
+
var formattedDateTo = formatStringToDate(dateTo, steps) || undefined;
|
|
130
133
|
if (formattedDateTo &&
|
|
131
134
|
formattedDateFrom &&
|
|
132
135
|
(formattedDateFrom === null || formattedDateFrom === void 0 ? void 0 : formattedDateFrom.getTime()) > (formattedDateTo === null || formattedDateTo === void 0 ? void 0 : formattedDateTo.getTime())) {
|
|
@@ -141,7 +144,8 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
141
144
|
setInputValue(value);
|
|
142
145
|
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(e, value);
|
|
143
146
|
var _a = __read(value || [], 2), valueFrom = _a[0], valueTo = _a[1];
|
|
144
|
-
if (isValidDateString(valueFrom) &&
|
|
147
|
+
if (isValidDateString(valueFrom, steps) &&
|
|
148
|
+
isValidDateString(valueTo, steps))
|
|
145
149
|
callOnChange([valueFrom, valueTo]);
|
|
146
150
|
};
|
|
147
151
|
var handleExited = function () {
|
|
@@ -150,12 +154,20 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
150
154
|
setCalendarPeriod(null);
|
|
151
155
|
(_a = popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.onExited) === null || _a === void 0 ? void 0 : _a.call(popoverProps);
|
|
152
156
|
};
|
|
157
|
+
var prepareInputValue = function (value) {
|
|
158
|
+
var trimmed = value.trim();
|
|
159
|
+
if (isWasPaste.current) {
|
|
160
|
+
return maskPastedDate(trimmed, steps);
|
|
161
|
+
}
|
|
162
|
+
return trimmed;
|
|
163
|
+
};
|
|
153
164
|
/** Событие ввода значения в текстовом поле */
|
|
154
|
-
var handleChangeInputFrom = function (
|
|
165
|
+
var handleChangeInputFrom = function (event) {
|
|
155
166
|
var _a;
|
|
156
|
-
var value =
|
|
157
|
-
(_a = inputPropsFrom === null || inputPropsFrom === void 0 ? void 0 : inputPropsFrom.onChange) === null || _a === void 0 ? void 0 : _a.call(inputPropsFrom,
|
|
158
|
-
changeInputValue(
|
|
167
|
+
var value = prepareInputValue(event.target.value);
|
|
168
|
+
(_a = inputPropsFrom === null || inputPropsFrom === void 0 ? void 0 : inputPropsFrom.onChange) === null || _a === void 0 ? void 0 : _a.call(inputPropsFrom, event);
|
|
169
|
+
changeInputValue(event, [value, inputValueTo]);
|
|
170
|
+
isWasPaste.current = false;
|
|
159
171
|
};
|
|
160
172
|
/** Очистка поля */
|
|
161
173
|
var handleClear = function (type) { return function () {
|
|
@@ -177,7 +189,7 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
177
189
|
setFocusInputFrom.off();
|
|
178
190
|
if (!inputValue)
|
|
179
191
|
return;
|
|
180
|
-
if (!isValidDateString(inputValueFrom)) {
|
|
192
|
+
if (!isValidDateString(inputValueFrom, steps)) {
|
|
181
193
|
changeInputValue(null, lastValidDate.current);
|
|
182
194
|
}
|
|
183
195
|
};
|
|
@@ -187,15 +199,26 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
187
199
|
setFocusInputTo.off();
|
|
188
200
|
if (!inputValue)
|
|
189
201
|
return;
|
|
190
|
-
if (!isValidDateString(inputValueTo))
|
|
202
|
+
if (!isValidDateString(inputValueTo, steps))
|
|
191
203
|
changeInputValue(null, lastValidDate.current);
|
|
192
204
|
};
|
|
193
205
|
/** Событие ввода значения в текстовом поле */
|
|
194
|
-
var handleChangeInputTo = function (
|
|
206
|
+
var handleChangeInputTo = function (event) {
|
|
207
|
+
var _a;
|
|
208
|
+
var value = prepareInputValue(event.target.value);
|
|
209
|
+
(_a = inputPropsTo === null || inputPropsTo === void 0 ? void 0 : inputPropsTo.onChange) === null || _a === void 0 ? void 0 : _a.call(inputPropsTo, event);
|
|
210
|
+
changeInputValue(event, [inputValueFrom, value]);
|
|
211
|
+
isWasPaste.current = false;
|
|
212
|
+
};
|
|
213
|
+
var handlePasteInputFrom = function (event) {
|
|
214
|
+
var _a;
|
|
215
|
+
isWasPaste.current = true;
|
|
216
|
+
(_a = inputPropsFrom === null || inputPropsFrom === void 0 ? void 0 : inputPropsFrom.onPaste) === null || _a === void 0 ? void 0 : _a.call(inputPropsFrom, event);
|
|
217
|
+
};
|
|
218
|
+
var handlePasteInputTo = function (event) {
|
|
195
219
|
var _a;
|
|
196
|
-
|
|
197
|
-
(_a = inputPropsTo === null || inputPropsTo === void 0 ? void 0 : inputPropsTo.
|
|
198
|
-
changeInputValue(e, [inputValueFrom, value]);
|
|
220
|
+
isWasPaste.current = true;
|
|
221
|
+
(_a = inputPropsTo === null || inputPropsTo === void 0 ? void 0 : inputPropsTo.onPaste) === null || _a === void 0 ? void 0 : _a.call(inputPropsTo, event);
|
|
199
222
|
};
|
|
200
223
|
/** Открытие списка по клику на текстовом поле */
|
|
201
224
|
var handleClickOnInputFrom = function (e) {
|
|
@@ -221,8 +244,8 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
221
244
|
var handleChangeCalendar = function (date) {
|
|
222
245
|
var _a = __read(date || [], 2), dateFrom = _a[0], dateTo = _a[1];
|
|
223
246
|
var formattedDate = [
|
|
224
|
-
formatDateToString(dateFrom),
|
|
225
|
-
formatDateToString(dateTo),
|
|
247
|
+
formatDateToString(dateFrom, steps),
|
|
248
|
+
formatDateToString(dateTo, steps),
|
|
226
249
|
];
|
|
227
250
|
changeInputValue(null, formattedDate);
|
|
228
251
|
if (!disableCloseOnSelect && dateFrom && dateTo)
|
|
@@ -238,10 +261,10 @@ export var DatePickerModeDateRange = forwardRef(function (props, ref) {
|
|
|
238
261
|
disableStroke: disableStroke,
|
|
239
262
|
}, [className]) }, other, { ref: rootRef }),
|
|
240
263
|
React.createElement(Stack, __assign({ gap: "l", className: cnDatePicker('Fields', [fieldsProps === null || fieldsProps === void 0 ? void 0 : fieldsProps.className]) }, fieldsProps, { ref: fieldsRef }),
|
|
241
|
-
React.createElement(DateInput, { size: size, error: error, label: labelFrom, required: required, disabled: disabled, value: inputValueFrom, onKeyDown: handleKeyDown, renderLeft: renderLeftFrom, labelProps: labelPropsFrom, disableStroke: disableStroke, placeholder: placeholderFrom, renderRight: React.createElement(DatePickerRenderRight, { size: size, open: open, hasValue: !!valueFrom, clearText: clearText, renderRight: renderRightFrom, onClear: handleClear('from'), disableClearButton: disableClearButton }), inputProps: __assign(__assign({ autoComplete: 'off' }, inputPropsFrom), { onBlur: handleBlurInputFrom, onFocus: handleFocusInputFrom, onClick: handleClickOnInputFrom, onChange: handleChangeInputFrom }), "data-testid": "date-input-from", bodyProps: { 'aria-expanded': open } }),
|
|
242
|
-
React.createElement(DateInput, { size: size, error: error, label: labelTo, required: required, disabled: disabled, value: inputValueTo, onKeyDown: handleKeyDown, renderLeft: renderLeftTo, labelProps: labelPropsTo, placeholder: placeholderTo, disableStroke: disableStroke, renderRight: React.createElement(DatePickerRenderRight, { size: size, open: open, hasValue: !!valueTo, clearText: clearText, renderRight: renderRightTo, onClear: handleClear('to'), disableClearButton: disableClearButton }), inputProps: __assign(__assign({ autoComplete: 'off' }, inputPropsTo), { onBlur: handleBlurInputTo, onFocus: handleFocusInputTo, onClick: handleClickOnInputTo, onChange: handleChangeInputTo }), "data-testid": "date-input-to", bodyProps: { ref: dateInputToRef, 'aria-expanded': open } })),
|
|
264
|
+
React.createElement(DateInput, { size: size, error: error, label: labelFrom, required: required, disabled: disabled, value: inputValueFrom, onKeyDown: handleKeyDown, renderLeft: renderLeftFrom, labelProps: labelPropsFrom, disableStroke: disableStroke, steps: steps, placeholder: placeholderFrom, renderRight: React.createElement(DatePickerRenderRight, { size: size, open: open, hasValue: !!valueFrom, clearText: clearText, renderRight: renderRightFrom, onClear: handleClear('from'), disableClearButton: disableClearButton }), inputProps: __assign(__assign({ autoComplete: 'off' }, inputPropsFrom), { onBlur: handleBlurInputFrom, onFocus: handleFocusInputFrom, onClick: handleClickOnInputFrom, onChange: handleChangeInputFrom, onPaste: handlePasteInputFrom }), "data-testid": "date-input-from", bodyProps: { 'aria-expanded': open } }),
|
|
265
|
+
React.createElement(DateInput, { size: size, error: error, label: labelTo, required: required, disabled: disabled, value: inputValueTo, onKeyDown: handleKeyDown, renderLeft: renderLeftTo, labelProps: labelPropsTo, placeholder: placeholderTo, disableStroke: disableStroke, steps: steps, renderRight: React.createElement(DatePickerRenderRight, { size: size, open: open, hasValue: !!valueTo, clearText: clearText, renderRight: renderRightTo, onClear: handleClear('to'), disableClearButton: disableClearButton }), inputProps: __assign(__assign({ autoComplete: 'off' }, inputPropsTo), { onBlur: handleBlurInputTo, onFocus: handleFocusInputTo, onClick: handleClickOnInputTo, onChange: handleChangeInputTo, onPaste: handlePasteInputTo }), "data-testid": "date-input-to", bodyProps: { ref: dateInputToRef, 'aria-expanded': open } })),
|
|
243
266
|
React.createElement(FieldHint, __assign({ size: size, error: error, disabled: disabled }, hintProps), hint),
|
|
244
267
|
React.createElement(Popover, __assign({ open: open, anchorRef: anchorRef, onClose: handleClose }, popoverProps, { onExited: handleExited, ignoreClickOutsideRefs: [containerRef], disableEnforceFocus: disableEnforceFocus }),
|
|
245
|
-
React.createElement(Calendar, __assign({ calendars: calendars }, calendarProps, { mode: "range", offsetDate: offsetDate, onChange: handleChangeCalendar, value: formatDateForCalendar(value), onCalendarsChange: onCalendarsChange, onOffsetDateChange: onOffsetDateChange })))));
|
|
268
|
+
React.createElement(Calendar, __assign({ calendars: calendars }, calendarProps, { initialStep: initialStep, steps: steps, mode: "range", offsetDate: offsetDate, onChange: handleChangeCalendar, value: formatDateForCalendar(value), onCalendarsChange: onCalendarsChange, onOffsetDateChange: onOffsetDateChange })))));
|
|
246
269
|
});
|
|
247
270
|
DatePickerModeDateRange.displayName = 'DatePickerModeDateRange';
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { CALENDAR_DEFAULT_INITIAL_STEP, CALENDAR_DEFAULT_STEPS, } from '../Calendar';
|
|
1
2
|
export var DATE_PICKER_DEFAULT_SIZE = 'm';
|
|
2
3
|
export var DATE_PICKER_DEFAULT_MODE = 'date';
|
|
4
|
+
export var DATE_PICKER_DEFAULT_STEPS = CALENDAR_DEFAULT_STEPS;
|
|
5
|
+
export var DATE_PICKER_DEFAULT_INITIAL_STEP = CALENDAR_DEFAULT_INITIAL_STEP;
|