@ozen-ui/kit 0.34.0 → 0.34.2

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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../__inner__/cjs/components/Calendar/index.js",
3
+ "module": "../__inner__/esm/components/Calendar/index.js",
4
+ "types": "../__inner__/esm/components/Calendar/index.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../__inner__/cjs/components/DatePicker/index.js",
3
+ "module": "../__inner__/esm/components/DatePicker/index.js",
4
+ "types": "../__inner__/esm/components/DatePicker/index.d.ts"
5
+ }
@@ -20,7 +20,7 @@ function AutocompleteRender(inProps, ref) {
20
20
  props: inProps,
21
21
  name: 'Autocomplete',
22
22
  });
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, 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", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
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
24
  var anchorRef = (0, react_1.useRef)(null);
25
25
  var _o = tslib_1.__read((0, useControlled_1.useControlled)({
26
26
  value: inputValueProp,
@@ -49,7 +49,7 @@ function AutocompleteRender(inProps, ref) {
49
49
  var savedGetOptionLabel = (0, useMutableRef_1.useMutableRef)(getOptionLabel);
50
50
  var _r = tslib_1.__read((0, react_1.useState)(tslib_1.__spreadArray([], tslib_1.__read(options), false)), 2), filteredOptions = _r[0], setFilteredOptions = _r[1];
51
51
  var searchFunction = searchFunctionProp || searchFunctionDefault;
52
- var dataListValue = valueState ? getOptionLabel(valueState) : '';
52
+ var dataListValue = valueState ? getOptionKey(valueState) : '';
53
53
  var hasOptions = !!(filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length);
54
54
  var showNoOptions = !hasOptions && !loading;
55
55
  var showLoading = !hasOptions && !!loading;
@@ -163,7 +163,7 @@ function AutocompleteRender(inProps, ref) {
163
163
  /** Событие выбора значения из раскрывающегося списка */
164
164
  var handleChangeDataList = function (event, _a) {
165
165
  var value = _a.value;
166
- var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option)) === value; });
166
+ 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
167
  if (selectedOption) {
168
168
  var newInputValue = getOptionLabel(selectedOption);
169
169
  setValueState(selectedOption);
@@ -177,17 +177,17 @@ function AutocompleteRender(inProps, ref) {
177
177
  }
178
178
  };
179
179
  /** Отображение текстового поля */
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: onClear, onOpen: handleToggle, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: tslib_1.__assign(tslib_1.__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: (0, exports.cnAutocomplete)({ size: size, hasChevron: !disableShowChevron }, [
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: onClear, onOpen: handleToggle, renderRight: renderRight, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: tslib_1.__assign(tslib_1.__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: (0, exports.cnAutocomplete)({ size: size, hasChevron: !disableShowChevron }, [
181
181
  className,
182
182
  ]), ref: ref }));
183
183
  /** Отображение опций */
184
184
  var renderOptions = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map(function (option) {
185
185
  var selected = valueState
186
- ? getOptionLabel(valueState) === getOptionLabel(option)
186
+ ? getOptionKey(valueState) === getOptionKey(option)
187
187
  : false;
188
188
  var renderOptionDefault = function (_a) {
189
- var option = _a.option, selected = _a.selected;
190
- return (react_1.default.createElement(DataList_1.DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option), selected: selected }));
189
+ var option = _a.option;
190
+ return (react_1.default.createElement(DataList_1.DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option) }));
191
191
  };
192
192
  var renderOption = renderOptionProp || renderOptionDefault;
193
193
  return renderOption({ option: option, selected: selected });
@@ -5,6 +5,6 @@ type AutocompleteRenderRightProps = {
5
5
  onOpen: () => void;
6
6
  onClear: (e: React.MouseEvent<HTMLElement>) => void;
7
7
  hasValue: boolean;
8
- } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron'>;
8
+ } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron' | 'renderRight'>;
9
9
  export declare const AutocompleteRenderRight: FC<AutocompleteRenderRightProps>;
10
10
  export {};
@@ -5,10 +5,11 @@ var tslib_1 = require("tslib");
5
5
  var react_1 = tslib_1.__importDefault(require("react"));
6
6
  var icons_1 = require("@ozen-ui/icons");
7
7
  var FieldControl_1 = require("../../../FieldControl");
8
+ var FieldIcon_1 = require("../../../FieldIcon");
8
9
  var IconButton_1 = require("../../../IconButton");
9
10
  var index_1 = require("../../index");
10
11
  var AutocompleteRenderRight = function (_a) {
11
- var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
12
+ var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, renderRight = _a.renderRight, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
12
13
  var _b = tslib_1.__read((0, FieldControl_1.useFieldControl)(), 1), _c = _b[0], focused = _c.focused, hovered = _c.hovered;
13
14
  var isVisibleClearButton = !!(hovered || open || focused) && hasValue;
14
15
  return (react_1.default.createElement("div", { className: (0, index_1.cnAutocomplete)('RenderRight') },
@@ -18,6 +19,7 @@ var AutocompleteRenderRight = function (_a) {
18
19
  }, className: (0, index_1.cnAutocomplete)('ClearButton', {
19
20
  visibility: isVisibleClearButton,
20
21
  }), title: clearText, "aria-label": clearText, size: size, icon: icons_1.CloseIcon, compressed: true })),
22
+ react_1.default.createElement(FieldIcon_1.FieldIcon, { icon: renderRight }),
21
23
  !disableShowChevron && (react_1.default.createElement(IconButton_1.IconButton, { type: "button", variant: "ghost", tabIndex: -1, onClick: function (e) {
22
24
  e.preventDefault();
23
25
  onOpen();
@@ -30,7 +30,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
30
30
  searchFunction?: import("./types").AutocompleteSearchFunction<OPTION> | undefined;
31
31
  disableShowEmptyOptionsList?: boolean | undefined;
32
32
  disableShowChevron?: boolean | undefined;
33
- dataListProps?: Partial<Omit<import("../DataList").DataListBaseProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
33
+ dataListProps?: Partial<Omit<import("../DataList").DataListProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
34
34
  } & {
35
35
  label?: string | undefined;
36
36
  style?: import("react").CSSProperties | undefined;
@@ -59,6 +59,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
59
59
  } & {
60
60
  size?: import("@ozen-ui/icons").IconSize | undefined;
61
61
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
63
+ color?: string | undefined;
64
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
65
+ } & {
66
+ size?: import("@ozen-ui/icons").IconSize | undefined;
67
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
68
+ color?: string | undefined;
69
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
70
+ } & {
71
+ size?: import("@ozen-ui/icons").IconSize | undefined;
72
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
73
+ color?: string | undefined;
74
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
75
+ } & {
76
+ size?: import("@ozen-ui/icons").IconSize | undefined;
77
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
78
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
63
79
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
64
80
  } & {
@@ -76,7 +92,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
76
92
  } ? Record<string, unknown> : {
77
93
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
78
94
  }) & (OPTION extends {
79
- id: boolean | undefined;
95
+ disabled: boolean | undefined;
80
96
  } ? Record<string, unknown> : {
81
97
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
82
98
  }) & {
@@ -110,7 +126,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
110
126
  searchFunction?: import("./types").AutocompleteSearchFunction<OPTION> | undefined;
111
127
  disableShowEmptyOptionsList?: boolean | undefined;
112
128
  disableShowChevron?: boolean | undefined;
113
- dataListProps?: Partial<Omit<import("../DataList").DataListBaseProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
129
+ dataListProps?: Partial<Omit<import("../DataList").DataListProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
114
130
  } & {
115
131
  label?: string | undefined;
116
132
  style?: import("react").CSSProperties | undefined;
@@ -139,6 +155,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
139
155
  } & {
140
156
  size?: import("@ozen-ui/icons").IconSize | undefined;
141
157
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
158
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
159
+ color?: string | undefined;
160
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
161
+ } & {
162
+ size?: import("@ozen-ui/icons").IconSize | undefined;
163
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
164
+ color?: string | undefined;
165
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
166
+ } & {
167
+ size?: import("@ozen-ui/icons").IconSize | undefined;
168
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
169
+ color?: string | undefined;
170
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
171
+ } & {
172
+ size?: import("@ozen-ui/icons").IconSize | undefined;
173
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
142
174
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
143
175
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
144
176
  } & {
@@ -156,7 +188,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
156
188
  } ? Record<string, unknown> : {
157
189
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
158
190
  }) & (OPTION extends {
159
- id: boolean | undefined;
191
+ disabled: boolean | undefined;
160
192
  } ? Record<string, unknown> : {
161
193
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
162
194
  }) & {
@@ -1,6 +1,6 @@
1
1
  import type { SyntheticEvent, ChangeEvent, ReactElement, ReactNode } from 'react';
2
2
  import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
3
- import type { DataListBaseProps } from '../DataList';
3
+ import type { DataListProps } from '../DataList';
4
4
  import type { InputProps } from '../Input';
5
5
  export type AutocompleteRenderOptionProps<OPTION> = {
6
6
  option: OPTION;
@@ -31,8 +31,8 @@ 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' | 'className' | 'inputProps' | 'onKeyDown'>;
35
- type AutocompleteDataListProps = Partial<Omit<DataListBaseProps, 'onClose' | 'open' | 'anchorRef' | 'multiple' | 'selected' | 'onSelect'>>;
34
+ type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'renderRight' | 'className' | 'inputProps' | 'onKeyDown'>;
35
+ type AutocompleteDataListProps = Partial<Omit<DataListProps, 'onClose' | 'open' | 'anchorRef' | 'multiple' | 'selected' | 'onSelect'>>;
36
36
  export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
37
37
  /** Список вариантов выбора (опции) */
38
38
  options: OPTION[];
@@ -97,7 +97,7 @@ export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
97
97
  } ? Record<string, unknown> : {
98
98
  getOptionKey?: AutocompletePropGetOptionKey<OPTION>;
99
99
  }) & (OPTION extends {
100
- id: AutocompleteDefaultOption['disabled'];
100
+ disabled: AutocompleteDefaultOption['disabled'];
101
101
  } ? Record<string, unknown> : {
102
102
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION>;
103
103
  });
@@ -5,14 +5,15 @@ var tslib_1 = require("tslib");
5
5
  require("./DataList.css");
6
6
  var react_1 = tslib_1.__importStar(require("react"));
7
7
  var react_is_1 = require("react-is");
8
- var useBoolean_1 = require("../../hooks/useBoolean");
9
8
  var useControlled_1 = require("../../hooks/useControlled");
10
9
  var useEventListener_1 = require("../../hooks/useEventListener");
11
10
  var useMultiRef_1 = require("../../hooks/useMultiRef");
11
+ var usePrevious_1 = require("../../hooks/usePrevious");
12
12
  var useThemeProps_1 = require("../../hooks/useThemeProps");
13
13
  var classname_1 = require("../../utils/classname");
14
14
  var isKey_1 = require("../../utils/isKey");
15
15
  var polymorphicComponentWithRef_1 = require("../../utils/polymorphicComponentWithRef");
16
+ var scrollContainerToElement_1 = require("../../utils/scrollContainerToElement");
16
17
  var List_1 = require("../List");
17
18
  var Popover_1 = require("../Popover");
18
19
  var constants_1 = require("./constants");
@@ -20,17 +21,15 @@ var helpers_1 = require("./helpers");
20
21
  var index_1 = require("./index");
21
22
  exports.cnDataList = (0, classname_1.cn)('DataList');
22
23
  var DataListRender = function (inProps, ref) {
23
- var _a = (0, useThemeProps_1.useThemeProps)({ props: inProps, name: 'DataList' }), _b = _a.open, open = _b === void 0 ? constants_1.DATA_LIST_DEFAULT_OPEN : _b, _c = _a.size, size = _c === void 0 ? constants_1.DATA_LIST_DEFAULT_SIZE : _c, _d = _a.as, as = _d === void 0 ? constants_1.DATA_LIST_DEFAULT_TAG : _d, name = _a.name, children = _a.children, anchorRef = _a.anchorRef, selectedProp = _a.selected, defaultSelected = _a.defaultSelected, onClose = _a.onClose, onEnteredProp = _a.onEntered, onExitedProp = _a.onExited, listProps = _a.listProps, className = _a.className, other = tslib_1.__rest(_a, ["open", "size", "as", "name", "children", "anchorRef", "selected", "defaultSelected", "onClose", "onEntered", "onExited", "listProps", "className"]);
24
+ var _a = (0, useThemeProps_1.useThemeProps)({ props: inProps, name: 'DataList' }), _b = _a.open, open = _b === void 0 ? constants_1.DATA_LIST_DEFAULT_OPEN : _b, _c = _a.size, size = _c === void 0 ? constants_1.DATA_LIST_DEFAULT_SIZE : _c, _d = _a.as, as = _d === void 0 ? constants_1.DATA_LIST_DEFAULT_TAG : _d, name = _a.name, children = _a.children, anchorRef = _a.anchorRef, selectedProp = _a.selected, defaultSelected = _a.defaultSelected, onClose = _a.onClose, listProps = _a.listProps, className = _a.className, other = tslib_1.__rest(_a, ["open", "size", "as", "name", "children", "anchorRef", "selected", "defaultSelected", "onClose", "listProps", "className"]);
24
25
  var dataListRef = (0, react_1.useRef)(null);
25
26
  var listRef = (0, react_1.useRef)(null);
26
- // Состояние представленного компонента с завершенной анимацией
27
- var _e = tslib_1.__read((0, useBoolean_1.useBoolean)(false), 2), opened = _e[0], _f = _e[1], onEntered = _f.on, onExited = _f.off;
28
- var _g = tslib_1.__read((0, useControlled_1.useControlled)({
27
+ var _e = tslib_1.__read((0, useControlled_1.useControlled)({
29
28
  name: 'DataList',
30
29
  defaultValue: defaultSelected,
31
30
  value: selectedProp,
32
31
  state: 'selected',
33
- }), 2), selectedState = _g[0], setSelected = _g[1];
32
+ }), 2), selectedState = _e[0], setSelected = _e[1];
34
33
  var nodes = (0, react_1.useMemo)(function () { return new Map(); }, [children]);
35
34
  var items = (0, react_1.useMemo)(function () { return new Array(); }, [children]);
36
35
  var resolvedChildren = (0, react_is_1.isFragment)(children)
@@ -70,29 +69,42 @@ var DataListRender = function (inProps, ref) {
70
69
  setSelected_2(value);
71
70
  }
72
71
  };
72
+ var handleOnMouseDownList = function (e) {
73
+ var _a;
74
+ e.preventDefault();
75
+ (_a = listProps === null || listProps === void 0 ? void 0 : listProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(listProps, e);
76
+ };
73
77
  // Навигация по списку
74
- var _h = (0, helpers_1.useDataListNavigation)({
75
- active: opened,
78
+ var _f = (0, helpers_1.useDataListNavigation)({
79
+ active: open,
76
80
  items: items,
77
81
  selected: (0, helpers_1.lastSelectedValue)(selectedState),
78
82
  onSelect: function (event, item) {
79
- handleSelect(event, item || '');
83
+ handleSelect(event, item !== null && item !== void 0 ? item : '');
80
84
  },
81
- }), current = _h.current, focused = _h.focused, onKeyDown = _h.onKeyDown, onClick = _h.onClick;
82
- var _j = tslib_1.__read((0, react_1.useState)({ current: null }), 2), selectedElRef = _j[0], setSelectedElRef = _j[1];
85
+ }), current = _f.current, focused = _f.focused, onKeyDown = _f.onKeyDown, onClick = _f.onClick;
86
+ var previousCurrent = (0, usePrevious_1.usePrevious)(current);
83
87
  (0, react_1.useEffect)(function () {
84
88
  var _a, _b;
85
- var selected = focused || current || '';
89
+ var firstCurrent = (previousCurrent === null || previousCurrent === undefined) &&
90
+ current !== null &&
91
+ current !== undefined
92
+ ? current
93
+ : undefined;
94
+ var selected = focused !== null && focused !== void 0 ? focused : firstCurrent;
86
95
  // Находит элемент по ключу
87
- var idx = nodes.get(selected);
96
+ var idx = selected !== undefined && selected !== null
97
+ ? nodes.get(selected)
98
+ : undefined;
88
99
  if (idx !== undefined) {
89
- setSelectedElRef({
90
- current: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
100
+ // Прокрутка списка
101
+ (0, scrollContainerToElement_1.scrollContainerToElement)({
102
+ container: dataListRef.current,
103
+ element: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
104
+ behavior: focused !== undefined && focused !== null ? 'smooth' : 'instant',
91
105
  });
92
106
  }
93
- }, [focused, current]);
94
- // Прокрутка списка
95
- (0, helpers_1.useScrollContainerToElement)(dataListRef, selectedElRef, focused ? 'smooth' : 'instant');
107
+ }, [focused, current, previousCurrent]);
96
108
  // Назначает элементу контроля событие управления списком с клавиатуры
97
109
  (0, useEventListener_1.useEventListener)({
98
110
  eventName: 'keydown',
@@ -136,17 +148,7 @@ var DataListRender = function (inProps, ref) {
136
148
  }, [resolvedChildren, selectedState, focused, onClick]);
137
149
  return (react_1.default.createElement(Popover_1.Popover, tslib_1.__assign({ as: as, open: open, placement: "bottom-start", strategy: "absolute", disableReturnFocus: true, disableEnforceFocus: true, offset: [0, 4], onClose: onClose, anchorRef: anchorRef, className: (0, exports.cnDataList)('', [className]), transitionProps: {
138
150
  classNames: 'DataList-animation',
139
- } }, other, { onEntered: function () {
140
- onEntered();
141
- onEnteredProp === null || onEnteredProp === void 0 ? void 0 : onEnteredProp();
142
- }, onExited: function () {
143
- onExited();
144
- onExitedProp === null || onExitedProp === void 0 ? void 0 : onExitedProp();
145
- }, ref: (0, useMultiRef_1.useMultiRef)([ref, dataListRef]) }),
146
- react_1.default.createElement(List_1.List, tslib_1.__assign({ as: "ul", size: size }, listProps, { onMouseDown: function (e) {
147
- var _a;
148
- e.preventDefault();
149
- (_a = listProps === null || listProps === void 0 ? void 0 : listProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(listProps, e);
150
- }, ref: (0, useMultiRef_1.useMultiRef)([listRef, listProps === null || listProps === void 0 ? void 0 : listProps.ref]) }), renderChildren)));
151
+ } }, other, { ref: (0, useMultiRef_1.useMultiRef)([ref, dataListRef]) }),
152
+ react_1.default.createElement(List_1.List, tslib_1.__assign({ as: "ul", size: size }, listProps, { onMouseDown: handleOnMouseDownList, ref: (0, useMultiRef_1.useMultiRef)([listRef, listProps === null || listProps === void 0 ? void 0 : listProps.ref]) }), renderChildren)));
151
153
  };
152
154
  exports.DataList = (0, polymorphicComponentWithRef_1.polymorphicComponentWithRef)(DataListRender);
@@ -17,7 +17,7 @@ function AutocompleteRender(inProps, ref) {
17
17
  props: inProps,
18
18
  name: 'Autocomplete',
19
19
  });
20
- var _a = withDefaultGetters(props), _b = _a.disabled, disabled = _b === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return React.createElement(Input, __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, 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 = __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", "hint", "getOptionKey", "getOptionLabel", "getOptionDisabled", "dataListProps", "onClose", "onOpen", "open", "defaultOpen", "loading", "inputProps", "onKeyDown", "noOptionsText", "clearText", "openText", "loadingText", "closeText"]);
20
+ var _a = withDefaultGetters(props), _b = _a.disabled, disabled = _b === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLED : _b, _c = _a.required, required = _c === void 0 ? AUTOCOMPLETE_DEFAULT_REQUIRED : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? AUTOCOMPLETE_DEFAULT_AUTOFOCUS : _d, _e = _a.fullWidth, fullWidth = _e === void 0 ? AUTOCOMPLETE_DEFAULT_FULLWIDTH : _e, _f = _a.size, size = _f === void 0 ? AUTOCOMPLETE_DEFAULT_SIZE : _f, _g = _a.allowCustomValue, allowCustomValue = _g === void 0 ? AUTOCOMPLETE_DEFAULT_ALLOW_CUSTOM_VALUE : _g, _h = _a.disableShowChevron, disableShowChevron = _h === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_CHEVRON : _h, _j = _a.disableClearButton, disableClearButton = _j === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLEAR_BUTTON : _j, _k = _a.disableShowEmptyOptionsList, disableShowEmptyOptionsList = _k === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_SHOW_EMPTY_OPTIONS_LIST : _k, _l = _a.disableCloseOnSelect, disableCloseOnSelect = _l === void 0 ? AUTOCOMPLETE_DEFAULT_DISABLE_CLOSE_ON_SELECT : _l, _m = _a.renderInput, renderInput = _m === void 0 ? function (props) { return React.createElement(Input, __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 = __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"]);
21
21
  var anchorRef = useRef(null);
22
22
  var _o = __read(useControlled({
23
23
  value: inputValueProp,
@@ -46,7 +46,7 @@ function AutocompleteRender(inProps, ref) {
46
46
  var savedGetOptionLabel = useMutableRef(getOptionLabel);
47
47
  var _r = __read(useState(__spreadArray([], __read(options), false)), 2), filteredOptions = _r[0], setFilteredOptions = _r[1];
48
48
  var searchFunction = searchFunctionProp || searchFunctionDefault;
49
- var dataListValue = valueState ? getOptionLabel(valueState) : '';
49
+ var dataListValue = valueState ? getOptionKey(valueState) : '';
50
50
  var hasOptions = !!(filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length);
51
51
  var showNoOptions = !hasOptions && !loading;
52
52
  var showLoading = !hasOptions && !!loading;
@@ -160,7 +160,7 @@ function AutocompleteRender(inProps, ref) {
160
160
  /** Событие выбора значения из раскрывающегося списка */
161
161
  var handleChangeDataList = function (event, _a) {
162
162
  var value = _a.value;
163
- var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option)) === value; });
163
+ var selectedOption = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.find(function (option) { return (getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option)) === value; });
164
164
  if (selectedOption) {
165
165
  var newInputValue = getOptionLabel(selectedOption);
166
166
  setValueState(selectedOption);
@@ -174,17 +174,17 @@ function AutocompleteRender(inProps, ref) {
174
174
  }
175
175
  };
176
176
  /** Отображение текстового поля */
177
- var input = renderInput(__assign(__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (React.createElement(AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear: onClear, onOpen: handleToggle, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: __assign(__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: cnAutocomplete({ size: size, hasChevron: !disableShowChevron }, [
177
+ var input = renderInput(__assign(__assign({ size: size, hint: hint, disabled: disabled, label: label, required: required, error: error, fullWidth: fullWidth, placeholder: placeholder, renderLeft: renderLeft }, other), { renderRight: (React.createElement(AutocompleteRenderRight, { open: open, size: size, disabled: disabled, clearText: clearText, closeText: closeText, openText: openText, hasValue: !!inputValue, onClear: onClear, onOpen: handleToggle, renderRight: renderRight, disableShowChevron: disableShowChevron, disableClearButton: disableClearButton })), onChange: handleChangeInput, onKeyDown: handleKeyDown, value: inputValue || '', inputProps: __assign(__assign({}, inputProps), { onBlur: onBlur, onClick: handleClickOnInput }), bodyProps: { ref: anchorRef, 'aria-expanded': open }, className: cnAutocomplete({ size: size, hasChevron: !disableShowChevron }, [
178
178
  className,
179
179
  ]), ref: ref }));
180
180
  /** Отображение опций */
181
181
  var renderOptions = filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map(function (option) {
182
182
  var selected = valueState
183
- ? getOptionLabel(valueState) === getOptionLabel(option)
183
+ ? getOptionKey(valueState) === getOptionKey(option)
184
184
  : false;
185
185
  var renderOptionDefault = function (_a) {
186
- var option = _a.option, selected = _a.selected;
187
- return (React.createElement(DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option), selected: selected }));
186
+ var option = _a.option;
187
+ return (React.createElement(DataListOption, { key: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), label: getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option), value: getOptionKey === null || getOptionKey === void 0 ? void 0 : getOptionKey(option), disabled: getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(option) }));
188
188
  };
189
189
  var renderOption = renderOptionProp || renderOptionDefault;
190
190
  return renderOption({ option: option, selected: selected });
@@ -5,6 +5,6 @@ type AutocompleteRenderRightProps = {
5
5
  onOpen: () => void;
6
6
  onClear: (e: React.MouseEvent<HTMLElement>) => void;
7
7
  hasValue: boolean;
8
- } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron'>;
8
+ } & Pick<AutocompleteProps, 'clearText' | 'closeText' | 'openText' | 'size' | 'disabled' | 'open' | 'disableClearButton' | 'disableShowChevron' | 'renderRight'>;
9
9
  export declare const AutocompleteRenderRight: FC<AutocompleteRenderRightProps>;
10
10
  export {};
@@ -2,10 +2,11 @@ import { __read } from "tslib";
2
2
  import React from 'react';
3
3
  import { ChevronDownIcon, ChevronUpIcon, CloseIcon } from '@ozen-ui/icons';
4
4
  import { useFieldControl } from '../../../FieldControl';
5
+ import { FieldIcon } from '../../../FieldIcon';
5
6
  import { IconButton } from '../../../IconButton';
6
7
  import { cnAutocomplete } from '../../index';
7
8
  export var AutocompleteRenderRight = function (_a) {
8
- var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
9
+ var disableClearButton = _a.disableClearButton, disableShowChevron = _a.disableShowChevron, renderRight = _a.renderRight, clearText = _a.clearText, closeText = _a.closeText, openText = _a.openText, disabled = _a.disabled, hasValue = _a.hasValue, onClear = _a.onClear, onOpen = _a.onOpen, open = _a.open, size = _a.size;
9
10
  var _b = __read(useFieldControl(), 1), _c = _b[0], focused = _c.focused, hovered = _c.hovered;
10
11
  var isVisibleClearButton = !!(hovered || open || focused) && hasValue;
11
12
  return (React.createElement("div", { className: cnAutocomplete('RenderRight') },
@@ -15,6 +16,7 @@ export var AutocompleteRenderRight = function (_a) {
15
16
  }, className: cnAutocomplete('ClearButton', {
16
17
  visibility: isVisibleClearButton,
17
18
  }), title: clearText, "aria-label": clearText, size: size, icon: CloseIcon, compressed: true })),
19
+ React.createElement(FieldIcon, { icon: renderRight }),
18
20
  !disableShowChevron && (React.createElement(IconButton, { type: "button", variant: "ghost", tabIndex: -1, onClick: function (e) {
19
21
  e.preventDefault();
20
22
  onOpen();
@@ -30,7 +30,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
30
30
  searchFunction?: import("./types").AutocompleteSearchFunction<OPTION> | undefined;
31
31
  disableShowEmptyOptionsList?: boolean | undefined;
32
32
  disableShowChevron?: boolean | undefined;
33
- dataListProps?: Partial<Omit<import("../DataList").DataListBaseProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
33
+ dataListProps?: Partial<Omit<import("../DataList").DataListProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
34
34
  } & {
35
35
  label?: string | undefined;
36
36
  style?: import("react").CSSProperties | undefined;
@@ -59,6 +59,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
59
59
  } & {
60
60
  size?: import("@ozen-ui/icons").IconSize | undefined;
61
61
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
63
+ color?: string | undefined;
64
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
65
+ } & {
66
+ size?: import("@ozen-ui/icons").IconSize | undefined;
67
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
68
+ color?: string | undefined;
69
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
70
+ } & {
71
+ size?: import("@ozen-ui/icons").IconSize | undefined;
72
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
73
+ color?: string | undefined;
74
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
75
+ } & {
76
+ size?: import("@ozen-ui/icons").IconSize | undefined;
77
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
62
78
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
63
79
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
64
80
  } & {
@@ -76,7 +92,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
76
92
  } ? Record<string, unknown> : {
77
93
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
78
94
  }) & (OPTION extends {
79
- id: boolean | undefined;
95
+ disabled: boolean | undefined;
80
96
  } ? Record<string, unknown> : {
81
97
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
82
98
  }) & {
@@ -110,7 +126,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
110
126
  searchFunction?: import("./types").AutocompleteSearchFunction<OPTION> | undefined;
111
127
  disableShowEmptyOptionsList?: boolean | undefined;
112
128
  disableShowChevron?: boolean | undefined;
113
- dataListProps?: Partial<Omit<import("../DataList").DataListBaseProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
129
+ dataListProps?: Partial<Omit<import("../DataList").DataListProps, "onSelect" | "open" | "onClose" | "multiple" | "selected" | "anchorRef">> | undefined;
114
130
  } & {
115
131
  label?: string | undefined;
116
132
  style?: import("react").CSSProperties | undefined;
@@ -139,6 +155,22 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
139
155
  } & {
140
156
  size?: import("@ozen-ui/icons").IconSize | undefined;
141
157
  }, string | import("react").JSXElementConstructor<any>>) | undefined;
158
+ renderRight?: string | number | import("react").FC<import("react").SVGProps<SVGSVGElement> & {
159
+ color?: string | undefined;
160
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
161
+ } & {
162
+ size?: import("@ozen-ui/icons").IconSize | undefined;
163
+ }> | import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
164
+ color?: string | undefined;
165
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
166
+ } & {
167
+ size?: import("@ozen-ui/icons").IconSize | undefined;
168
+ }, string | import("react").JSXElementConstructor<any>> | (() => import("react").ReactElement<import("react").SVGProps<SVGSVGElement> & {
169
+ color?: string | undefined;
170
+ ref?: import("react").Ref<SVGSVGElement> | undefined;
171
+ } & {
172
+ size?: import("@ozen-ui/icons").IconSize | undefined;
173
+ }, string | import("react").JSXElementConstructor<any>>) | undefined;
142
174
  inputProps?: (Omit<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & {
143
175
  ref?: ((instance: HTMLInputElement | null) => void) | import("react").RefObject<HTMLInputElement> | null | undefined;
144
176
  } & {
@@ -156,7 +188,7 @@ export declare function withDefaultGetters<OPTION>(props: AutocompleteProps<OPTI
156
188
  } ? Record<string, unknown> : {
157
189
  getOptionKey?: AutocompletePropGetOptionKey<OPTION> | undefined;
158
190
  }) & (OPTION extends {
159
- id: boolean | undefined;
191
+ disabled: boolean | undefined;
160
192
  } ? Record<string, unknown> : {
161
193
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION> | undefined;
162
194
  }) & {
@@ -1,6 +1,6 @@
1
1
  import type { SyntheticEvent, ChangeEvent, ReactElement, ReactNode } from 'react';
2
2
  import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
3
- import type { DataListBaseProps } from '../DataList';
3
+ import type { DataListProps } from '../DataList';
4
4
  import type { InputProps } from '../Input';
5
5
  export type AutocompleteRenderOptionProps<OPTION> = {
6
6
  option: OPTION;
@@ -31,8 +31,8 @@ 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' | 'className' | 'inputProps' | 'onKeyDown'>;
35
- type AutocompleteDataListProps = Partial<Omit<DataListBaseProps, 'onClose' | 'open' | 'anchorRef' | 'multiple' | 'selected' | 'onSelect'>>;
34
+ type AutocompleteInputProps = Pick<InputProps, 'placeholder' | 'autoFocus' | 'fullWidth' | 'disabled' | 'label' | 'required' | 'style' | 'error' | 'hint' | 'renderLeft' | 'renderRight' | 'className' | 'inputProps' | 'onKeyDown'>;
35
+ type AutocompleteDataListProps = Partial<Omit<DataListProps, 'onClose' | 'open' | 'anchorRef' | 'multiple' | 'selected' | 'onSelect'>>;
36
36
  export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
37
37
  /** Список вариантов выбора (опции) */
38
38
  options: OPTION[];
@@ -97,7 +97,7 @@ export type AutocompleteProps<OPTION = AutocompleteDefaultOption> = {
97
97
  } ? Record<string, unknown> : {
98
98
  getOptionKey?: AutocompletePropGetOptionKey<OPTION>;
99
99
  }) & (OPTION extends {
100
- id: AutocompleteDefaultOption['disabled'];
100
+ disabled: AutocompleteDefaultOption['disabled'];
101
101
  } ? Record<string, unknown> : {
102
102
  getOptionDisabled?: AutocompletePropGetOptionKey<OPTION>;
103
103
  });
@@ -1,33 +1,32 @@
1
1
  import { __assign, __read, __rest, __spreadArray } from "tslib";
2
2
  import './DataList.css';
3
- import React, { useMemo, Children, isValidElement, cloneElement, useRef, useEffect, useState, } from 'react';
3
+ import React, { useMemo, Children, isValidElement, cloneElement, useRef, useEffect, } from 'react';
4
4
  import { isFragment } from 'react-is';
5
- import { useBoolean } from '../../hooks/useBoolean';
6
5
  import { useControlled } from '../../hooks/useControlled';
7
6
  import { useEventListener } from '../../hooks/useEventListener';
8
7
  import { useMultiRef } from '../../hooks/useMultiRef';
8
+ import { usePrevious } from '../../hooks/usePrevious';
9
9
  import { useThemeProps } from '../../hooks/useThemeProps';
10
10
  import { cn } from '../../utils/classname';
11
11
  import { isKey } from '../../utils/isKey';
12
12
  import { polymorphicComponentWithRef } from '../../utils/polymorphicComponentWithRef';
13
+ import { scrollContainerToElement } from '../../utils/scrollContainerToElement';
13
14
  import { List } from '../List';
14
15
  import { Popover } from '../Popover';
15
16
  import { DATA_LIST_DEFAULT_SIZE, DATA_LIST_DEFAULT_OPEN, DATA_LIST_DEFAULT_TAG, } from './constants';
16
- import { lastSelectedValue, isMultipleParams, isNotMultipleParams, useDataListNavigation, useScrollContainerToElement, } from './helpers';
17
+ import { lastSelectedValue, isMultipleParams, isNotMultipleParams, useDataListNavigation, } from './helpers';
17
18
  import { DataListOption } from './index';
18
19
  export var cnDataList = cn('DataList');
19
20
  var DataListRender = function (inProps, ref) {
20
- var _a = useThemeProps({ props: inProps, name: 'DataList' }), _b = _a.open, open = _b === void 0 ? DATA_LIST_DEFAULT_OPEN : _b, _c = _a.size, size = _c === void 0 ? DATA_LIST_DEFAULT_SIZE : _c, _d = _a.as, as = _d === void 0 ? DATA_LIST_DEFAULT_TAG : _d, name = _a.name, children = _a.children, anchorRef = _a.anchorRef, selectedProp = _a.selected, defaultSelected = _a.defaultSelected, onClose = _a.onClose, onEnteredProp = _a.onEntered, onExitedProp = _a.onExited, listProps = _a.listProps, className = _a.className, other = __rest(_a, ["open", "size", "as", "name", "children", "anchorRef", "selected", "defaultSelected", "onClose", "onEntered", "onExited", "listProps", "className"]);
21
+ var _a = useThemeProps({ props: inProps, name: 'DataList' }), _b = _a.open, open = _b === void 0 ? DATA_LIST_DEFAULT_OPEN : _b, _c = _a.size, size = _c === void 0 ? DATA_LIST_DEFAULT_SIZE : _c, _d = _a.as, as = _d === void 0 ? DATA_LIST_DEFAULT_TAG : _d, name = _a.name, children = _a.children, anchorRef = _a.anchorRef, selectedProp = _a.selected, defaultSelected = _a.defaultSelected, onClose = _a.onClose, listProps = _a.listProps, className = _a.className, other = __rest(_a, ["open", "size", "as", "name", "children", "anchorRef", "selected", "defaultSelected", "onClose", "listProps", "className"]);
21
22
  var dataListRef = useRef(null);
22
23
  var listRef = useRef(null);
23
- // Состояние представленного компонента с завершенной анимацией
24
- var _e = __read(useBoolean(false), 2), opened = _e[0], _f = _e[1], onEntered = _f.on, onExited = _f.off;
25
- var _g = __read(useControlled({
24
+ var _e = __read(useControlled({
26
25
  name: 'DataList',
27
26
  defaultValue: defaultSelected,
28
27
  value: selectedProp,
29
28
  state: 'selected',
30
- }), 2), selectedState = _g[0], setSelected = _g[1];
29
+ }), 2), selectedState = _e[0], setSelected = _e[1];
31
30
  var nodes = useMemo(function () { return new Map(); }, [children]);
32
31
  var items = useMemo(function () { return new Array(); }, [children]);
33
32
  var resolvedChildren = isFragment(children)
@@ -67,29 +66,42 @@ var DataListRender = function (inProps, ref) {
67
66
  setSelected_2(value);
68
67
  }
69
68
  };
69
+ var handleOnMouseDownList = function (e) {
70
+ var _a;
71
+ e.preventDefault();
72
+ (_a = listProps === null || listProps === void 0 ? void 0 : listProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(listProps, e);
73
+ };
70
74
  // Навигация по списку
71
- var _h = useDataListNavigation({
72
- active: opened,
75
+ var _f = useDataListNavigation({
76
+ active: open,
73
77
  items: items,
74
78
  selected: lastSelectedValue(selectedState),
75
79
  onSelect: function (event, item) {
76
- handleSelect(event, item || '');
80
+ handleSelect(event, item !== null && item !== void 0 ? item : '');
77
81
  },
78
- }), current = _h.current, focused = _h.focused, onKeyDown = _h.onKeyDown, onClick = _h.onClick;
79
- var _j = __read(useState({ current: null }), 2), selectedElRef = _j[0], setSelectedElRef = _j[1];
82
+ }), current = _f.current, focused = _f.focused, onKeyDown = _f.onKeyDown, onClick = _f.onClick;
83
+ var previousCurrent = usePrevious(current);
80
84
  useEffect(function () {
81
85
  var _a, _b;
82
- var selected = focused || current || '';
86
+ var firstCurrent = (previousCurrent === null || previousCurrent === undefined) &&
87
+ current !== null &&
88
+ current !== undefined
89
+ ? current
90
+ : undefined;
91
+ var selected = focused !== null && focused !== void 0 ? focused : firstCurrent;
83
92
  // Находит элемент по ключу
84
- var idx = nodes.get(selected);
93
+ var idx = selected !== undefined && selected !== null
94
+ ? nodes.get(selected)
95
+ : undefined;
85
96
  if (idx !== undefined) {
86
- setSelectedElRef({
87
- current: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
97
+ // Прокрутка списка
98
+ scrollContainerToElement({
99
+ container: dataListRef.current,
100
+ element: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
101
+ behavior: focused !== undefined && focused !== null ? 'smooth' : 'instant',
88
102
  });
89
103
  }
90
- }, [focused, current]);
91
- // Прокрутка списка
92
- useScrollContainerToElement(dataListRef, selectedElRef, focused ? 'smooth' : 'instant');
104
+ }, [focused, current, previousCurrent]);
93
105
  // Назначает элементу контроля событие управления списком с клавиатуры
94
106
  useEventListener({
95
107
  eventName: 'keydown',
@@ -133,17 +145,7 @@ var DataListRender = function (inProps, ref) {
133
145
  }, [resolvedChildren, selectedState, focused, onClick]);
134
146
  return (React.createElement(Popover, __assign({ as: as, open: open, placement: "bottom-start", strategy: "absolute", disableReturnFocus: true, disableEnforceFocus: true, offset: [0, 4], onClose: onClose, anchorRef: anchorRef, className: cnDataList('', [className]), transitionProps: {
135
147
  classNames: 'DataList-animation',
136
- } }, other, { onEntered: function () {
137
- onEntered();
138
- onEnteredProp === null || onEnteredProp === void 0 ? void 0 : onEnteredProp();
139
- }, onExited: function () {
140
- onExited();
141
- onExitedProp === null || onExitedProp === void 0 ? void 0 : onExitedProp();
142
- }, ref: useMultiRef([ref, dataListRef]) }),
143
- React.createElement(List, __assign({ as: "ul", size: size }, listProps, { onMouseDown: function (e) {
144
- var _a;
145
- e.preventDefault();
146
- (_a = listProps === null || listProps === void 0 ? void 0 : listProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(listProps, e);
147
- }, ref: useMultiRef([listRef, listProps === null || listProps === void 0 ? void 0 : listProps.ref]) }), renderChildren)));
148
+ } }, other, { ref: useMultiRef([ref, dataListRef]) }),
149
+ React.createElement(List, __assign({ as: "ul", size: size }, listProps, { onMouseDown: handleOnMouseDownList, ref: useMultiRef([listRef, listProps === null || listProps === void 0 ? void 0 : listProps.ref]) }), renderChildren)));
148
150
  };
149
151
  export var DataList = polymorphicComponentWithRef(DataListRender);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ozen-ui/kit",
3
- "version": "0.34.0",
3
+ "version": "0.34.2",
4
4
  "description": "React component library",
5
5
  "files": [
6
6
  "*"