@ozen-ui/kit 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__inner__/cjs/components/DataList/DataList.css +55 -28
- package/__inner__/cjs/components/DataList/DataList.d.ts +2 -2
- package/__inner__/cjs/components/DataList/DataList.js +62 -24
- package/__inner__/cjs/components/DataList/DataListProvider.d.ts +8 -10
- package/__inner__/cjs/components/DataList/DataListProvider.js +0 -2
- package/__inner__/cjs/components/DataList/components/DataListOption.d.ts +5 -18
- package/__inner__/cjs/components/DataList/components/DataListOption.js +14 -22
- package/__inner__/cjs/components/DataList/types.d.ts +19 -12
- package/__inner__/cjs/components/DataList/types.js +5 -0
- package/__inner__/cjs/components/DataList/useDataListNavigation.d.ts +15 -6
- package/__inner__/cjs/components/DataList/useDataListNavigation.js +68 -21
- package/__inner__/cjs/components/Input/Input.js +5 -5
- package/__inner__/cjs/components/Input/types.d.ts +3 -3
- package/__inner__/cjs/components/InputNumber/InputNumber.js +10 -10
- package/__inner__/cjs/components/InputNumber/types.d.ts +2 -0
- package/__inner__/cjs/components/Textarea/types.d.ts +1 -3
- package/__inner__/cjs/hooks/useControlled/useControlled.js +3 -3
- package/__inner__/esm/components/DataList/DataList.css +55 -28
- package/__inner__/esm/components/DataList/DataList.d.ts +2 -2
- package/__inner__/esm/components/DataList/DataList.js +63 -25
- package/__inner__/esm/components/DataList/DataListProvider.d.ts +8 -10
- package/__inner__/esm/components/DataList/DataListProvider.js +0 -2
- package/__inner__/esm/components/DataList/components/DataListOption.d.ts +5 -18
- package/__inner__/esm/components/DataList/components/DataListOption.js +16 -23
- package/__inner__/esm/components/DataList/types.d.ts +19 -12
- package/__inner__/esm/components/DataList/types.js +2 -1
- package/__inner__/esm/components/DataList/useDataListNavigation.d.ts +15 -6
- package/__inner__/esm/components/DataList/useDataListNavigation.js +69 -22
- package/__inner__/esm/components/Input/Input.js +5 -5
- package/__inner__/esm/components/Input/types.d.ts +3 -3
- package/__inner__/esm/components/InputNumber/InputNumber.js +10 -10
- package/__inner__/esm/components/InputNumber/types.d.ts +2 -0
- package/__inner__/esm/components/Textarea/types.d.ts +1 -3
- package/__inner__/esm/hooks/useControlled/useControlled.js +3 -3
- package/package.json +1 -1
|
@@ -21,16 +21,16 @@ exports.Input = (0, react_1.forwardRef)(function (inProps, ref) {
|
|
|
21
21
|
props: inProps,
|
|
22
22
|
name: 'Input',
|
|
23
23
|
});
|
|
24
|
-
var _a = props.size, size = _a === void 0 ? constants_1.INPUT_DEFAULT_SIZE : _a, label = props.label, error = props.error, autoFocus = props.autoFocus, placeholder = props.placeholder, id = props.id, name = props.name, type = props.type, renderLeft = props.renderLeft, renderRight = props.renderRight, inputRef = props.inputRef, fullWidth = props.fullWidth, disabled = props.disabled, hint = props.hint, required = props.required, className = props.className, inputProps = props.inputProps, value = props.value, defaultValue = props.defaultValue, onChange = props.onChange, labelProps = props.labelProps, labelRef = props.labelRef, other = tslib_1.__rest(props, ["size", "label", "error", "autoFocus", "placeholder", "id", "name", "type", "renderLeft", "renderRight", "inputRef", "fullWidth", "disabled", "hint", "required", "className", "inputProps", "value", "defaultValue", "onChange", "labelProps", "labelRef"]);
|
|
25
|
-
var
|
|
24
|
+
var _a = props.size, size = _a === void 0 ? constants_1.INPUT_DEFAULT_SIZE : _a, label = props.label, error = props.error, autoFocus = props.autoFocus, placeholder = props.placeholder, id = props.id, name = props.name, type = props.type, renderLeft = props.renderLeft, renderRight = props.renderRight, inputRef = props.inputRef, fullWidth = props.fullWidth, disabled = props.disabled, hint = props.hint, required = props.required, className = props.className, inputProps = props.inputProps, value = props.value, defaultValue = props.defaultValue, onChange = props.onChange, labelProps = props.labelProps, labelRef = props.labelRef, bodyProps = props.bodyProps, other = tslib_1.__rest(props, ["size", "label", "error", "autoFocus", "placeholder", "id", "name", "type", "renderLeft", "renderRight", "inputRef", "fullWidth", "disabled", "hint", "required", "className", "inputProps", "value", "defaultValue", "onChange", "labelProps", "labelRef", "bodyProps"]);
|
|
25
|
+
var bodyInnerRef = (0, react_1.useRef)(null);
|
|
26
26
|
var fieldInnerRef = (0, react_1.useRef)(null);
|
|
27
27
|
/* Хук useEventListener необходим для того, чтобы при нажатии на кнопку мыши
|
|
28
|
-
* внутри HTML-элемента label
|
|
28
|
+
* внутри HTML-элемента label – фокус не переходил на body или на цель нажатия кнопки мыши.
|
|
29
29
|
* Если же нажатие кнопки происходит на самом HTML-элементе input, то мы ничего не делаем,
|
|
30
30
|
* так как в противном случае мы сломаем возможность выделять текст для копирования.
|
|
31
31
|
*/
|
|
32
32
|
(0, useEventListener_1.useEventListener)({
|
|
33
|
-
element:
|
|
33
|
+
element: bodyInnerRef,
|
|
34
34
|
eventName: 'mousedown',
|
|
35
35
|
handler: function (e) {
|
|
36
36
|
var _a;
|
|
@@ -41,7 +41,7 @@ exports.Input = (0, react_1.forwardRef)(function (inProps, ref) {
|
|
|
41
41
|
},
|
|
42
42
|
});
|
|
43
43
|
return (react_1.default.createElement(FieldControl_1.FieldControl, tslib_1.__assign({ size: size, error: error, disabled: disabled, required: required, fullWidth: fullWidth }, other, { ref: ref, className: (0, exports.cnInput)({}, [className]) }),
|
|
44
|
-
react_1.default.createElement("label", { className: (0, exports.cnInput)('Body'), ref:
|
|
44
|
+
react_1.default.createElement("label", tslib_1.__assign({}, bodyProps, { className: (0, exports.cnInput)('Body'), ref: (0, useMultiRef_1.useMultiRef)([bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.ref, bodyInnerRef]) }),
|
|
45
45
|
react_1.default.createElement(FieldIcon_1.FieldIcon, { icon: renderLeft }),
|
|
46
46
|
react_1.default.createElement("div", { className: (0, exports.cnInput)('FieldContainer') },
|
|
47
47
|
react_1.default.createElement(FieldLabel_1.FieldLabel, tslib_1.__assign({}, labelProps, { ref: labelRef || (labelProps === null || labelProps === void 0 ? void 0 : labelProps.ref), className: labelProps === null || labelProps === void 0 ? void 0 : labelProps.className }), label),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentPropsWithRef,
|
|
1
|
+
import type { ComponentPropsWithRef, Ref } from 'react';
|
|
2
2
|
import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
|
|
3
3
|
import type { FIELD_CONTROL_DEFAULT_TAG } from '../FieldControl';
|
|
4
4
|
import type { FieldIconProps } from '../FieldIcon';
|
|
@@ -63,8 +63,8 @@ export type InputProps = Omit<ComponentPropsWithRef<typeof FIELD_CONTROL_DEFAULT
|
|
|
63
63
|
};
|
|
64
64
|
/** Свойства FieldLabel */
|
|
65
65
|
labelProps?: FieldLabelProps;
|
|
66
|
-
/**
|
|
67
|
-
|
|
66
|
+
/** Cвойства Body */
|
|
67
|
+
bodyProps?: ComponentPropsWithRef<'label'>;
|
|
68
68
|
/** data-атрибут для тестирования */
|
|
69
69
|
'data-testid'?: string;
|
|
70
70
|
} & InputPropsDeprecated;
|
|
@@ -24,7 +24,7 @@ exports.InputNumber = (0, react_1.forwardRef)(function (inProps, ref) {
|
|
|
24
24
|
props: inProps,
|
|
25
25
|
name: 'InputNumber',
|
|
26
26
|
});
|
|
27
|
-
var _a = props.size, size = _a === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_SIZE : _a, _b = props.step, step = _b === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_STEP : _b, _c = props.autoFocus, autoFocus = _c === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_AUTO_FOCUS : _c, _d = props.error, error = _d === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_ERROR : _d, _e = props.required, required = _e === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_REQUIRED : _e, _f = props.disabled, disabled = _f === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_DISABLED : _f, _g = props.fullWidth, fullWidth = _g === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_FULL_WIDTH : _g, _h = props.defaultValue, defaultValue = _h === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_VALUE : _h, _j = props.min, min = _j === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_MIN : _j, _k = props.max, max = _k === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_MAX : _k, label = props.label, placeholder = props.placeholder, id = props.id, name = props.name, renderLeft = props.renderLeft, renderRight = props.renderRight, hint = props.hint, className = props.className, inputProps = props.inputProps, valueProp = props.value, onChange = props.onChange, labelRef = props.labelRef, labelProps = props.labelProps, other = tslib_1.__rest(props, ["size", "step", "autoFocus", "error", "required", "disabled", "fullWidth", "defaultValue", "min", "max", "label", "placeholder", "id", "name", "renderLeft", "renderRight", "hint", "className", "inputProps", "value", "onChange", "labelRef", "labelProps"]);
|
|
27
|
+
var _a = props.size, size = _a === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_SIZE : _a, _b = props.step, step = _b === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_STEP : _b, _c = props.autoFocus, autoFocus = _c === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_AUTO_FOCUS : _c, _d = props.error, error = _d === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_ERROR : _d, _e = props.required, required = _e === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_REQUIRED : _e, _f = props.disabled, disabled = _f === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_DISABLED : _f, _g = props.fullWidth, fullWidth = _g === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_FULL_WIDTH : _g, _h = props.defaultValue, defaultValue = _h === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_VALUE : _h, _j = props.min, min = _j === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_MIN : _j, _k = props.max, max = _k === void 0 ? constants_1.INPUT_NUMBER_DEFAULT_MAX : _k, label = props.label, placeholder = props.placeholder, id = props.id, name = props.name, renderLeft = props.renderLeft, renderRight = props.renderRight, hint = props.hint, className = props.className, inputProps = props.inputProps, valueProp = props.value, onChange = props.onChange, labelRef = props.labelRef, labelProps = props.labelProps, bodyProps = props.bodyProps, other = tslib_1.__rest(props, ["size", "step", "autoFocus", "error", "required", "disabled", "fullWidth", "defaultValue", "min", "max", "label", "placeholder", "id", "name", "renderLeft", "renderRight", "hint", "className", "inputProps", "value", "onChange", "labelRef", "labelProps", "bodyProps"]);
|
|
28
28
|
var _l = tslib_1.__read((0, react_1.useState)(false), 2), focused = _l[0], setFocused = _l[1];
|
|
29
29
|
var _m = tslib_1.__read((0, react_1.useState)(null), 2), timeoutId = _m[0], setTimeoutId = _m[1];
|
|
30
30
|
var _o = tslib_1.__read((0, react_1.useState)(null), 2), countDirection = _o[0], setCountDirection = _o[1];
|
|
@@ -34,8 +34,8 @@ exports.InputNumber = (0, react_1.forwardRef)(function (inProps, ref) {
|
|
|
34
34
|
state: 'value',
|
|
35
35
|
defaultValue: defaultValue,
|
|
36
36
|
}), 2), valueState = _p[0], setValueState = _p[1];
|
|
37
|
-
var
|
|
38
|
-
var
|
|
37
|
+
var bodyInnerRef = (0, react_1.useRef)(null);
|
|
38
|
+
var fieldInnerRef = (0, react_1.useRef)(null);
|
|
39
39
|
var filled = (0, utils_1.isValidValue)(valueState);
|
|
40
40
|
var handleChange = function (event) {
|
|
41
41
|
if (disabled)
|
|
@@ -93,18 +93,18 @@ exports.InputNumber = (0, react_1.forwardRef)(function (inProps, ref) {
|
|
|
93
93
|
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(inputProps, event);
|
|
94
94
|
};
|
|
95
95
|
/* Хук useEventListener необходим для того, чтобы при нажатии на кнопку мыши
|
|
96
|
-
* внутри HTML-элемента label
|
|
96
|
+
* внутри HTML-элемента label – фокус не переходил на body или на цель нажатия кнопки мыши.
|
|
97
97
|
* Если же нажатие кнопки происходит на самом HTML-элементе input, то мы ничего не делаем,
|
|
98
98
|
* так как в противном случае мы сломаем возможность выделять текст для копирования.
|
|
99
99
|
*/
|
|
100
100
|
(0, useEventListener_1.useEventListener)({
|
|
101
|
-
element:
|
|
101
|
+
element: bodyInnerRef,
|
|
102
102
|
eventName: 'mousedown',
|
|
103
103
|
handler: function (e) {
|
|
104
104
|
var _a;
|
|
105
|
-
if (e.target !==
|
|
105
|
+
if (e.target !== fieldInnerRef.current) {
|
|
106
106
|
e.preventDefault();
|
|
107
|
-
(_a =
|
|
107
|
+
(_a = fieldInnerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
});
|
|
@@ -135,13 +135,13 @@ exports.InputNumber = (0, react_1.forwardRef)(function (inProps, ref) {
|
|
|
135
135
|
hasLabel: !!label,
|
|
136
136
|
focused: focused,
|
|
137
137
|
}, [className]) }),
|
|
138
|
-
react_1.default.createElement("label", {
|
|
138
|
+
react_1.default.createElement("label", tslib_1.__assign({}, bodyProps, { className: (0, exports.cnInputNumber)('Body'), ref: (0, useMultiRef_1.useMultiRef)([bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.ref, bodyInnerRef]) }),
|
|
139
139
|
react_1.default.createElement(FieldIcon_1.FieldIcon, { className: (0, exports.cnInputNumber)('RenderLeft'), icon: renderLeft, size: size }),
|
|
140
140
|
react_1.default.createElement("div", { className: (0, exports.cnInputNumber)('FieldContainer') },
|
|
141
|
-
|
|
141
|
+
react_1.default.createElement(FieldLabel_1.FieldLabel, tslib_1.__assign({ filled: filled, focused: focused, required: required, disabled: disabled, size: size }, labelProps, { className: (0, exports.cnInputNumber)('Label', [labelProps === null || labelProps === void 0 ? void 0 : labelProps.className]), ref: labelRef }), label),
|
|
142
142
|
react_1.default.createElement("input", tslib_1.__assign({ id: id, name: name, autoFocus: autoFocus, disabled: disabled, value: valueState, required: required, placeholder: placeholder, className: (0, exports.cnInputNumber)('Field', { filled: filled }, [
|
|
143
143
|
inputProps === null || inputProps === void 0 ? void 0 : inputProps.className,
|
|
144
|
-
]), min: min, max: max, step: step }, inputProps, { type: "number", onFocus: handleFocus, onBlur: handleBlur, onChange: handleChange, onKeyDown: handleKeyDown, ref: (0, useMultiRef_1.useMultiRef)([inputProps === null || inputProps === void 0 ? void 0 : inputProps.ref,
|
|
144
|
+
]), min: min, max: max, step: step }, inputProps, { type: "number", onFocus: handleFocus, onBlur: handleBlur, onChange: handleChange, onKeyDown: handleKeyDown, ref: (0, useMultiRef_1.useMultiRef)([inputProps === null || inputProps === void 0 ? void 0 : inputProps.ref, fieldInnerRef]) }))),
|
|
145
145
|
react_1.default.createElement(FieldIcon_1.FieldIcon, { className: (0, exports.cnInputNumber)('RenderRight'), icon: renderRight, size: size }),
|
|
146
146
|
react_1.default.createElement("span", { className: (0, exports.cnInputNumber)('Controls') },
|
|
147
147
|
react_1.default.createElement(IconButton_1.IconButton, { tabIndex: -1, size: size, className: (0, exports.cnInputNumber)('Increment'), icon: icons_1.SortUpIcon, onMouseDown: handleMouseDown('increment'), disabled: disabled, "aria-label": "increment", type: "button", variant: "ghost" }),
|
|
@@ -52,6 +52,8 @@ export type InputNumberProps = {
|
|
|
52
52
|
labelRef?: FieldLabelProps['ref'];
|
|
53
53
|
/** Свойства FieldLabel */
|
|
54
54
|
labelProps?: FieldLabelProps;
|
|
55
|
+
/** Cвойства Body */
|
|
56
|
+
bodyProps?: ComponentPropsWithRef<'label'>;
|
|
55
57
|
/** Шаг инкремента/декремента */
|
|
56
58
|
step?: number;
|
|
57
59
|
/** Минимально допустимое значение */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ref, ComponentPropsWithRef
|
|
1
|
+
import type { Ref, ComponentPropsWithRef } from 'react';
|
|
2
2
|
import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
|
|
3
3
|
import type { FIELD_CONTROL_DEFAULT_TAG } from '../FieldControl';
|
|
4
4
|
import type { FieldLabelProps } from '../FieldLabel';
|
|
@@ -61,8 +61,6 @@ export type TextareaProps = Omit<ComponentPropsWithRef<typeof FIELD_CONTROL_DEFA
|
|
|
61
61
|
};
|
|
62
62
|
/** Свойства FieldLabel */
|
|
63
63
|
labelProps?: FieldLabelProps;
|
|
64
|
-
/** Ссылка на корневой DOM-элемент компонента */
|
|
65
|
-
ref?: ComponentRef<typeof FIELD_CONTROL_DEFAULT_TAG>;
|
|
66
64
|
/** data-атрибут для тестирования */
|
|
67
65
|
'data-testid'?: string;
|
|
68
66
|
} & TextareaPropsDeprecated;
|
|
@@ -25,7 +25,7 @@ var useControlled = function (_a) {
|
|
|
25
25
|
console.error([
|
|
26
26
|
"\u00D6zen-UI: \u041F\u043E\u0432\u0435\u0434\u0435\u043D\u0438\u0435 \u0441\u0432\u043E\u0439\u0441\u0442\u0432\u0430 '".concat(state, "' \u0443 \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442\u0430 ").concat(name, " \u043F\u043E\u043C\u0435\u043D\u044F\u043B\u043E\u0441\u044C \u0441 ").concat(isControlled ? '' : 'не', "\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u043E\u0433\u043E \u043D\u0430 ").concat(isControlled ? 'не' : '', "\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u043E\u0435."),
|
|
27
27
|
'Компоненты не должны переключаться с неконтролируемого поведения в контролируемое, или наоборот.',
|
|
28
|
-
'Поведение определяется после первого рендера и является контролируемым, если значение не
|
|
28
|
+
'Поведение определяется после первого рендера и является контролируемым, если значение не «undefined».',
|
|
29
29
|
].join('\n'));
|
|
30
30
|
}
|
|
31
31
|
}, [state, name, valueProp]);
|
|
@@ -33,8 +33,8 @@ var useControlled = function (_a) {
|
|
|
33
33
|
(0, react_1.useEffect)(function () {
|
|
34
34
|
if (!isControlled && defaultValue_1 !== defaultProp) {
|
|
35
35
|
console.error([
|
|
36
|
-
"\u00D6zen-UI: \u041D\u0435\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u044B\u0439 \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442 ".concat(name, " \u0441\u043C\u0435\u043D\u0438\u043B default ").concat(state, " \u043F\u043E\u0441\u043B\u0435 \u043F\u0435\u0440\u0432\u043E\u0439 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438 ").concat(name)
|
|
37
|
-
|
|
36
|
+
"\u00D6zen-UI: \u041D\u0435\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u044B\u0439 \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442 ".concat(name, " \u0441\u043C\u0435\u043D\u0438\u043B default ").concat(state, " \u043F\u043E\u0441\u043B\u0435 \u043F\u0435\u0440\u0432\u043E\u0439 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438 ").concat(name, "."),
|
|
37
|
+
"\u0415\u0441\u043B\u0438 \u043D\u0435\u043E\u0431\u0445\u043E\u0434\u0438\u043C\u043E \u043C\u0435\u043D\u044F\u0442\u044C \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0432\u043E\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435\u0441\u044C \u043A\u043E\u043D\u0442\u0440\u043E\u043B\u0438\u0440\u0443\u0435\u043C\u044B\u043C \u043F\u043E\u0432\u0435\u0434\u0435\u043D\u0438\u0435\u043C.",
|
|
38
38
|
].join('\n'));
|
|
39
39
|
}
|
|
40
40
|
}, [JSON.stringify(defaultProp)]);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
.DataList {
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
1
|
+
.DataList-List {
|
|
2
|
+
--scroll-bar-size: 12px;
|
|
3
|
+
}
|
|
4
|
+
.DataList-List::-webkit-scrollbar {
|
|
5
5
|
inline-size: var(--scroll-bar-size);
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
.DataList-List::-webkit-scrollbar-thumb {
|
|
8
8
|
background-color: var(--color-background-secondary);
|
|
9
9
|
border-radius: calc(var(--scroll-bar-size) / 2);
|
|
10
10
|
border: calc(var(--scroll-bar-size) / 4) solid transparent;
|
|
@@ -12,56 +12,83 @@
|
|
|
12
12
|
border-image: initial;
|
|
13
13
|
min-block-size: 24px;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
.DataList::-webkit-scrollbar-thumb:active {
|
|
15
|
+
.DataList-List::-webkit-scrollbar-thumb:hover,
|
|
16
|
+
.DataList-List::-webkit-scrollbar-thumb:active {
|
|
17
17
|
border: calc(var(--scroll-bar-size) / 4) solid transparent;
|
|
18
18
|
background-clip: padding-box;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
.DataList-List::-webkit-scrollbar-thumb:hover {
|
|
21
21
|
background-color: var(--color-background-secondary-hover);
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
.DataList-List::-webkit-scrollbar-thumb:active {
|
|
24
24
|
background-color: var(--color-background-secondary-pressed);
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
.DataList-List::-webkit-scrollbar-corner {
|
|
27
27
|
background: transparent;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
max-block-size: 40vb;
|
|
29
|
+
.DataList-List {
|
|
30
|
+
overflow: hidden auto;
|
|
31
|
+
max-block-size: 40vb;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
33
|
.DataList-Option {
|
|
36
34
|
cursor: pointer;
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
.DataList-Option:not(.DataList-Option_disabled).DataList-Option_highlighted {
|
|
40
|
-
background-color: var(--color-background-main-hover);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.DataList-Option:not(.DataList-Option_disabled).DataList-Option_outlined {
|
|
36
|
+
.DataList-Option_focused {
|
|
44
37
|
box-shadow: inset var(--shadow-outline-focused);
|
|
45
38
|
}
|
|
46
|
-
|
|
39
|
+
.DataList-Option_highlighted {
|
|
40
|
+
background-color: var(--color-background-main-hover);
|
|
41
|
+
}
|
|
47
42
|
.DataList-Option_disabled {
|
|
48
43
|
cursor: not-allowed;
|
|
49
44
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
color: var(--color-content-
|
|
45
|
+
.DataList-Option_disabled .ListItemText-TextPrimary,
|
|
46
|
+
.DataList-Option_disabled .ListItemText-TextSecondary {
|
|
47
|
+
color: var(--color-content-tertiary);
|
|
53
48
|
}
|
|
54
|
-
|
|
55
49
|
.DataList-IconWrapper {
|
|
56
50
|
min-inline-size: var(--select-check-icon-size);
|
|
57
51
|
min-block-size: var(--select-check-icon-size);
|
|
58
52
|
display: flex;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
.DataList-IconWrapper_size_s {
|
|
62
55
|
--select-check-icon-size: 16px;
|
|
63
56
|
}
|
|
64
|
-
|
|
65
57
|
.DataList-IconWrapper_size_m {
|
|
66
58
|
--select-check-icon-size: 24px;
|
|
67
59
|
}
|
|
60
|
+
.DataList_animation-enter {
|
|
61
|
+
opacity: 0;
|
|
62
|
+
transform: translate(0, calc(var(--space-s) * -1));
|
|
63
|
+
pointer-events: none;
|
|
64
|
+
}
|
|
65
|
+
.DataList_animation-enter-active {
|
|
66
|
+
opacity: 1;
|
|
67
|
+
transition:
|
|
68
|
+
opacity var(--transition-default),
|
|
69
|
+
transform var(--transition-default);
|
|
70
|
+
transform: translate(0);
|
|
71
|
+
pointer-events: none;
|
|
72
|
+
}
|
|
73
|
+
.DataList_animation-enter-done {
|
|
74
|
+
opacity: 1;
|
|
75
|
+
transform: translate(0);
|
|
76
|
+
}
|
|
77
|
+
.DataList_animation-exit {
|
|
78
|
+
opacity: 1;
|
|
79
|
+
transform: translate(0);
|
|
80
|
+
pointer-events: none;
|
|
81
|
+
}
|
|
82
|
+
.DataList_animation-exit-active {
|
|
83
|
+
opacity: 0;
|
|
84
|
+
transition:
|
|
85
|
+
opacity var(--transition-default),
|
|
86
|
+
transform var(--transition-default);
|
|
87
|
+
transform: translate(0, calc(var(--space-s) * -1));
|
|
88
|
+
pointer-events: none;
|
|
89
|
+
}
|
|
90
|
+
.DataList_animation-exit-done {
|
|
91
|
+
opacity: 0;
|
|
92
|
+
transform: translate(0, calc(var(--space-s) * -1));
|
|
93
|
+
pointer-events: none;
|
|
94
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import './DataList.css';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DataListComponent } from './index';
|
|
3
3
|
export declare const cnDataList: import("@bem-react/classname").ClassNameFormatter;
|
|
4
|
-
export declare const DataList:
|
|
4
|
+
export declare const DataList: DataListComponent;
|
|
@@ -1,50 +1,88 @@
|
|
|
1
|
-
import { __assign, __read, __rest } from "tslib";
|
|
1
|
+
import { __assign, __read, __rest, __spreadArray } from "tslib";
|
|
2
2
|
import './DataList.css';
|
|
3
|
-
import React
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useBoolean } from '../../hooks/useBoolean';
|
|
4
5
|
import { useControlled } from '../../hooks/useControlled';
|
|
5
6
|
import { useEventListener } from '../../hooks/useEventListener';
|
|
6
7
|
import { useMultiRef } from '../../hooks/useMultiRef';
|
|
7
8
|
import { useThemeProps } from '../../hooks/useThemeProps';
|
|
8
9
|
import { cn } from '../../utils/classname';
|
|
9
|
-
import { isKey } from '../../utils/isKey';
|
|
10
10
|
import { polymorphicComponentWithRef } from '../../utils/polymorphicComponentWithRef';
|
|
11
11
|
import { List } from '../List';
|
|
12
12
|
import { Popover } from '../Popover';
|
|
13
13
|
import { DATA_LIST_DEFAULT_SIZE, DATA_LIST_DEFAULT_OPEN, DATA_LIST_DEFAULT_TAG, } from './constants';
|
|
14
14
|
import { DataListContext } from './DataListProvider';
|
|
15
|
+
import { isMultipleParams, isNotMultipleParams } from './index';
|
|
15
16
|
import { useDataListNavigation } from './useDataListNavigation';
|
|
16
17
|
export var cnDataList = cn('DataList');
|
|
17
|
-
|
|
18
|
-
var _a = useThemeProps({ props: inProps, name: 'DataList' }), _b = _a.
|
|
19
|
-
|
|
18
|
+
var DataListRender = function (inProps, ref) {
|
|
19
|
+
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, other = __rest(_a, ["open", "size", "as", "name", "children", "anchorRef", "selected", "defaultSelected", "onClose", "onEntered", "onExited", "listProps"]);
|
|
20
|
+
// Состояние полностью представленного компонента
|
|
21
|
+
var _e = __read(useBoolean(false), 2), opened = _e[0], _f = _e[1], onEntered = _f.on, onExited = _f.off;
|
|
22
|
+
var _g = __read(useControlled({
|
|
20
23
|
name: 'DataList',
|
|
21
24
|
defaultValue: defaultSelected,
|
|
22
25
|
value: selectedProp,
|
|
23
26
|
state: 'selected',
|
|
24
|
-
}), 2), selected =
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
}), 2), selected = _g[0], setSelected = _g[1];
|
|
28
|
+
var handleSelect = function (event, value) {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
var res;
|
|
31
|
+
var props = __assign(__assign({}, inProps), { selected: selected });
|
|
32
|
+
if (isMultipleParams(props)) {
|
|
33
|
+
res = ((_a = props.selected) === null || _a === void 0 ? void 0 : _a.includes(value))
|
|
34
|
+
? props.selected.filter(function (item) { return item !== value; })
|
|
35
|
+
: __spreadArray(__spreadArray([], __read((selected || [])), false), [value], false);
|
|
36
|
+
(_b = props.onSelect) === null || _b === void 0 ? void 0 : _b.call(props, event, { name: name, value: res });
|
|
37
|
+
}
|
|
38
|
+
if (isNotMultipleParams(props)) {
|
|
39
|
+
res = value;
|
|
40
|
+
(_c = props.onSelect) === null || _c === void 0 ? void 0 : _c.call(props, event, { name: name, value: value });
|
|
41
|
+
}
|
|
42
|
+
setSelected(res || '');
|
|
29
43
|
};
|
|
30
|
-
|
|
44
|
+
// Фиксируем последний выбранный элемент в списке, чтобы потом переводить на него scroll в контейнере
|
|
45
|
+
var lastSelectedOption = Array.isArray(selected)
|
|
46
|
+
? selected[selected.length - 1]
|
|
47
|
+
: selected;
|
|
48
|
+
var _h = useDataListNavigation({
|
|
31
49
|
name: name,
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
active: opened,
|
|
51
|
+
selected: lastSelectedOption,
|
|
52
|
+
onSelect: function (e, selectedItem) {
|
|
53
|
+
handleSelect(e, selectedItem);
|
|
54
|
+
},
|
|
55
|
+
}), onKeyDown = _h.onKeyDown, listRef = _h.ref, navigation = __rest(_h, ["onKeyDown", "ref"]);
|
|
56
|
+
// Назначает элементу контроля события управления списком с клавиатуры
|
|
34
57
|
useEventListener({
|
|
35
58
|
active: open,
|
|
36
59
|
eventName: 'keydown',
|
|
37
60
|
element: anchorRef,
|
|
38
|
-
handler:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
handler: onKeyDown,
|
|
62
|
+
});
|
|
63
|
+
// Закрывает список как только элемент контроля теряет фокус
|
|
64
|
+
useEventListener({
|
|
65
|
+
active: open,
|
|
66
|
+
eventName: 'focusout',
|
|
67
|
+
element: anchorRef,
|
|
68
|
+
handler: function () {
|
|
69
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
44
70
|
},
|
|
45
71
|
});
|
|
46
|
-
return (React.createElement(Popover, __assign({ as: as, open: open, placement: "bottom-start", disableReturnFocus: true,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
72
|
+
return (React.createElement(Popover, __assign({ as: as, open: open, placement: "bottom-start", disableReturnFocus: true, disableClickOutside: true, disableEnforceFocus: true, offset: [0, 4], onClose: onClose, anchorRef: anchorRef, transitionProps: {
|
|
73
|
+
classNames: cnDataList({ animation: true }),
|
|
74
|
+
} }, other, { onEntered: function () {
|
|
75
|
+
onEntered();
|
|
76
|
+
onEnteredProp === null || onEnteredProp === void 0 ? void 0 : onEnteredProp();
|
|
77
|
+
}, onExited: function () {
|
|
78
|
+
onExited();
|
|
79
|
+
onExitedProp === null || onExitedProp === void 0 ? void 0 : onExitedProp();
|
|
80
|
+
}, ref: ref }),
|
|
81
|
+
React.createElement(DataListContext.Provider, { value: __assign({ selected: selected, size: size }, navigation) },
|
|
82
|
+
React.createElement(List, __assign({ as: "ul", size: size }, listProps, { onMouseDown: function (e) {
|
|
83
|
+
var _a;
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
(_a = listProps === null || listProps === void 0 ? void 0 : listProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(listProps, e);
|
|
86
|
+
}, ref: useMultiRef([listRef, listProps === null || listProps === void 0 ? void 0 : listProps.ref]), className: cnDataList('List', [listProps === null || listProps === void 0 ? void 0 : listProps.className]) }), children))));
|
|
87
|
+
};
|
|
88
|
+
export var DataList = polymorphicComponentWithRef(DataListRender);
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import type { SyntheticEvent, MouseEvent } from 'react';
|
|
2
|
+
import type React from 'react';
|
|
2
3
|
import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
|
|
3
|
-
export type DataListSelectPayload = {
|
|
4
|
-
name?: string;
|
|
5
|
-
value: string;
|
|
6
|
-
};
|
|
7
4
|
export type DataListContextState = {
|
|
8
5
|
'data-list': string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
selected?: string | string[];
|
|
7
|
+
focused?: string | null;
|
|
8
|
+
highlighted?: string | null;
|
|
12
9
|
size: FormElementSizeVariant;
|
|
10
|
+
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
|
13
11
|
onSelect?: (event: SyntheticEvent, option: string) => void;
|
|
14
|
-
onMouseMove?: (event: MouseEvent<
|
|
15
|
-
onMouseLeave?: (event: MouseEvent<
|
|
12
|
+
onMouseMove?: (event: MouseEvent<HTMLElement>) => void;
|
|
13
|
+
onMouseLeave?: (event: MouseEvent<HTMLElement>) => void;
|
|
16
14
|
};
|
|
17
|
-
export declare const DataListContext:
|
|
15
|
+
export declare const DataListContext: React.Context<DataListContextState>;
|
|
18
16
|
export declare const useDataListContext: () => DataListContextState;
|
|
@@ -2,8 +2,6 @@ import { createContext, useContext } from 'react';
|
|
|
2
2
|
import { DATA_LIST_DEFAULT_SIZE } from './constants';
|
|
3
3
|
export var DataListContext = createContext({
|
|
4
4
|
'data-list': '',
|
|
5
|
-
currentItem: null,
|
|
6
|
-
keyboardHighlight: false,
|
|
7
5
|
size: DATA_LIST_DEFAULT_SIZE,
|
|
8
6
|
});
|
|
9
7
|
export var useDataListContext = function () { return useContext(DataListContext); };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { KeyboardEventHandler, MouseEventHandler,
|
|
2
|
+
import type { KeyboardEventHandler, MouseEventHandler, ReactNode, ComponentPropsWithRef } from 'react';
|
|
3
3
|
export type DataListOptionProps = {
|
|
4
4
|
/** Если {true} отображает опцию заблокированной */
|
|
5
5
|
disabled?: boolean;
|
|
6
6
|
/** Значение, если оно отличается от содержимого опции */
|
|
7
|
-
value
|
|
7
|
+
value: string;
|
|
8
8
|
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
9
9
|
onKeyDown?: KeyboardEventHandler<HTMLLIElement>;
|
|
10
10
|
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
@@ -12,19 +12,6 @@ export type DataListOptionProps = {
|
|
|
12
12
|
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
13
13
|
onMouseLeave?: MouseEventHandler<HTMLLIElement>;
|
|
14
14
|
/** Содержимое компонента */
|
|
15
|
-
children:
|
|
16
|
-
} &
|
|
17
|
-
export declare const DataListOption: React.ForwardRefExoticComponent<
|
|
18
|
-
/** Если {true} отображает опцию заблокированной */
|
|
19
|
-
disabled?: boolean | undefined;
|
|
20
|
-
/** Значение, если оно отличается от содержимого опции */
|
|
21
|
-
value?: string | undefined;
|
|
22
|
-
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
23
|
-
onKeyDown?: React.KeyboardEventHandler<HTMLLIElement> | undefined;
|
|
24
|
-
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
25
|
-
onMouseMove?: React.MouseEventHandler<HTMLLIElement> | undefined;
|
|
26
|
-
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
27
|
-
onMouseLeave?: React.MouseEventHandler<HTMLLIElement> | undefined;
|
|
28
|
-
/** Содержимое компонента */
|
|
29
|
-
children: string;
|
|
30
|
-
} & React.HTMLAttributes<HTMLLIElement> & React.RefAttributes<HTMLLIElement>>;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
} & ComponentPropsWithRef<'li'>;
|
|
17
|
+
export declare const DataListOption: React.ForwardRefExoticComponent<Omit<DataListOptionProps, "ref"> & React.RefAttributes<HTMLLIElement>>;
|
|
@@ -1,44 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __assign, __rest } from "tslib";
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
2
3
|
import { TickIcon } from '@ozen-ui/icons';
|
|
3
|
-
import { useMultiRef } from '../../../hooks/useMultiRef';
|
|
4
4
|
import { getIconSizeToFormElement } from '../../../utils/getIconSizeToFormElement';
|
|
5
5
|
import { ListItem, ListItemText, ListItemIcon } from '../../List';
|
|
6
6
|
import { DATA_LIST_OPTION_DEFAULT_DISABLED } from '../constants';
|
|
7
7
|
import { cnDataList } from '../DataList';
|
|
8
8
|
import { useDataListContext } from '../DataListProvider';
|
|
9
9
|
export var DataListOption = forwardRef(function (_a, ref) {
|
|
10
|
-
var value = _a.value,
|
|
11
|
-
var
|
|
12
|
-
var _c = useDataListContext(), size = _c.size, currentItem = _c.currentItem, _d = _c.selected, selected = _d === void 0 ? '' : _d, keyboardHighlight = _c.keyboardHighlight, onSelect = _c.onSelect, onMouseMove = _c.onMouseMove, onMouseLeave = _c.onMouseLeave, dataListName = _c["data-list"];
|
|
10
|
+
var value = _a.value, onMouseMoveProp = _a.onMouseMove, onMouseLeaveProp = _a.onMouseLeave, onClickProp = _a.onClick, _b = _a.disabled, disabled = _b === void 0 ? DATA_LIST_OPTION_DEFAULT_DISABLED : _b, label = _a.children, className = _a.className, other = __rest(_a, ["value", "onMouseMove", "onMouseLeave", "onClick", "disabled", "children", "className"]);
|
|
11
|
+
var _c = useDataListContext(), size = _c.size, _d = _c.selected, selected = _d === void 0 ? [] : _d, focused = _c.focused, highlighted = _c.highlighted, onClick = _c.onClick, onMouseMove = _c.onMouseMove, onMouseLeave = _c.onMouseLeave, dataListName = _c["data-list"];
|
|
13
12
|
var iconSize = getIconSizeToFormElement(size);
|
|
14
|
-
var isSelected = (
|
|
15
|
-
|
|
13
|
+
var isSelected = Array.isArray(selected)
|
|
14
|
+
? selected.includes(value)
|
|
15
|
+
: selected === value;
|
|
16
16
|
var handleClick = function (event) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
onSelect === null || onSelect === void 0 ? void 0 : onSelect(event, ((_a = event.currentTarget.dataset) === null || _a === void 0 ? void 0 : _a.value) || '');
|
|
17
|
+
onClickProp === null || onClickProp === void 0 ? void 0 : onClickProp(event);
|
|
18
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
22
19
|
};
|
|
23
20
|
var handleMouseMove = function (event) {
|
|
24
|
-
onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove(event);
|
|
25
21
|
onMouseMoveProp === null || onMouseMoveProp === void 0 ? void 0 : onMouseMoveProp(event);
|
|
22
|
+
onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove(event);
|
|
26
23
|
};
|
|
27
24
|
var handleMouseLeave = function (event) {
|
|
28
25
|
onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(event);
|
|
29
26
|
onMouseLeaveProp === null || onMouseLeaveProp === void 0 ? void 0 : onMouseLeaveProp(event);
|
|
30
27
|
};
|
|
31
|
-
|
|
32
|
-
event.preventDefault();
|
|
33
|
-
onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
|
|
34
|
-
};
|
|
35
|
-
return (React.createElement(ListItem, { role: "option", ref: useMultiRef([optionRef, ref]), "data-list": dataListName, "data-value": value || label, "aria-selected": isSelected, "aria-disabled": disabled, onClick: handleClick, onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, className: cnDataList('Option', {
|
|
28
|
+
return (React.createElement(ListItem, __assign({ role: "option", "data-list": dataListName, "data-list-value": value, "data-list-disabled": disabled, "aria-selected": isSelected, "aria-disabled": disabled, onClick: handleClick, onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, className: cnDataList('Option', {
|
|
36
29
|
disabled: disabled,
|
|
37
|
-
highlighted: !disabled &&
|
|
38
|
-
|
|
39
|
-
}) },
|
|
40
|
-
React.createElement(ListItemText, { className: cnDataList('Text'
|
|
30
|
+
highlighted: !disabled && highlighted === value,
|
|
31
|
+
focused: !disabled && focused === value,
|
|
32
|
+
}, [className]) }, other, { ref: ref }), typeof label === 'string' ? (React.createElement(React.Fragment, null,
|
|
33
|
+
React.createElement(ListItemText, { className: cnDataList('Text'), primary: label }),
|
|
41
34
|
React.createElement("div", { className: cnDataList('IconWrapper', { size: iconSize }) }, isSelected && (React.createElement(ListItemIcon, null,
|
|
42
|
-
React.createElement(TickIcon, { size: iconSize }))))));
|
|
35
|
+
React.createElement(TickIcon, { size: iconSize })))))) : (label)));
|
|
43
36
|
});
|
|
44
37
|
DataListOption.displayName = 'DataListOption';
|
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
import type { ReactNode,
|
|
1
|
+
import type { ReactNode, ElementType } from 'react';
|
|
2
2
|
import type React from 'react';
|
|
3
3
|
import type { FormElementSizeVariant } from '../../types/FormElementSizeVariant';
|
|
4
|
-
import type { PolymorphicComponentPropsWithRef } from '../../utils/polymorphicComponentWithRef';
|
|
4
|
+
import type { PolymorphicComponentPropsWithRef, PolymorphicComponentRef } from '../../utils/polymorphicComponentWithRef';
|
|
5
5
|
import type { ListProps } from '../List';
|
|
6
6
|
import type { PopoverBaseProps } from '../Popover';
|
|
7
7
|
import type { DATA_LIST_DEFAULT_TAG } from './constants';
|
|
8
|
-
export type DataListPayload = {
|
|
8
|
+
export type DataListPayload<MULTIPLE extends boolean> = {
|
|
9
9
|
name?: string;
|
|
10
|
-
value: string;
|
|
10
|
+
value: MULTIPLE extends true ? string[] : string;
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
12
|
+
export type DataListSelected<MULTIPLE extends boolean> = (MULTIPLE extends true ? string[] : string) | undefined;
|
|
13
|
+
export type DataListOnSelect<MULTIPLE extends boolean> = (event: React.SyntheticEvent | KeyboardEvent, payload: DataListPayload<MULTIPLE>) => void;
|
|
14
|
+
export type DataListBaseProps<MULTIPLE extends boolean = false> = {
|
|
13
15
|
/** Имя списка */
|
|
14
16
|
name?: string;
|
|
15
17
|
/** Признак по которому компонент будет представлен */
|
|
16
18
|
open?: boolean;
|
|
17
19
|
/** Содержимое компонента */
|
|
18
20
|
children: ReactNode;
|
|
21
|
+
/** Если {true} из списка можно выбрать несколько вариантов */
|
|
22
|
+
multiple?: MULTIPLE;
|
|
19
23
|
/** Дополнительные CSS-классы */
|
|
20
24
|
className?: string;
|
|
21
25
|
/** Размер компонента */
|
|
22
26
|
size?: FormElementSizeVariant;
|
|
23
|
-
/** Выбранная
|
|
24
|
-
selected?:
|
|
27
|
+
/** Выбранная или выбранные опции */
|
|
28
|
+
selected?: DataListSelected<MULTIPLE>;
|
|
25
29
|
/** Выбранная опция по умолчанию */
|
|
26
|
-
defaultSelected?:
|
|
30
|
+
defaultSelected?: DataListSelected<MULTIPLE>;
|
|
27
31
|
/** Функция обратного вызова для выбора значения */
|
|
28
|
-
onSelect?:
|
|
32
|
+
onSelect?: DataListOnSelect<MULTIPLE>;
|
|
29
33
|
/** Свойства компонента List */
|
|
30
34
|
listProps?: ListProps;
|
|
31
|
-
}
|
|
32
|
-
export
|
|
33
|
-
export
|
|
35
|
+
} & Omit<PopoverBaseProps, 'onSelect'>;
|
|
36
|
+
export declare const isMultipleParams: (params: DataListBaseProps<boolean>) => params is DataListBaseProps<true>;
|
|
37
|
+
export declare const isNotMultipleParams: (params: DataListBaseProps<boolean>) => params is DataListBaseProps<false>;
|
|
38
|
+
export type DataListRef = PolymorphicComponentRef<typeof DATA_LIST_DEFAULT_TAG>;
|
|
39
|
+
export type DataListProps<As extends ElementType = typeof DATA_LIST_DEFAULT_TAG, MULTIPLE extends boolean = false> = PolymorphicComponentPropsWithRef<DataListBaseProps<MULTIPLE>, As>;
|
|
40
|
+
export type DataListComponent = <As extends ElementType = typeof DATA_LIST_DEFAULT_TAG, MULTIPLE extends boolean = false>(props: PolymorphicComponentPropsWithRef<DataListBaseProps<MULTIPLE>, As>) => React.ReactElement | null;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export var isMultipleParams = function (params) { return !!params.multiple; };
|
|
2
|
+
export var isNotMultipleParams = function (params) { return !params.multiple; };
|