@ozen-ui/kit 0.47.2 → 0.48.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/DatePicker/package.json +5 -0
- package/__inner__/cjs/components/Autocomplete/Autocomplete.js +57 -63
- package/__inner__/cjs/components/Autocomplete/helper.d.ts +6 -0
- package/__inner__/cjs/components/Autocomplete/types.d.ts +1 -1
- package/__inner__/cjs/components/Calendar/types.d.ts +1 -1
- package/__inner__/cjs/components/DatePicker/DatePicker.css +11 -0
- package/__inner__/cjs/components/DatePicker/DatePicker.d.ts +39 -0
- package/__inner__/cjs/components/DatePicker/DatePicker.js +160 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/DateInput.d.ts +6 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/DateInput.js +14 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.d.ts +2 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.js +20 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/dateInputMask/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/dateInputMask/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/components/DateInput/utils/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/components/DatePickerRenderRight/DatePickerRenderRight.d.ts +8 -0
- package/__inner__/cjs/components/DatePicker/components/DatePickerRenderRight/DatePickerRenderRight.js +26 -0
- package/__inner__/cjs/components/DatePicker/components/DatePickerRenderRight/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/components/DatePickerRenderRight/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/components/index.d.ts +2 -0
- package/__inner__/cjs/components/DatePicker/components/index.js +5 -0
- package/__inner__/cjs/components/DatePicker/constants.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/constants.js +4 -0
- package/__inner__/cjs/components/DatePicker/index.d.ts +2 -0
- package/__inner__/cjs/components/DatePicker/index.js +5 -0
- package/__inner__/cjs/components/DatePicker/types.d.ts +52 -0
- package/__inner__/cjs/components/DatePicker/types.js +2 -0
- package/__inner__/cjs/components/DatePicker/utils/formatDateToString/formatDateToString.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/formatDateToString/formatDateToString.js +13 -0
- package/__inner__/cjs/components/DatePicker/utils/formatDateToString/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/formatDateToString/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/utils/formatStringToDate/formatStringToDate.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/formatStringToDate/formatStringToDate.js +13 -0
- package/__inner__/cjs/components/DatePicker/utils/formatStringToDate/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/formatStringToDate/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/utils/index.d.ts +5 -0
- package/__inner__/cjs/components/DatePicker/utils/index.js +8 -0
- package/__inner__/cjs/components/DatePicker/utils/isInExclude/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/isInExclude/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/utils/isInExclude/isInExclude.d.ts +2 -0
- package/__inner__/cjs/components/DatePicker/utils/isInExclude/isInExclude.js +14 -0
- package/__inner__/cjs/components/DatePicker/utils/isOutOfRange/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/isOutOfRange/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/utils/isOutOfRange/isOutOfRange.d.ts +2 -0
- package/__inner__/cjs/components/DatePicker/utils/isOutOfRange/isOutOfRange.js +11 -0
- package/__inner__/cjs/components/DatePicker/utils/matchCalendarSizeToFormElement/index.d.ts +1 -0
- package/__inner__/cjs/components/DatePicker/utils/matchCalendarSizeToFormElement/index.js +4 -0
- package/__inner__/cjs/components/DatePicker/utils/matchCalendarSizeToFormElement/matchCalendarSizeToFormElement.d.ts +5 -0
- package/__inner__/cjs/components/DatePicker/utils/matchCalendarSizeToFormElement/matchCalendarSizeToFormElement.js +10 -0
- package/__inner__/cjs/components/Input/Input.css +0 -1
- package/__inner__/cjs/components/Input/Input.js +1 -1
- package/__inner__/cjs/components/ThemeProvider/types.d.ts +2 -0
- package/__inner__/cjs/locale/locale.js +12 -0
- package/__inner__/esm/components/Autocomplete/Autocomplete.js +57 -63
- package/__inner__/esm/components/Autocomplete/helper.d.ts +6 -0
- package/__inner__/esm/components/Autocomplete/types.d.ts +1 -1
- package/__inner__/esm/components/Calendar/types.d.ts +1 -1
- package/__inner__/esm/components/DatePicker/DatePicker.css +11 -0
- package/__inner__/esm/components/DatePicker/DatePicker.d.ts +39 -0
- package/__inner__/esm/components/DatePicker/DatePicker.js +157 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/DateInput.d.ts +6 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/DateInput.js +11 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/index.js +1 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.d.ts +2 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/dateInputMask/dateInputMask.js +15 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/dateInputMask/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/dateInputMask/index.js +1 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/components/DateInput/utils/index.js +1 -0
- package/__inner__/esm/components/DatePicker/components/DatePickerRenderRight/DatePickerRenderRight.d.ts +8 -0
- package/__inner__/esm/components/DatePicker/components/DatePickerRenderRight/DatePickerRenderRight.js +22 -0
- package/__inner__/esm/components/DatePicker/components/DatePickerRenderRight/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/components/DatePickerRenderRight/index.js +1 -0
- package/__inner__/esm/components/DatePicker/components/index.d.ts +2 -0
- package/__inner__/esm/components/DatePicker/components/index.js +2 -0
- package/__inner__/esm/components/DatePicker/constants.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/constants.js +1 -0
- package/__inner__/esm/components/DatePicker/index.d.ts +2 -0
- package/__inner__/esm/components/DatePicker/index.js +2 -0
- package/__inner__/esm/components/DatePicker/types.d.ts +52 -0
- package/__inner__/esm/components/DatePicker/types.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/formatDateToString/formatDateToString.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/formatDateToString/formatDateToString.js +9 -0
- package/__inner__/esm/components/DatePicker/utils/formatDateToString/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/formatDateToString/index.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/formatStringToDate/formatStringToDate.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/formatStringToDate/formatStringToDate.js +9 -0
- package/__inner__/esm/components/DatePicker/utils/formatStringToDate/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/formatStringToDate/index.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/index.d.ts +5 -0
- package/__inner__/esm/components/DatePicker/utils/index.js +5 -0
- package/__inner__/esm/components/DatePicker/utils/isInExclude/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/isInExclude/index.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/isInExclude/isInExclude.d.ts +2 -0
- package/__inner__/esm/components/DatePicker/utils/isInExclude/isInExclude.js +10 -0
- package/__inner__/esm/components/DatePicker/utils/isOutOfRange/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/isOutOfRange/index.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/isOutOfRange/isOutOfRange.d.ts +2 -0
- package/__inner__/esm/components/DatePicker/utils/isOutOfRange/isOutOfRange.js +7 -0
- package/__inner__/esm/components/DatePicker/utils/matchCalendarSizeToFormElement/index.d.ts +1 -0
- package/__inner__/esm/components/DatePicker/utils/matchCalendarSizeToFormElement/index.js +1 -0
- package/__inner__/esm/components/DatePicker/utils/matchCalendarSizeToFormElement/matchCalendarSizeToFormElement.d.ts +5 -0
- package/__inner__/esm/components/DatePicker/utils/matchCalendarSizeToFormElement/matchCalendarSizeToFormElement.js +7 -0
- package/__inner__/esm/components/Input/Input.css +0 -1
- package/__inner__/esm/components/Input/Input.js +1 -1
- package/__inner__/esm/components/ThemeProvider/types.d.ts +2 -0
- package/__inner__/esm/locale/locale.js +12 -0
- package/package.json +4 -4
|
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
require("./Autocomplete.css");
|
|
6
6
|
var react_1 = tslib_1.__importStar(require("react"));
|
|
7
7
|
var useControlled_1 = require("../../hooks/useControlled");
|
|
8
|
+
var useMultiRef_1 = require("../../hooks/useMultiRef");
|
|
8
9
|
var useMutableRef_1 = require("../../hooks/useMutableRef");
|
|
9
10
|
var useThemeProps_1 = require("../../hooks/useThemeProps");
|
|
10
11
|
var classname_1 = require("../../utils/classname");
|
|
@@ -20,8 +21,10 @@ function AutocompleteRender(inProps, ref) {
|
|
|
20
21
|
props: inProps,
|
|
21
22
|
name: 'Autocomplete',
|
|
22
23
|
});
|
|
23
|
-
var _a = (0, helper_1.withDefaultGetters)(props), _b = _a.disabled, disabled = _b === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return react_1.default.createElement(Input_1.Input, tslib_1.__assign({}, props, { ref: ref })); } : _m, searchFunctionProp = _a.searchFunction, renderOptionProp = _a.renderOption, inputValueProp = _a.inputValue, className = _a.className, valueProp = _a.value, options = _a.options, defaultValue = _a.defaultValue, error = _a.error, onChange = _a.onChange, onInputChange = _a.onInputChange, label = _a.label, placeholder = _a.placeholder, renderLeft = _a.renderLeft, renderRight = _a.renderRight, hint = _a.hint, getOptionKey = _a.getOptionKey, getOptionLabel = _a.getOptionLabel, getOptionDisabled = _a.getOptionDisabled, dataListProps = _a.dataListProps, onCloseProp = _a.onClose, onOpenProp = _a.onOpen, openProp = _a.open, defaultOpen = _a.defaultOpen, loading = _a.loading, inputProps = _a.inputProps, onKeyDown = _a.onKeyDown, noOptionsText = _a.noOptionsText, clearText = _a.clearText, openText = _a.openText, loadingText = _a.loadingText, closeText = _a.closeText, other = tslib_1.__rest(_a, ["disabled", "required", "autoFocus", "fullWidth", "size", "allowCustomValue", "disableShowChevron", "disableClearButton", "disableShowEmptyOptionsList", "disableCloseOnSelect", "renderInput", "searchFunction", "renderOption", "inputValue", "className", "value", "options", "defaultValue", "error", "onChange", "onInputChange", "label", "placeholder", "renderLeft", "renderRight", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
|
|
24
|
+
var _a = (0, helper_1.withDefaultGetters)(props), _b = _a.disabled, disabled = _b === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? constants_1.AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return react_1.default.createElement(Input_1.Input, tslib_1.__assign({}, props, { ref: ref })); } : _m, searchFunctionProp = _a.searchFunction, renderOptionProp = _a.renderOption, inputValueProp = _a.inputValue, className = _a.className, valueProp = _a.value, options = _a.options, defaultValue = _a.defaultValue, error = _a.error, onChange = _a.onChange, onInputChange = _a.onInputChange, label = _a.label, placeholder = _a.placeholder, renderLeft = _a.renderLeft, renderRight = _a.renderRight, hint = _a.hint, getOptionKey = _a.getOptionKey, getOptionLabel = _a.getOptionLabel, getOptionDisabled = _a.getOptionDisabled, dataListProps = _a.dataListProps, onCloseProp = _a.onClose, onOpenProp = _a.onOpen, openProp = _a.open, defaultOpen = _a.defaultOpen, loading = _a.loading, inputProps = _a.inputProps, bodyProps = _a.bodyProps, onKeyDown = _a.onKeyDown, noOptionsText = _a.noOptionsText, clearText = _a.clearText, openText = _a.openText, loadingText = _a.loadingText, closeText = _a.closeText, other = tslib_1.__rest(_a, ["disabled", "required", "autoFocus", "fullWidth", "size", "allowCustomValue", "disableShowChevron", "disableClearButton", "disableShowEmptyOptionsList", "disableCloseOnSelect", "renderInput", "searchFunction", "renderOption", "inputValue", "className", "value", "options", "defaultValue", "error", "onChange", "onInputChange", "label", "placeholder", "renderLeft", "renderRight", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "bodyProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
|
|
24
25
|
var anchorRef = (0, react_1.useRef)(null);
|
|
26
|
+
var lastInputValue = (0, react_1.useRef)('');
|
|
27
|
+
var inputBodyRef = (0, useMultiRef_1.useMultiRef)([anchorRef, bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.ref]);
|
|
25
28
|
var _o = tslib_1.__read((0, useControlled_1.useControlled)({
|
|
26
29
|
value: inputValueProp,
|
|
27
30
|
defaultValue: '',
|
|
@@ -54,47 +57,43 @@ function AutocompleteRender(inProps, ref) {
|
|
|
54
57
|
var showNoOptions = !hasOptions && !loading;
|
|
55
58
|
var showLoading = !hasOptions && !!loading;
|
|
56
59
|
var _s = tslib_1.__read((0, react_1.useState)(undefined), 2), search = _s[0], setSearch = _s[1];
|
|
57
|
-
|
|
60
|
+
var changeInputValue = function (e, value) {
|
|
61
|
+
var _a;
|
|
62
|
+
setInputValue(value);
|
|
63
|
+
(_a = savedOnInputChange.current) === null || _a === void 0 ? void 0 : _a.call(savedOnInputChange, e, value);
|
|
64
|
+
};
|
|
65
|
+
var callOnChange = function (e, value) {
|
|
66
|
+
var inputValue = value ? getOptionLabel(value) : '';
|
|
67
|
+
setValueState(value);
|
|
68
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e, value);
|
|
69
|
+
changeInputValue(null, inputValue);
|
|
70
|
+
};
|
|
71
|
+
/** Эффект – фильтрация списка при изменении опций */
|
|
58
72
|
(0, react_1.useEffect)(function () {
|
|
59
|
-
if (!open)
|
|
73
|
+
if (!open)
|
|
60
74
|
return;
|
|
61
|
-
}
|
|
62
75
|
setFilteredOptions(search ? search(options) : tslib_1.__spreadArray([], tslib_1.__read(options), false));
|
|
63
76
|
}, [search, options, open, searchFunctionProp]);
|
|
64
77
|
/** Эффект – синхронизируем значение текстового поля со значением в списке */
|
|
65
78
|
(0, react_1.useEffect)(function () {
|
|
66
|
-
var _a
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
(
|
|
79
|
+
var _a;
|
|
80
|
+
if (allowCustomValue)
|
|
81
|
+
return;
|
|
82
|
+
lastInputValue.current = valueState
|
|
83
|
+
? (_a = savedGetOptionLabel.current) === null || _a === void 0 ? void 0 : _a.call(savedGetOptionLabel, valueState)
|
|
84
|
+
: '';
|
|
85
|
+
if (lastInputValue.current !== inputValue) {
|
|
86
|
+
changeInputValue(null, lastInputValue.current);
|
|
74
87
|
}
|
|
75
|
-
}, [valueState]);
|
|
88
|
+
}, [valueState, allowCustomValue]);
|
|
76
89
|
/** Эффект – автофокусировка в текстовом поле */
|
|
77
90
|
(0, react_1.useEffect)(function () {
|
|
78
91
|
var _a;
|
|
79
|
-
if (autoFocus)
|
|
92
|
+
if (autoFocus)
|
|
80
93
|
(_a = anchorRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
81
|
-
}
|
|
82
94
|
}, [autoFocus]);
|
|
83
|
-
/**
|
|
84
|
-
var
|
|
85
|
-
var _a;
|
|
86
|
-
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
87
|
-
if (allowCustomValue) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
var value = valueState ? getOptionLabel(valueState) : '';
|
|
91
|
-
if (inputValue !== value) {
|
|
92
|
-
setInputValue(value);
|
|
93
|
-
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(null, value);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
/** Ждем выполнения анимации на закрытие и делаем сброс */
|
|
97
|
-
var onExited = function () {
|
|
95
|
+
/** Ждём выполнения анимации на закрытие и делаем сброс функции фильтрации */
|
|
96
|
+
var handleExited = function () {
|
|
98
97
|
var _a;
|
|
99
98
|
setSearch(undefined);
|
|
100
99
|
(_a = dataListProps === null || dataListProps === void 0 ? void 0 : dataListProps.onExited) === null || _a === void 0 ? void 0 : _a.call(dataListProps);
|
|
@@ -113,21 +112,26 @@ function AutocompleteRender(inProps, ref) {
|
|
|
113
112
|
var handleToggle = function () {
|
|
114
113
|
if (disabled)
|
|
115
114
|
return;
|
|
116
|
-
if (open)
|
|
115
|
+
if (open)
|
|
117
116
|
handleClose();
|
|
118
|
-
|
|
119
|
-
else {
|
|
117
|
+
else
|
|
120
118
|
handleOpen();
|
|
121
|
-
}
|
|
122
119
|
};
|
|
123
120
|
/** Очистка поля */
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
setInputValue('');
|
|
127
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(e, null);
|
|
128
|
-
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(null, '');
|
|
121
|
+
var handleClear = function (e) {
|
|
122
|
+
callOnChange(e, null);
|
|
129
123
|
setSearch(undefined);
|
|
130
124
|
};
|
|
125
|
+
/** Актуализация значения текстового поля после его покидания */
|
|
126
|
+
var handleBlur = function (e) {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
129
|
+
if (allowCustomValue)
|
|
130
|
+
return;
|
|
131
|
+
if (inputValue !== lastInputValue.current) {
|
|
132
|
+
changeInputValue(null, lastInputValue.current);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
131
135
|
/** Открытие списка по клику на текстовом поле */
|
|
132
136
|
var handleClickOnInput = function (e) {
|
|
133
137
|
var _a;
|
|
@@ -135,49 +139,39 @@ function AutocompleteRender(inProps, ref) {
|
|
|
135
139
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onClick) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
136
140
|
};
|
|
137
141
|
/** Управление элементом контроля через клавиатуру */
|
|
138
|
-
var handleKeyDown = function (
|
|
139
|
-
if ((0, isKeys_1.isKeys)(
|
|
140
|
-
|
|
142
|
+
var handleKeyDown = function (e) {
|
|
143
|
+
if ((0, isKeys_1.isKeys)(e, ['ArrowDown', 'ArrowUp']) && !open) {
|
|
144
|
+
e.preventDefault();
|
|
141
145
|
handleToggle();
|
|
142
146
|
}
|
|
143
|
-
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(
|
|
147
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
144
148
|
};
|
|
145
149
|
/** Событие ввода значения в текстовом поле */
|
|
146
150
|
var handleChangeInput = function (e) {
|
|
147
151
|
var value = e.target.value;
|
|
148
152
|
// Открываем список при вводе первого символа (при условии, что список еще не открыт)
|
|
149
|
-
if (value.length && !open)
|
|
153
|
+
if (value.length && !open)
|
|
150
154
|
handleOpen();
|
|
155
|
+
if (value) {
|
|
156
|
+
changeInputValue(e, value);
|
|
151
157
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
setValueState(null);
|
|
155
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(e, null);
|
|
158
|
+
else {
|
|
159
|
+
callOnChange(e, null);
|
|
156
160
|
}
|
|
157
|
-
// Назначаем значение
|
|
158
|
-
setInputValue(value);
|
|
159
|
-
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(e, value);
|
|
160
161
|
// Задаем функцию фильтрации
|
|
161
162
|
setSearch(function () { return function (options) { return searchFunction(tslib_1.__spreadArray([], tslib_1.__read(options), false), value); }; });
|
|
162
163
|
};
|
|
163
164
|
/** Событие выбора значения из раскрывающегося списка */
|
|
164
|
-
var handleChangeDataList = function (
|
|
165
|
+
var handleChangeDataList = function (e, _a) {
|
|
165
166
|
var value = _a.value;
|
|
166
167
|
var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option)) === value; });
|
|
167
|
-
|
|
168
|
-
var newInputValue = getOptionLabel(selectedOption);
|
|
169
|
-
setValueState(selectedOption);
|
|
170
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(event, selectedOption);
|
|
171
|
-
setInputValue(newInputValue);
|
|
172
|
-
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(null, newInputValue);
|
|
173
|
-
}
|
|
168
|
+
callOnChange(e, selectedOption || null);
|
|
174
169
|
// Закрываем список после выбора
|
|
175
|
-
if (!disableCloseOnSelect)
|
|
170
|
+
if (!disableCloseOnSelect)
|
|
176
171
|
handleClose();
|
|
177
|
-
}
|
|
178
172
|
};
|
|
179
173
|
/** Отображение текстового поля */
|
|
180
|
-
var input = renderInput(tslib_1.__assign(tslib_1.__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (react_1.default.createElement(components_1.AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear:
|
|
174
|
+
var input = renderInput(tslib_1.__assign(tslib_1.__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (react_1.default.createElement(components_1.AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear: handleClear, onOpen: handleToggle, renderRight: renderRight, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: tslib_1.__assign(tslib_1.__assign({}, inputProps), { onBlur: handleBlur, onClick: handleClickOnInput }), bodyProps: tslib_1.__assign(tslib_1.__assign({ 'aria-expanded': open }, bodyProps), { ref: inputBodyRef }), className: (0, exports.cnAutocomplete)({ size: size, hasChevron: !disableShowChevron }, [
|
|
181
175
|
className,
|
|
182
176
|
]), ref: ref }));
|
|
183
177
|
/** Отображение опций */
|
|
@@ -194,7 +188,7 @@ function AutocompleteRender(inProps, ref) {
|
|
|
194
188
|
});
|
|
195
189
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
196
190
|
input,
|
|
197
|
-
react_1.default.createElement(DataList_1.DataList, tslib_1.__assign({ size: size, equalAnchorWidth: true, offset: [0, 4], placement: "bottom-start" }, dataListProps, { open: open,
|
|
191
|
+
react_1.default.createElement(DataList_1.DataList, tslib_1.__assign({ size: size, equalAnchorWidth: true, offset: [0, 4], placement: "bottom-start" }, dataListProps, { open: open, onClose: handleClose, anchorRef: anchorRef, onExited: handleExited, selected: dataListValue, onSelect: handleChangeDataList, listProps: tslib_1.__assign({ role: 'listbox' }, dataListProps === null || dataListProps === void 0 ? void 0 : dataListProps.listProps) }),
|
|
198
192
|
renderOptions,
|
|
199
193
|
!disableShowEmptyOptionsList && (react_1.default.createElement(components_1.AutocompleteNoOptions, { showNoOptions: showNoOptions, noOptionsText: noOptionsText })),
|
|
200
194
|
react_1.default.createElement(components_1.AutocompleteLoading, { showLoading: showLoading, loadingText: loadingText, size: size }))));
|
|
@@ -80,6 +80,9 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
|
|
|
80
80
|
} & {
|
|
81
81
|
'data-testid'?: string | undefined;
|
|
82
82
|
}) | undefined;
|
|
83
|
+
bodyProps?: (Omit<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "ref"> & {
|
|
84
|
+
ref?: ((instance: HTMLLabelElement | null) => void) | import("react").RefObject<HTMLLabelElement> | null | undefined;
|
|
85
|
+
}) | undefined;
|
|
83
86
|
hintProps?: Omit<import("../FieldHint").FieldHintProps, "children"> | undefined;
|
|
84
87
|
} & {
|
|
85
88
|
open?: boolean | undefined;
|
|
@@ -177,6 +180,9 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
|
|
|
177
180
|
} & {
|
|
178
181
|
'data-testid'?: string | undefined;
|
|
179
182
|
}) | undefined;
|
|
183
|
+
bodyProps?: (Omit<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "ref"> & {
|
|
184
|
+
ref?: ((instance: HTMLLabelElement | null) => void) | import("react").RefObject<HTMLLabelElement> | null | undefined;
|
|
185
|
+
}) | undefined;
|
|
180
186
|
hintProps?: Omit<import("../FieldHint").FieldHintProps, "children"> | undefined;
|
|
181
187
|
} & {
|
|
182
188
|
open?: undefined;
|
|
@@ -31,7 +31,7 @@ type AutocompleteOpenUncontrolledProps = {
|
|
|
31
31
|
/** Состояние открытие по умолчанию (неконтролируемый компонент) */
|
|
32
32
|
defaultOpen?: boolean;
|
|
33
33
|
};
|
|
34
|
-
type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'renderRight' | 'className' | 'inputProps' | 'hintProps' | 'onKeyDown'>;
|
|
34
|
+
type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'renderRight' | 'className' | 'inputProps' | 'hintProps' | 'bodyProps' | 'onKeyDown'>;
|
|
35
35
|
type AutocompleteDataListProps = Partial<Omit<DataListProps, 'onClose' | 'open' | 'anchorRef' | 'multiple' | 'selected' | 'onSelect'>>;
|
|
36
36
|
export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
|
|
37
37
|
/** Список вариантов выбора (опции) */
|
|
@@ -6,7 +6,7 @@ import type { CALENDAR_DEFAULT_AS } from './constants';
|
|
|
6
6
|
export declare const calendarStepVariant: readonly ["days", "months", "years"];
|
|
7
7
|
export declare const calendarSizeVariant: readonly ["s", "m", "l"];
|
|
8
8
|
export type CalendarStepVariant = (typeof calendarStepVariant)[number];
|
|
9
|
-
export type CalendarOnChange = (date: Date) => void;
|
|
9
|
+
export type CalendarOnChange = (date: Date | null) => void;
|
|
10
10
|
export type CalendarOnOffsetDateChange = (date: Date) => void;
|
|
11
11
|
export type CalendarSizeVariant = (typeof calendarSizeVariant)[number];
|
|
12
12
|
export type CalendarExclude = DPExcludeConfig;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import './DatePicker.css';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { CalendarOnChange } from '../Calendar';
|
|
4
|
+
export declare const cnDatePicker: import("@bem-react/classname").ClassNameFormatter;
|
|
5
|
+
export declare const DatePicker: React.ForwardRefExoticComponent<(Omit<{
|
|
6
|
+
value?: Date | null | undefined;
|
|
7
|
+
defaultValue?: Date | null | undefined;
|
|
8
|
+
onChange?: CalendarOnChange | undefined;
|
|
9
|
+
onInputChange?: import("./types").DatePickerOnInputChange | undefined;
|
|
10
|
+
onClose?: (() => void) | undefined;
|
|
11
|
+
onOpen?: (() => void) | undefined;
|
|
12
|
+
calendarProps?: import("../Calendar").CalendarBaseProps | undefined;
|
|
13
|
+
popoverProps?: import("../Popover").PopoverBaseProps | undefined;
|
|
14
|
+
clearText?: string | undefined;
|
|
15
|
+
disableClearButton?: boolean | undefined;
|
|
16
|
+
onError?: import("./types").DatePickerPropOnError | undefined;
|
|
17
|
+
} & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
18
|
+
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
19
|
+
}, "defaultValue" | "onChange" | "onError"> & Pick<import("../Calendar").CalendarBaseProps, "exclude" | "offsetDate" | "minDate" | "maxDate"> & Pick<import("../Input").InputProps, "label" | "onKeyDown" | "disabled" | "placeholder" | "required" | "size" | "error" | "fullWidth" | "hint" | "renderLeft" | "renderRight" | "inputProps"> & {
|
|
20
|
+
open?: boolean | undefined;
|
|
21
|
+
defaultOpen?: undefined;
|
|
22
|
+
}, "ref"> | Omit<{
|
|
23
|
+
value?: Date | null | undefined;
|
|
24
|
+
defaultValue?: Date | null | undefined;
|
|
25
|
+
onChange?: CalendarOnChange | undefined;
|
|
26
|
+
onInputChange?: import("./types").DatePickerOnInputChange | undefined;
|
|
27
|
+
onClose?: (() => void) | undefined;
|
|
28
|
+
onOpen?: (() => void) | undefined;
|
|
29
|
+
calendarProps?: import("../Calendar").CalendarBaseProps | undefined;
|
|
30
|
+
popoverProps?: import("../Popover").PopoverBaseProps | undefined;
|
|
31
|
+
clearText?: string | undefined;
|
|
32
|
+
disableClearButton?: boolean | undefined;
|
|
33
|
+
onError?: import("./types").DatePickerPropOnError | undefined;
|
|
34
|
+
} & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
35
|
+
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
36
|
+
}, "defaultValue" | "onChange" | "onError"> & Pick<import("../Calendar").CalendarBaseProps, "exclude" | "offsetDate" | "minDate" | "maxDate"> & Pick<import("../Input").InputProps, "label" | "onKeyDown" | "disabled" | "placeholder" | "required" | "size" | "error" | "fullWidth" | "hint" | "renderLeft" | "renderRight" | "inputProps"> & {
|
|
37
|
+
open?: undefined;
|
|
38
|
+
defaultOpen?: boolean | undefined;
|
|
39
|
+
}, "ref">) & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatePicker = exports.cnDatePicker = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
require("./DatePicker.css");
|
|
6
|
+
var react_1 = tslib_1.__importStar(require("react"));
|
|
7
|
+
var useControlled_1 = require("../../hooks/useControlled");
|
|
8
|
+
var useThemeProps_1 = require("../../hooks/useThemeProps");
|
|
9
|
+
var classname_1 = require("../../utils/classname");
|
|
10
|
+
var getPaperSizeToFormElement_1 = require("../../utils/getPaperSizeToFormElement");
|
|
11
|
+
var isKeys_1 = require("../../utils/isKeys");
|
|
12
|
+
var Calendar_1 = require("../Calendar");
|
|
13
|
+
var Paper_1 = require("../Paper");
|
|
14
|
+
var Popover_1 = require("../Popover");
|
|
15
|
+
var components_1 = require("./components");
|
|
16
|
+
var utils_1 = require("./components/DateInput/utils");
|
|
17
|
+
var constants_1 = require("./constants");
|
|
18
|
+
var utils_2 = require("./utils");
|
|
19
|
+
exports.cnDatePicker = (0, classname_1.cn)('DatePicker');
|
|
20
|
+
exports.DatePicker = (0, react_1.forwardRef)(function (inProps, ref) {
|
|
21
|
+
var props = (0, useThemeProps_1.useThemeProps)({
|
|
22
|
+
props: inProps,
|
|
23
|
+
name: 'DatePicker',
|
|
24
|
+
});
|
|
25
|
+
var _a = props.size, size = _a === void 0 ? constants_1.DATE_PICKER_DEFAULT_SIZE : _a, label = props.label, error = props.error, required = props.required, fullWidth = props.fullWidth, placeholder = props.placeholder, hint = props.hint, valueProp = props.value, 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, offsetDate = props.offsetDate, inputProps = props.inputProps, calendarProps = props.calendarProps, popoverProps = props.popoverProps, renderRight = props.renderRight, disableClearButton = props.disableClearButton, onChange = props.onChange, onKeyDown = props.onKeyDown, className = props.className, autoFocus = props.autoFocus, onError = props.onError, other = tslib_1.__rest(props, ["size", "label", "error", "required", "fullWidth", "placeholder", "hint", "value", "defaultValue", "open", "onClose", "onOpen", "onInputChange", "clearText", "defaultOpen", "disabled", "minDate", "maxDate", "exclude", "offsetDate", "inputProps", "calendarProps", "popoverProps", "renderRight", "disableClearButton", "onChange", "onKeyDown", "className", "autoFocus", "onError"]);
|
|
26
|
+
var anchorRef = (0, react_1.useRef)(null);
|
|
27
|
+
var lastValidDate = (0, react_1.useRef)('');
|
|
28
|
+
var _b = tslib_1.__read((0, useControlled_1.useControlled)({
|
|
29
|
+
value: undefined,
|
|
30
|
+
defaultValue: '',
|
|
31
|
+
name: 'DatePicker',
|
|
32
|
+
state: 'inputValue',
|
|
33
|
+
}), 2), inputValue = _b[0], setInputValue = _b[1];
|
|
34
|
+
var _c = tslib_1.__read((0, useControlled_1.useControlled)({
|
|
35
|
+
value: openProp,
|
|
36
|
+
defaultValue: defaultOpen,
|
|
37
|
+
name: 'DatePicker',
|
|
38
|
+
state: 'open',
|
|
39
|
+
}), 2), open = _c[0], setOpen = _c[1];
|
|
40
|
+
var _d = tslib_1.__read((0, useControlled_1.useControlled)({
|
|
41
|
+
value: valueProp,
|
|
42
|
+
defaultValue: defaultValue,
|
|
43
|
+
name: 'DatePicker',
|
|
44
|
+
state: 'value',
|
|
45
|
+
}), 2), value = _d[0], setValue = _d[1];
|
|
46
|
+
/** Соотношение размера календаря к размеру элемента контроля */
|
|
47
|
+
var calendarSize = utils_2.matchCalendarSizeToFormElement[size];
|
|
48
|
+
/** Вычисление border-radius по размеру компонента */
|
|
49
|
+
var radius = (0, getPaperSizeToFormElement_1.getPaperSizeToFormElement)(size);
|
|
50
|
+
var callOnChange = function (value) {
|
|
51
|
+
var formattedDate = (0, utils_2.formatStringToDate)(value);
|
|
52
|
+
setValue(formattedDate);
|
|
53
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(formattedDate);
|
|
54
|
+
lastValidDate.current = value;
|
|
55
|
+
};
|
|
56
|
+
var changeInputValue = function (e, value) {
|
|
57
|
+
setInputValue(value);
|
|
58
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(e, value);
|
|
59
|
+
if ((0, utils_1.isCompleted)(value) || value === '')
|
|
60
|
+
callOnChange(value);
|
|
61
|
+
};
|
|
62
|
+
/** Эффект – автофокусировка в текстовом поле */
|
|
63
|
+
(0, react_1.useEffect)(function () {
|
|
64
|
+
var _a;
|
|
65
|
+
if (autoFocus)
|
|
66
|
+
(_a = anchorRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
67
|
+
}, [autoFocus]);
|
|
68
|
+
/** Эффект – синхронизируем значение текстового поля со значением в списке */
|
|
69
|
+
(0, react_1.useEffect)(function () {
|
|
70
|
+
var formattedDate = (0, utils_2.formatDateToString)(value);
|
|
71
|
+
if (formattedDate !== inputValue) {
|
|
72
|
+
setInputValue(formattedDate);
|
|
73
|
+
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(null, formattedDate);
|
|
74
|
+
lastValidDate.current = formattedDate;
|
|
75
|
+
}
|
|
76
|
+
}, [value]);
|
|
77
|
+
/** Эффект для обработки ошибок */
|
|
78
|
+
(0, react_1.useEffect)(function () {
|
|
79
|
+
if ((0, utils_2.isInExclude)({ exclude: exclude, value: value })) {
|
|
80
|
+
onError === null || onError === void 0 ? void 0 : onError({
|
|
81
|
+
type: 'inExclude',
|
|
82
|
+
inputValue: inputValue,
|
|
83
|
+
value: value,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if ((0, utils_2.isOutOfRange)({ minDate: minDate, maxDate: maxDate, value: value })) {
|
|
87
|
+
onError === null || onError === void 0 ? void 0 : onError({
|
|
88
|
+
type: 'outOfRange',
|
|
89
|
+
inputValue: inputValue,
|
|
90
|
+
value: value,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}, [value, inputValue, onError, minDate, maxDate, exclude]);
|
|
94
|
+
/** Закрытие */
|
|
95
|
+
var handleClose = function () {
|
|
96
|
+
setOpen(false);
|
|
97
|
+
onCloseProp === null || onCloseProp === void 0 ? void 0 : onCloseProp();
|
|
98
|
+
};
|
|
99
|
+
/** Открытие */
|
|
100
|
+
var handleOpen = function () {
|
|
101
|
+
setOpen(true);
|
|
102
|
+
onOpenProp === null || onOpenProp === void 0 ? void 0 : onOpenProp();
|
|
103
|
+
};
|
|
104
|
+
/** Переключатель открытия и закрытия */
|
|
105
|
+
var handleToggle = function () {
|
|
106
|
+
if (disabled)
|
|
107
|
+
return;
|
|
108
|
+
if (open)
|
|
109
|
+
handleClose();
|
|
110
|
+
else
|
|
111
|
+
handleOpen();
|
|
112
|
+
};
|
|
113
|
+
/** Открытие списка по клику на текстовом поле */
|
|
114
|
+
var handleClickOnInput = function (e) {
|
|
115
|
+
var _a;
|
|
116
|
+
handleToggle();
|
|
117
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onClick) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
118
|
+
};
|
|
119
|
+
/** Управление элементом контроля через клавиатуру */
|
|
120
|
+
var handleKeyDown = function (event) {
|
|
121
|
+
if ((0, isKeys_1.isKeys)(event, ['ArrowDown', 'ArrowUp']) && !open) {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
handleToggle();
|
|
124
|
+
}
|
|
125
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
126
|
+
};
|
|
127
|
+
/** Актуализация значения текстового поля после его покидания */
|
|
128
|
+
var handleBlur = function (e) {
|
|
129
|
+
var _a;
|
|
130
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
131
|
+
if (!inputValue)
|
|
132
|
+
return;
|
|
133
|
+
if (!(0, utils_1.isCompleted)(inputValue))
|
|
134
|
+
changeInputValue(null, lastValidDate.current);
|
|
135
|
+
};
|
|
136
|
+
/** Очистка поля */
|
|
137
|
+
var handleClear = function () {
|
|
138
|
+
changeInputValue(null, '');
|
|
139
|
+
};
|
|
140
|
+
/** Событие ввода значения в текстовом поле */
|
|
141
|
+
var handleChangeInput = function (e) {
|
|
142
|
+
var value = e.target.value;
|
|
143
|
+
changeInputValue(e, value);
|
|
144
|
+
};
|
|
145
|
+
/** Событие выбора значения из календаря */
|
|
146
|
+
var handleChangeCalendar = function (date) {
|
|
147
|
+
var formattedDate = (0, utils_2.formatDateToString)(date);
|
|
148
|
+
changeInputValue(null, formattedDate);
|
|
149
|
+
handleClose();
|
|
150
|
+
};
|
|
151
|
+
/** Предотвращаем переход фокуса с текстового поля на интерактивные элементы календаря */
|
|
152
|
+
var handleMouseDownCalendar = function (e) {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
};
|
|
155
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
156
|
+
react_1.default.createElement(components_1.DateInput, tslib_1.__assign({ size: size, hint: hint, error: error, label: label, required: required, disabled: disabled, fullWidth: fullWidth, placeholder: placeholder }, other, { renderRight: react_1.default.createElement(components_1.DatePickerRenderRight, { size: size, open: open, onClear: handleClear, clearText: clearText, hasValue: !!inputValue, renderRight: renderRight, disableClearButton: disableClearButton }), value: inputValue, inputProps: tslib_1.__assign(tslib_1.__assign({}, inputProps), { onBlur: handleBlur, onClick: handleClickOnInput, onInput: handleChangeInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: (0, exports.cnDatePicker)('', [className]), onKeyDown: handleKeyDown, ref: ref })),
|
|
157
|
+
react_1.default.createElement(Popover_1.Popover, tslib_1.__assign({ as: Paper_1.Paper, open: open, offset: [0, 4], radius: radius, anchorRef: anchorRef, onClose: handleClose, placement: "bottom-start", disableReturnFocus: true, disableEnforceFocus: true }, popoverProps),
|
|
158
|
+
react_1.default.createElement(Calendar_1.Calendar, tslib_1.__assign({ minDate: minDate, maxDate: maxDate, exclude: exclude, size: calendarSize, offsetDate: offsetDate, onMouseDown: handleMouseDownCalendar }, calendarProps, { value: value || null, onChange: handleChangeCalendar })))));
|
|
159
|
+
});
|
|
160
|
+
exports.DatePicker.displayName = 'DatePicker';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { InputProps } from '../../../Input';
|
|
3
|
+
export declare const DateInput: React.ForwardRefExoticComponent<Omit<Omit<InputProps, "value" | "defaultValue"> & {
|
|
4
|
+
value?: string | undefined;
|
|
5
|
+
defaultValue?: string | undefined;
|
|
6
|
+
}, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateInput = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
var icons_1 = require("@ozen-ui/icons");
|
|
7
|
+
var useMultiRef_1 = require("../../../../hooks/useMultiRef");
|
|
8
|
+
var Input_1 = require("../../../Input");
|
|
9
|
+
var utils_1 = require("./utils");
|
|
10
|
+
exports.DateInput = (0, react_1.forwardRef)(function (_a, ref) {
|
|
11
|
+
var valueProp = _a.value, defaultValue = _a.defaultValue, other = tslib_1.__rest(_a, ["value", "defaultValue"]);
|
|
12
|
+
return (react_1.default.createElement(Input_1.Input, tslib_1.__assign({ renderRight: icons_1.CalendarIcon, value: (0, utils_1.dateInputMask)(valueProp), defaultValue: (0, utils_1.dateInputMask)(defaultValue) }, other, { ref: (0, useMultiRef_1.useMultiRef)([ref]) })));
|
|
13
|
+
});
|
|
14
|
+
exports.DateInput.displayName = 'DateInput';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DateInput';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateInputMask = exports.isCompleted = void 0;
|
|
4
|
+
var isCompleted = function (value) { return value.length === 10; };
|
|
5
|
+
exports.isCompleted = isCompleted;
|
|
6
|
+
var dateInputMask = function (value) {
|
|
7
|
+
if (!value) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
var newValue = value.replace(/[^0-9.]/g, ''); // Запрещаем ввод, кроме цифр и точек
|
|
11
|
+
newValue = newValue.replace(/\.\.+/g, '..'); // Удаляем лишние точки
|
|
12
|
+
newValue = newValue.replace(/^(\d)\.$/g, '0$1.'); // Добавляем 0 в D.
|
|
13
|
+
newValue = newValue.replace(/^(\d\d)(\d)$/g, '$1.$2'); // Добавляем точку в DD.M
|
|
14
|
+
newValue = newValue.replace(/^(\d\d)\.(\d)\.$/g, '$1.0$2.'); // Добавляем 0 в DD.M.
|
|
15
|
+
newValue = newValue.replace(/^(\d\d\.\d\d)(\d)$/g, '$1.$2'); // Добавляем точку в DD.MM.Y
|
|
16
|
+
if (newValue.length > 10)
|
|
17
|
+
newValue = newValue.slice(0, 10); // Ограничиваем длину
|
|
18
|
+
return newValue;
|
|
19
|
+
};
|
|
20
|
+
exports.dateInputMask = dateInputMask;
|
package/__inner__/cjs/components/DatePicker/components/DateInput/utils/dateInputMask/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dateInputMask';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dateInputMask';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FC, MouseEvent } from 'react';
|
|
2
|
+
import type { DatePickerProps } from '../../index';
|
|
3
|
+
type AutocompleteRenderRightProps = {
|
|
4
|
+
onClear: (e: MouseEvent<HTMLElement>) => void;
|
|
5
|
+
hasValue: boolean;
|
|
6
|
+
} & Pick<DatePickerProps, 'clearText' | 'renderRight' | 'size' | 'open' | 'disableClearButton'>;
|
|
7
|
+
export declare const DatePickerRenderRight: FC<AutocompleteRenderRightProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatePickerRenderRight = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
var icons_1 = require("@ozen-ui/icons");
|
|
7
|
+
var FieldControl_1 = require("../../../FieldControl");
|
|
8
|
+
var FieldIcon_1 = require("../../../FieldIcon");
|
|
9
|
+
var IconButtonNext_1 = require("../../../IconButtonNext");
|
|
10
|
+
var index_1 = require("../../index");
|
|
11
|
+
var DatePickerRenderRight = function (_a) {
|
|
12
|
+
var disableClearButton = _a.disableClearButton, renderRight = _a.renderRight, clearText = _a.clearText, hasValue = _a.hasValue, onClear = _a.onClear, open = _a.open, size = _a.size;
|
|
13
|
+
var _b = tslib_1.__read((0, FieldControl_1.useFieldControl)(), 1), _c = _b[0], focused = _c.focused, hovered = _c.hovered;
|
|
14
|
+
var isVisibleClearButton = !!(hovered || open || focused) && hasValue;
|
|
15
|
+
var handleClear = function (e) {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
onClear === null || onClear === void 0 ? void 0 : onClear(e);
|
|
18
|
+
};
|
|
19
|
+
return (react_1.default.createElement("div", { className: (0, index_1.cnDatePicker)('RenderRight') },
|
|
20
|
+
!disableClearButton && (react_1.default.createElement(IconButtonNext_1.IconButton, { size: size, type: "button", tabIndex: -1, icon: icons_1.CrossIcon, title: clearText, variant: "function", onClick: handleClear, "aria-label": clearText, className: (0, index_1.cnDatePicker)('ClearButton', {
|
|
21
|
+
visibility: isVisibleClearButton,
|
|
22
|
+
}), compressed: true })),
|
|
23
|
+
react_1.default.createElement(FieldIcon_1.FieldIcon, { icon: renderRight }),
|
|
24
|
+
react_1.default.createElement(FieldIcon_1.FieldIcon, { icon: icons_1.CalendarIcon, size: size })));
|
|
25
|
+
};
|
|
26
|
+
exports.DatePickerRenderRight = DatePickerRenderRight;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DatePickerRenderRight';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DATE_PICKER_DEFAULT_SIZE = "m";
|