@ozen-ui/kit 0.16.1 → 0.17.0-canary.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 +19 -46
- package/__inner__/cjs/components/DataList/DataList.js +101 -40
- package/__inner__/cjs/components/DataList/components/DataListCheckIcon/DataListCheckIcon.css +13 -0
- package/__inner__/cjs/components/{Select/components/SelectCheckIcon/SelectCheckIcon.d.ts → DataList/components/DataListCheckIcon/DataListCheckIcon.d.ts} +2 -2
- package/__inner__/cjs/components/DataList/components/DataListCheckIcon/DataListCheckIcon.js +16 -0
- package/__inner__/cjs/components/DataList/components/DataListCheckIcon/index.d.ts +1 -0
- package/__inner__/cjs/components/DataList/components/DataListCheckIcon/index.js +4 -0
- package/__inner__/cjs/components/DataList/components/DataListOption/DataListOption.css +20 -0
- package/__inner__/{esm/components/DataList/components → cjs/components/DataList/components/DataListOption}/DataListOption.d.ts +15 -4
- package/__inner__/cjs/components/DataList/components/DataListOption/DataListOption.js +39 -0
- package/__inner__/cjs/components/DataList/components/DataListOption/index.d.ts +1 -0
- package/__inner__/cjs/components/{Select/components/SelectCheckIcon → DataList/components/DataListOption}/index.js +1 -1
- package/__inner__/cjs/components/DataList/constants.d.ts +1 -0
- package/__inner__/cjs/components/DataList/constants.js +3 -1
- package/__inner__/cjs/components/DataList/helpers/index.d.ts +4 -0
- package/__inner__/cjs/components/DataList/helpers/index.js +7 -0
- package/__inner__/cjs/components/DataList/helpers/lastSelectedValue.d.ts +1 -0
- package/__inner__/cjs/components/DataList/helpers/lastSelectedValue.js +8 -0
- package/__inner__/cjs/components/DataList/helpers/types.d.ts +10 -0
- package/__inner__/cjs/components/DataList/helpers/types.js +7 -0
- package/__inner__/cjs/components/DataList/helpers/useDataListNavigation.d.ts +23 -0
- package/__inner__/cjs/components/DataList/helpers/useDataListNavigation.js +85 -0
- package/__inner__/cjs/components/DataList/helpers/useScrollContainerToElement.d.ts +3 -0
- package/__inner__/cjs/components/DataList/helpers/useScrollContainerToElement.js +15 -0
- package/__inner__/cjs/components/DataList/types.d.ts +3 -4
- package/__inner__/cjs/components/DataList/types.js +0 -5
- package/__inner__/cjs/components/FieldControl/FieldControl.js +1 -0
- package/__inner__/cjs/components/Input/Input.js +1 -1
- package/__inner__/cjs/components/Input/types.d.ts +3 -2
- package/__inner__/cjs/components/Select/Select.css +33 -128
- package/__inner__/cjs/components/Select/Select.d.ts +2 -3
- package/__inner__/cjs/components/Select/Select.js +92 -80
- package/__inner__/cjs/components/Select/components/SelectConsumer/SelectInputConsumer.d.ts +5 -0
- package/__inner__/cjs/components/Select/components/SelectConsumer/SelectInputConsumer.js +21 -0
- package/__inner__/cjs/components/Select/components/SelectConsumer/index.d.ts +1 -0
- package/__inner__/cjs/components/Select/components/SelectConsumer/index.js +4 -0
- package/__inner__/cjs/components/Select/components/SelectInput/SelectInput.d.ts +1 -72
- package/__inner__/cjs/components/Select/components/SelectInput/SelectInput.js +23 -22
- package/__inner__/cjs/components/Select/components/SelectInput/index.d.ts +1 -0
- package/__inner__/cjs/components/Select/components/SelectInput/index.js +1 -0
- package/__inner__/cjs/components/Select/components/SelectInput/types.d.ts +89 -0
- package/__inner__/cjs/components/Select/components/SelectInput/types.js +2 -0
- package/__inner__/cjs/components/Select/components/index.d.ts +0 -1
- package/__inner__/cjs/components/Select/components/index.js +0 -1
- package/__inner__/cjs/components/Select/constants.d.ts +1 -1
- package/__inner__/cjs/components/Select/constants.js +2 -2
- package/__inner__/cjs/components/Select/helpers/index.d.ts +1 -0
- package/__inner__/cjs/components/Select/helpers/index.js +4 -0
- package/__inner__/cjs/components/Select/helpers/types.d.ts +8 -0
- package/__inner__/cjs/components/Select/helpers/types.js +7 -0
- package/__inner__/cjs/components/Select/index.d.ts +2 -1
- package/__inner__/cjs/components/Select/index.js +5 -4
- package/__inner__/cjs/components/Select/types.d.ts +31 -18
- package/__inner__/cjs/components/Textarea/Textarea.js +1 -1
- package/__inner__/cjs/components/Textarea/types.d.ts +2 -2
- package/__inner__/cjs/utils/scrollContainerToElement.d.ts +3 -4
- package/__inner__/esm/components/DataList/DataList.css +19 -46
- package/__inner__/esm/components/DataList/DataList.js +101 -40
- package/__inner__/esm/components/DataList/components/DataListCheckIcon/DataListCheckIcon.css +13 -0
- package/__inner__/esm/components/{Select/components/SelectCheckIcon/SelectCheckIcon.d.ts → DataList/components/DataListCheckIcon/DataListCheckIcon.d.ts} +2 -2
- package/__inner__/esm/components/DataList/components/DataListCheckIcon/DataListCheckIcon.js +11 -0
- package/__inner__/esm/components/DataList/components/DataListCheckIcon/index.d.ts +1 -0
- package/__inner__/esm/components/DataList/components/DataListCheckIcon/index.js +1 -0
- package/__inner__/esm/components/DataList/components/DataListOption/DataListOption.css +20 -0
- package/__inner__/{cjs/components/DataList/components → esm/components/DataList/components/DataListOption}/DataListOption.d.ts +15 -4
- package/__inner__/esm/components/DataList/components/DataListOption/DataListOption.js +36 -0
- package/__inner__/esm/components/DataList/components/DataListOption/index.d.ts +1 -0
- package/__inner__/esm/components/DataList/components/DataListOption/index.js +1 -0
- package/__inner__/esm/components/DataList/constants.d.ts +1 -0
- package/__inner__/esm/components/DataList/constants.js +2 -0
- package/__inner__/esm/components/DataList/helpers/index.d.ts +4 -0
- package/__inner__/esm/components/DataList/helpers/index.js +4 -0
- package/__inner__/esm/components/DataList/helpers/lastSelectedValue.d.ts +1 -0
- package/__inner__/esm/components/DataList/helpers/lastSelectedValue.js +4 -0
- package/__inner__/esm/components/DataList/helpers/types.d.ts +10 -0
- package/__inner__/esm/components/DataList/helpers/types.js +2 -0
- package/__inner__/esm/components/DataList/helpers/useDataListNavigation.d.ts +23 -0
- package/__inner__/esm/components/DataList/helpers/useDataListNavigation.js +81 -0
- package/__inner__/esm/components/DataList/helpers/useScrollContainerToElement.d.ts +3 -0
- package/__inner__/esm/components/DataList/helpers/useScrollContainerToElement.js +11 -0
- package/__inner__/esm/components/DataList/types.d.ts +3 -4
- package/__inner__/esm/components/DataList/types.js +1 -2
- package/__inner__/esm/components/FieldControl/FieldControl.js +1 -0
- package/__inner__/esm/components/Input/Input.js +1 -1
- package/__inner__/esm/components/Input/types.d.ts +3 -2
- package/__inner__/esm/components/Select/Select.css +33 -128
- package/__inner__/esm/components/Select/Select.d.ts +2 -3
- package/__inner__/esm/components/Select/Select.js +96 -84
- package/__inner__/esm/components/Select/components/SelectConsumer/SelectInputConsumer.d.ts +5 -0
- package/__inner__/esm/components/Select/components/SelectConsumer/SelectInputConsumer.js +17 -0
- package/__inner__/esm/components/Select/components/SelectConsumer/index.d.ts +1 -0
- package/__inner__/esm/components/Select/components/SelectConsumer/index.js +1 -0
- package/__inner__/esm/components/Select/components/SelectInput/SelectInput.d.ts +1 -72
- package/__inner__/esm/components/Select/components/SelectInput/SelectInput.js +25 -24
- package/__inner__/esm/components/Select/components/SelectInput/index.d.ts +1 -0
- package/__inner__/esm/components/Select/components/SelectInput/index.js +1 -0
- package/__inner__/esm/components/Select/components/SelectInput/types.d.ts +89 -0
- package/__inner__/esm/components/Select/components/SelectInput/types.js +1 -0
- package/__inner__/esm/components/Select/components/index.d.ts +0 -1
- package/__inner__/esm/components/Select/components/index.js +0 -1
- package/__inner__/esm/components/Select/constants.d.ts +1 -1
- package/__inner__/esm/components/Select/constants.js +1 -1
- package/__inner__/esm/components/Select/helpers/index.d.ts +1 -0
- package/__inner__/esm/components/Select/helpers/index.js +1 -0
- package/__inner__/esm/components/Select/helpers/types.d.ts +8 -0
- package/__inner__/esm/components/Select/helpers/types.js +2 -0
- package/__inner__/esm/components/Select/index.d.ts +2 -1
- package/__inner__/esm/components/Select/index.js +2 -1
- package/__inner__/esm/components/Select/types.d.ts +31 -18
- package/__inner__/esm/components/Textarea/Textarea.js +1 -1
- package/__inner__/esm/components/Textarea/types.d.ts +2 -2
- package/__inner__/esm/utils/scrollContainerToElement.d.ts +3 -4
- package/package.json +1 -1
- package/__inner__/cjs/components/DataList/DataListProvider.d.ts +0 -16
- package/__inner__/cjs/components/DataList/DataListProvider.js +0 -11
- package/__inner__/cjs/components/DataList/components/DataListOption.js +0 -40
- package/__inner__/cjs/components/DataList/useDataListNavigation.d.ts +0 -23
- package/__inner__/cjs/components/DataList/useDataListNavigation.js +0 -109
- package/__inner__/cjs/components/Select/components/SelectCheckIcon/SelectCheckIcon.css +0 -13
- package/__inner__/cjs/components/Select/components/SelectCheckIcon/SelectCheckIcon.js +0 -14
- package/__inner__/cjs/components/Select/components/SelectCheckIcon/index.d.ts +0 -1
- package/__inner__/esm/components/DataList/DataListProvider.d.ts +0 -16
- package/__inner__/esm/components/DataList/DataListProvider.js +0 -7
- package/__inner__/esm/components/DataList/components/DataListOption.js +0 -37
- package/__inner__/esm/components/DataList/useDataListNavigation.d.ts +0 -23
- package/__inner__/esm/components/DataList/useDataListNavigation.js +0 -105
- package/__inner__/esm/components/Select/components/SelectCheckIcon/SelectCheckIcon.css +0 -13
- package/__inner__/esm/components/Select/components/SelectCheckIcon/SelectCheckIcon.js +0 -9
- package/__inner__/esm/components/Select/components/SelectCheckIcon/index.d.ts +0 -1
- package/__inner__/esm/components/Select/components/SelectCheckIcon/index.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __assign, __read, __rest, __spreadArray } from "tslib";
|
|
2
2
|
import './DataList.css';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { useMemo, Children, isValidElement, cloneElement, useRef, useEffect, useState, } from 'react';
|
|
4
|
+
import { isFragment } from 'react-is';
|
|
4
5
|
import { useBoolean } from '../../hooks/useBoolean';
|
|
5
6
|
import { useControlled } from '../../hooks/useControlled';
|
|
6
7
|
import { useEventListener } from '../../hooks/useEventListener';
|
|
@@ -12,58 +13,88 @@ import { polymorphicComponentWithRef } from '../../utils/polymorphicComponentWit
|
|
|
12
13
|
import { List } from '../List';
|
|
13
14
|
import { Popover } from '../Popover';
|
|
14
15
|
import { DATA_LIST_DEFAULT_SIZE, DATA_LIST_DEFAULT_OPEN, DATA_LIST_DEFAULT_TAG, } from './constants';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { useDataListNavigation } from './useDataListNavigation';
|
|
16
|
+
import { lastSelectedValue, isMultipleParams, isNotMultipleParams, useDataListNavigation, useScrollContainerToElement, } from './helpers';
|
|
17
|
+
import { DataListOption } from './index';
|
|
18
18
|
export var cnDataList = cn('DataList');
|
|
19
19
|
var DataListRender = function (inProps, ref) {
|
|
20
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, other = __rest(_a, ["open", "size", "as", "name", "children", "anchorRef", "selected", "defaultSelected", "onClose", "onEntered", "onExited", "listProps"]);
|
|
21
|
-
|
|
21
|
+
var listRef = useRef(null);
|
|
22
|
+
// Состояние представленного компонента с завершенной анимацией
|
|
22
23
|
var _e = __read(useBoolean(false), 2), opened = _e[0], _f = _e[1], onEntered = _f.on, onExited = _f.off;
|
|
23
24
|
var _g = __read(useControlled({
|
|
24
25
|
name: 'DataList',
|
|
25
26
|
defaultValue: defaultSelected,
|
|
26
27
|
value: selectedProp,
|
|
27
28
|
state: 'selected',
|
|
28
|
-
}), 2),
|
|
29
|
+
}), 2), selectedState = _g[0], setSelected = _g[1];
|
|
30
|
+
var nodes = useMemo(function () { return new Map(); }, [children]);
|
|
31
|
+
var resolvedChildren = isFragment(children)
|
|
32
|
+
? children.props.children
|
|
33
|
+
: children;
|
|
34
|
+
var isNotSelectOption = function (child) {
|
|
35
|
+
return !isValidElement(child) ||
|
|
36
|
+
child.type !== DataListOption ||
|
|
37
|
+
!!child.props.disabled;
|
|
38
|
+
};
|
|
39
|
+
Children.forEach(resolvedChildren, function (child, idx) {
|
|
40
|
+
if (!isNotSelectOption(child)) {
|
|
41
|
+
nodes.set(child.props.value, idx);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
29
44
|
var handleSelect = function (event, value) {
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
var params = {
|
|
46
|
+
multiple: inProps.multiple,
|
|
47
|
+
onSelect: inProps.onSelect,
|
|
48
|
+
selected: selectedState,
|
|
49
|
+
setSelected: setSelected,
|
|
50
|
+
};
|
|
51
|
+
if (isMultipleParams(params)) {
|
|
52
|
+
var selected_1 = params.selected, onSelect = params.onSelect, setSelected_1 = params.setSelected;
|
|
53
|
+
var res = (selected_1 === null || selected_1 === void 0 ? void 0 : selected_1.includes(value || ''))
|
|
54
|
+
? selected_1.filter(function (item) { return item !== value; })
|
|
55
|
+
: __spreadArray(__spreadArray([], __read((selected_1 || [])), false), [value], false);
|
|
56
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(event, { name: name, value: res });
|
|
57
|
+
setSelected_1(res);
|
|
38
58
|
}
|
|
39
|
-
if (isNotMultipleParams(
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
if (isNotMultipleParams(params)) {
|
|
60
|
+
var onSelect = params.onSelect, setSelected_2 = params.setSelected;
|
|
61
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(event, { name: name, value: value });
|
|
62
|
+
setSelected_2(value);
|
|
42
63
|
}
|
|
43
|
-
setSelected(res || '');
|
|
44
64
|
};
|
|
45
|
-
//
|
|
46
|
-
var lastSelectedOption = Array.isArray(selected)
|
|
47
|
-
? selected[selected.length - 1]
|
|
48
|
-
: selected;
|
|
65
|
+
// Навигация по списку
|
|
49
66
|
var _h = useDataListNavigation({
|
|
50
|
-
name: name,
|
|
51
67
|
active: opened,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
items: __spreadArray([], __read(nodes.keys()), false),
|
|
69
|
+
current: lastSelectedValue(selectedState),
|
|
70
|
+
onSelect: function (event, item) {
|
|
71
|
+
handleSelect(event, item || '');
|
|
55
72
|
},
|
|
56
|
-
}),
|
|
57
|
-
|
|
73
|
+
}), selected = _h.selected, focused = _h.focused, highlighted = _h.highlighted, onKeyDown = _h.onKeyDown, onClick = _h.onClick, onMouseEnter = _h.onMouseEnter, onMouseLeave = _h.onMouseLeave;
|
|
74
|
+
var _j = __read(useState({ current: null }), 2), selectedElRef = _j[0], setSelectedElRef = _j[1];
|
|
75
|
+
// Находит элемент по ключу
|
|
76
|
+
useEffect(function () {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
var current = focused || selected || '';
|
|
79
|
+
var idx = nodes.get(current);
|
|
80
|
+
if (idx) {
|
|
81
|
+
setSelectedElRef({
|
|
82
|
+
current: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, [focused, selected]);
|
|
86
|
+
// Прокрутка списка
|
|
87
|
+
useScrollContainerToElement(listRef, selectedElRef, focused ? 'smooth' : 'instant');
|
|
88
|
+
// Назначает элементу контроля событие управления списком с клавиатуры
|
|
58
89
|
useEventListener({
|
|
59
|
-
active:
|
|
90
|
+
active: opened,
|
|
60
91
|
eventName: 'keydown',
|
|
61
92
|
element: anchorRef,
|
|
62
|
-
handler:
|
|
93
|
+
handler: function (event) {
|
|
94
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
95
|
+
},
|
|
63
96
|
});
|
|
64
|
-
// Закрывает список нажатию
|
|
65
|
-
// Событие focusout может не срабатывать на устройствах iOS,
|
|
66
|
-
// так как многие интерактивные элементы по клику не получают фокус.
|
|
97
|
+
// Закрывает список по нажатию на клавишу {Tab}
|
|
67
98
|
useEventListener({
|
|
68
99
|
active: open,
|
|
69
100
|
eventName: 'keydown',
|
|
@@ -74,8 +105,39 @@ var DataListRender = function (inProps, ref) {
|
|
|
74
105
|
}
|
|
75
106
|
},
|
|
76
107
|
});
|
|
108
|
+
// Представление раскрывающегося списка
|
|
109
|
+
var renderChildren = Children.map(resolvedChildren, function (child) {
|
|
110
|
+
if (isNotSelectOption(child)) {
|
|
111
|
+
return child;
|
|
112
|
+
}
|
|
113
|
+
var key = child.props.value;
|
|
114
|
+
var elementChild = child;
|
|
115
|
+
var props = {
|
|
116
|
+
onClick: function (event) {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event, key);
|
|
119
|
+
(_b = (_a = child.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
120
|
+
},
|
|
121
|
+
onMouseEnter: function (event) {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(key);
|
|
124
|
+
(_b = (_a = child.props).onMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
125
|
+
},
|
|
126
|
+
onMouseLeave: function (event) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave();
|
|
129
|
+
(_b = (_a = child.props).onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
130
|
+
},
|
|
131
|
+
highlighted: key === highlighted,
|
|
132
|
+
focused: key === focused,
|
|
133
|
+
selected: Array.isArray(selectedState)
|
|
134
|
+
? selectedState.includes(key)
|
|
135
|
+
: selectedState === key,
|
|
136
|
+
};
|
|
137
|
+
return cloneElement(elementChild, __assign({}, props));
|
|
138
|
+
});
|
|
77
139
|
return (React.createElement(Popover, __assign({ as: as, open: open, placement: "bottom-start", disableReturnFocus: true, disableEnforceFocus: true, offset: [0, 4], onClose: onClose, anchorRef: anchorRef, transitionProps: {
|
|
78
|
-
classNames:
|
|
140
|
+
classNames: 'DataList-animation',
|
|
79
141
|
} }, other, { onEntered: function () {
|
|
80
142
|
onEntered();
|
|
81
143
|
onEnteredProp === null || onEnteredProp === void 0 ? void 0 : onEnteredProp();
|
|
@@ -83,11 +145,10 @@ var DataListRender = function (inProps, ref) {
|
|
|
83
145
|
onExited();
|
|
84
146
|
onExitedProp === null || onExitedProp === void 0 ? void 0 : onExitedProp();
|
|
85
147
|
}, ref: ref }),
|
|
86
|
-
React.createElement(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}, 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))));
|
|
148
|
+
React.createElement(List, __assign({ as: "ul", size: size }, listProps, { onMouseDown: function (e) {
|
|
149
|
+
var _a;
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
(_a = listProps === null || listProps === void 0 ? void 0 : listProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(listProps, e);
|
|
152
|
+
}, ref: useMultiRef([listRef, listProps === null || listProps === void 0 ? void 0 : listProps.ref]), className: cnDataList('', [listProps === null || listProps === void 0 ? void 0 : listProps.className]) }), renderChildren)));
|
|
92
153
|
};
|
|
93
154
|
export var DataList = polymorphicComponentWithRef(DataListRender);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.DataListCheckIcon {
|
|
2
|
+
inline-size: var(--data-list-check-icon-size);
|
|
3
|
+
block-size: var(--data-list-check-icon-size);
|
|
4
|
+
display: flex;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.DataListCheckIcon_size_s {
|
|
8
|
+
--data-list-check-icon-size: 16px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.DataListCheckIcon_size_m {
|
|
12
|
+
--data-list-check-icon-size: 24px;
|
|
13
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import './
|
|
1
|
+
import './DataListCheckIcon.css';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { type IconSize } from '@ozen-ui/icons';
|
|
4
4
|
export type SelectCheckIconProps = {
|
|
5
5
|
size?: IconSize;
|
|
6
6
|
selected?: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const DataListCheckIcon: React.FC<SelectCheckIconProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './DataListCheckIcon.css';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TickIcon } from '@ozen-ui/icons';
|
|
4
|
+
import { cn } from '../../../../utils/classname';
|
|
5
|
+
import { ListItemIcon } from '../../../List';
|
|
6
|
+
var cnDataListCheckIcon = cn('DataListCheckIcon');
|
|
7
|
+
export var DataListCheckIcon = function (_a) {
|
|
8
|
+
var size = _a.size, selected = _a.selected;
|
|
9
|
+
return (React.createElement("div", { className: cnDataListCheckIcon('', { size: size }) }, selected && (React.createElement(ListItemIcon, null,
|
|
10
|
+
React.createElement(TickIcon, { size: size })))));
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DataListCheckIcon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DataListCheckIcon';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.DataListOption {
|
|
2
|
+
cursor: pointer;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.DataListOption_focused {
|
|
6
|
+
box-shadow: inset var(--shadow-outline-focused);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.DataListOption_highlighted {
|
|
10
|
+
background-color: var(--color-background-main-hover);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.DataListOption_disabled {
|
|
14
|
+
cursor: not-allowed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.DataListOption_disabled .ListItemText-TextPrimary,
|
|
18
|
+
.DataListOption_disabled .ListItemText-TextSecondary {
|
|
19
|
+
color: var(--color-content-tertiary);
|
|
20
|
+
}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
import './DataListOption.css';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { KeyboardEventHandler, MouseEventHandler, ReactNode, ComponentPropsWithRef } from 'react';
|
|
4
|
+
import type { DATA_LIST_OPTION_DEFAULT_TAG } from '../../constants';
|
|
5
|
+
export declare const cnDataListOption: import("@bem-react/classname").ClassNameFormatter;
|
|
3
6
|
export type DataListOptionProps = {
|
|
7
|
+
/** Значение опции */
|
|
8
|
+
value: string | number;
|
|
9
|
+
/** Лейбл опции */
|
|
10
|
+
label?: string;
|
|
4
11
|
/** Если {true} отображает опцию заблокированной */
|
|
5
12
|
disabled?: boolean;
|
|
6
|
-
/**
|
|
7
|
-
|
|
13
|
+
/** Если {true} отображает опцию сфокусированной (клавиатура) */
|
|
14
|
+
focused?: boolean;
|
|
15
|
+
/** Если {true} отображает опцию наведенной (мышь) */
|
|
16
|
+
highlighted?: boolean;
|
|
17
|
+
/** Если {true} отображает опцию выбранной */
|
|
18
|
+
selected?: boolean;
|
|
8
19
|
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
9
20
|
onKeyDown?: KeyboardEventHandler<HTMLLIElement>;
|
|
10
21
|
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
@@ -12,6 +23,6 @@ export type DataListOptionProps = {
|
|
|
12
23
|
/** Функция обратного вызова обработчик нажатий на клавиатуре */
|
|
13
24
|
onMouseLeave?: MouseEventHandler<HTMLLIElement>;
|
|
14
25
|
/** Содержимое компонента */
|
|
15
|
-
children
|
|
16
|
-
} & ComponentPropsWithRef<'
|
|
26
|
+
children?: ReactNode;
|
|
27
|
+
} & Omit<ComponentPropsWithRef<typeof DATA_LIST_OPTION_DEFAULT_TAG>, 'value'>;
|
|
17
28
|
export declare const DataListOption: React.ForwardRefExoticComponent<Omit<DataListOptionProps, "ref"> & React.RefAttributes<HTMLLIElement>>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __assign, __rest } from "tslib";
|
|
2
|
+
import './DataListOption.css';
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { cn } from '../../../../utils/classname';
|
|
5
|
+
import { getIconSizeToFormElement } from '../../../../utils/getIconSizeToFormElement';
|
|
6
|
+
import { isString } from '../../../../utils/isString';
|
|
7
|
+
import { ListItem, ListItemText, useListContext } from '../../../List';
|
|
8
|
+
import { DATA_LIST_OPTION_DEFAULT_DISABLED } from '../../constants';
|
|
9
|
+
import { DataListCheckIcon } from '../DataListCheckIcon';
|
|
10
|
+
export var cnDataListOption = cn('DataListOption');
|
|
11
|
+
var DataListContent = function (_a) {
|
|
12
|
+
var label = _a.label, selected = _a.selected;
|
|
13
|
+
var size = useListContext().size;
|
|
14
|
+
var iconSize = getIconSizeToFormElement(size);
|
|
15
|
+
return (React.createElement(React.Fragment, null,
|
|
16
|
+
React.createElement(ListItemText, { className: cnDataListOption('Text'), primary: label }),
|
|
17
|
+
React.createElement(DataListCheckIcon, { selected: selected, size: iconSize })));
|
|
18
|
+
};
|
|
19
|
+
export var DataListOption = forwardRef(function (_a, ref) {
|
|
20
|
+
var _b = _a.disabled, disabled = _b === void 0 ? DATA_LIST_OPTION_DEFAULT_DISABLED : _b, value = _a.value, label = _a.label, children = _a.children, className = _a.className, highlighted = _a.highlighted, selected = _a.selected, focused = _a.focused, other = __rest(_a, ["disabled", "value", "label", "children", "className", "highlighted", "selected", "focused"]);
|
|
21
|
+
var renderChildren = function () {
|
|
22
|
+
if (isString(children)) {
|
|
23
|
+
return React.createElement(DataListContent, { label: children, selected: selected });
|
|
24
|
+
}
|
|
25
|
+
if (label && !children) {
|
|
26
|
+
return React.createElement(DataListContent, { label: label, selected: selected });
|
|
27
|
+
}
|
|
28
|
+
return children;
|
|
29
|
+
};
|
|
30
|
+
return (React.createElement(ListItem, __assign({ role: "option", "aria-selected": selected, "aria-disabled": disabled, "data-label": label, "data-value": value, className: cnDataListOption({
|
|
31
|
+
disabled: disabled,
|
|
32
|
+
highlighted: !disabled && highlighted,
|
|
33
|
+
focused: !disabled && focused,
|
|
34
|
+
}, [className]) }, other, { ref: ref }), renderChildren()));
|
|
35
|
+
});
|
|
36
|
+
DataListOption.displayName = 'DataListOption';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DataListOption';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DataListOption';
|
|
@@ -2,3 +2,4 @@ export declare const DATA_LIST_DEFAULT_TAG: import("../../utils/polymorphicCompo
|
|
|
2
2
|
export declare const DATA_LIST_DEFAULT_SIZE = "m";
|
|
3
3
|
export declare const DATA_LIST_DEFAULT_OPEN = false;
|
|
4
4
|
export declare const DATA_LIST_OPTION_DEFAULT_DISABLED = false;
|
|
5
|
+
export declare const DATA_LIST_OPTION_DEFAULT_TAG = "li";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { LIST_ITEM_DEFAULT_TAG } from '../List/constants';
|
|
1
2
|
import { Paper } from '../Paper';
|
|
2
3
|
export var DATA_LIST_DEFAULT_TAG = Paper;
|
|
3
4
|
export var DATA_LIST_DEFAULT_SIZE = 'm';
|
|
4
5
|
export var DATA_LIST_DEFAULT_OPEN = false;
|
|
5
6
|
export var DATA_LIST_OPTION_DEFAULT_DISABLED = false;
|
|
7
|
+
export var DATA_LIST_OPTION_DEFAULT_TAG = LIST_ITEM_DEFAULT_TAG;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const lastSelectedValue: <T>(selected: T) => any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DataListBaseProps, DataListSelected } from '../index';
|
|
2
|
+
export type SetSelect<MULTIPLE extends boolean> = (newValue: DataListSelected<MULTIPLE>) => void;
|
|
3
|
+
export type SelectedParams<MULTIPLE extends boolean = false> = {
|
|
4
|
+
multiple: DataListBaseProps<MULTIPLE>['multiple'];
|
|
5
|
+
onSelect: DataListBaseProps<MULTIPLE>['onSelect'];
|
|
6
|
+
selected: DataListSelected<MULTIPLE>;
|
|
7
|
+
setSelected: SetSelect<MULTIPLE>;
|
|
8
|
+
};
|
|
9
|
+
export declare const isMultipleParams: (params: SelectedParams<boolean>) => params is SelectedParams<true>;
|
|
10
|
+
export declare const isNotMultipleParams: (params: SelectedParams<boolean>) => params is SelectedParams<false>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MouseEvent } from 'react';
|
|
2
|
+
export type UseListNavigationItem = string | number | null;
|
|
3
|
+
export type UseListNavigationItems = UseListNavigationItem[];
|
|
4
|
+
export type UseListNavigationProps = {
|
|
5
|
+
active?: boolean;
|
|
6
|
+
items?: UseListNavigationItems;
|
|
7
|
+
current?: UseListNavigationItem;
|
|
8
|
+
onSelect?: (event: KeyboardEvent | MouseEvent<HTMLElement>, item?: UseListNavigationItem) => void;
|
|
9
|
+
};
|
|
10
|
+
export type UseListNavigationState = {
|
|
11
|
+
focused?: UseListNavigationItem;
|
|
12
|
+
selected?: UseListNavigationItem;
|
|
13
|
+
highlighted?: UseListNavigationItem;
|
|
14
|
+
};
|
|
15
|
+
export type UseListNavigationEvents = {
|
|
16
|
+
onMouseLeave?: () => void;
|
|
17
|
+
onKeyDown?: (event: KeyboardEvent) => void;
|
|
18
|
+
onClick?: (event: MouseEvent<HTMLElement>, item: UseListNavigationItem) => void;
|
|
19
|
+
onMouseEnter?: (item: UseListNavigationItem) => void;
|
|
20
|
+
};
|
|
21
|
+
export type UseListNavigationReturn = UseListNavigationState & UseListNavigationEvents;
|
|
22
|
+
/** Навигация по элементам списка без перехвата фокуса с элемента контроля */
|
|
23
|
+
export declare function useDataListNavigation({ current, onSelect, active, items: itemsProps, }: UseListNavigationProps): UseListNavigationReturn;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { __assign, __read } from "tslib";
|
|
2
|
+
import { useEffect, useState, useRef } from 'react';
|
|
3
|
+
import { getNextIndex } from '../../../utils/getNextIndex';
|
|
4
|
+
import { getPrevIndex } from '../../../utils/getPrevIndex';
|
|
5
|
+
import { isKey } from '../../../utils/isKey';
|
|
6
|
+
/** Навигация по элементам списка без перехвата фокуса с элемента контроля */
|
|
7
|
+
export function useDataListNavigation(_a) {
|
|
8
|
+
var current = _a.current, onSelect = _a.onSelect, _b = _a.active, active = _b === void 0 ? false : _b, itemsProps = _a.items;
|
|
9
|
+
var savedItems = useRef(itemsProps);
|
|
10
|
+
var savedOnSelect = useRef();
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
savedItems.current = itemsProps;
|
|
13
|
+
}, [itemsProps]);
|
|
14
|
+
useEffect(function () {
|
|
15
|
+
savedOnSelect.current = onSelect;
|
|
16
|
+
}, [onSelect]);
|
|
17
|
+
var _c = __read(useState({}), 2), state = _c[0], setState = _c[1];
|
|
18
|
+
var findInItems = function (value) { var _a; return (_a = savedItems.current) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item === value; }); };
|
|
19
|
+
// Актуализирует состояние при каждом изменении текущего значения
|
|
20
|
+
useEffect(function () {
|
|
21
|
+
if (active) {
|
|
22
|
+
setState(function (prevState) {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
return (__assign(__assign({}, prevState), { focused: (_a = findInItems(prevState.focused)) !== null && _a !== void 0 ? _a : null, selected: (_b = findInItems(current)) !== null && _b !== void 0 ? _b : (_c = savedItems.current) === null || _c === void 0 ? void 0 : _c[0] }));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}, [active, current]);
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
if (!active) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
// Инициализация всех событий
|
|
33
|
+
var onMouseLeave = function () {
|
|
34
|
+
setState(function (prevState) { return (__assign(__assign({}, prevState), { highlighted: null })); });
|
|
35
|
+
};
|
|
36
|
+
var onMouseEnter = function (item) {
|
|
37
|
+
setState(function (prevState) { return (__assign(__assign({}, prevState), { highlighted: item })); });
|
|
38
|
+
};
|
|
39
|
+
var onClick = function (event, item) {
|
|
40
|
+
var _a;
|
|
41
|
+
setState(function (prevState) { return (__assign(__assign({}, prevState), { focused: item === prevState.focused ? item : null, selected: item })); });
|
|
42
|
+
(_a = savedOnSelect.current) === null || _a === void 0 ? void 0 : _a.call(savedOnSelect, event, item);
|
|
43
|
+
};
|
|
44
|
+
var onKeyDown = function (event) {
|
|
45
|
+
var _a;
|
|
46
|
+
if (isKey(event, 'Enter')) {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
var selected_1;
|
|
49
|
+
setState(function (prevState) {
|
|
50
|
+
var _a;
|
|
51
|
+
selected_1 = (_a = prevState.focused) !== null && _a !== void 0 ? _a : prevState.selected;
|
|
52
|
+
return __assign(__assign({}, prevState), { selected: selected_1, focused: selected_1 });
|
|
53
|
+
});
|
|
54
|
+
(_a = savedOnSelect.current) === null || _a === void 0 ? void 0 : _a.call(savedOnSelect, event, selected_1);
|
|
55
|
+
}
|
|
56
|
+
if (!isKey(event, 'ArrowUp') && !isKey(event, 'ArrowDown')) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
setState(function (prevState) {
|
|
61
|
+
var _a, _b, _c, _d, _e;
|
|
62
|
+
var selected = (_a = prevState.focused) !== null && _a !== void 0 ? _a : prevState.selected;
|
|
63
|
+
var currentIndex = typeof selected !== 'undefined'
|
|
64
|
+
? (_b = savedItems.current) === null || _b === void 0 ? void 0 : _b.indexOf(selected)
|
|
65
|
+
: null;
|
|
66
|
+
var isArrowUp = isKey(event, 'ArrowUp');
|
|
67
|
+
var newIndex = isArrowUp
|
|
68
|
+
? getPrevIndex(currentIndex !== null && currentIndex !== void 0 ? currentIndex : 0, ((_c = savedItems.current) === null || _c === void 0 ? void 0 : _c.length) || 0)
|
|
69
|
+
: getNextIndex(currentIndex !== null && currentIndex !== void 0 ? currentIndex : -1, ((_d = savedItems.current) === null || _d === void 0 ? void 0 : _d.length) || 0);
|
|
70
|
+
var newItem = (_e = savedItems.current) === null || _e === void 0 ? void 0 : _e[newIndex];
|
|
71
|
+
return __assign(__assign({}, prevState), { focused: newItem });
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
setState(function (prevState) { return (__assign(__assign({}, prevState), { onClick: onClick, onKeyDown: onKeyDown, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave })); });
|
|
75
|
+
return function () {
|
|
76
|
+
// Сброс
|
|
77
|
+
setState({});
|
|
78
|
+
};
|
|
79
|
+
}, [active]);
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { ScrollContainerToElement } from '../../../utils/scrollContainerToElement';
|
|
3
|
+
export declare function useScrollContainerToElement(container: RefObject<HTMLElement>, element: RefObject<HTMLElement>, behavior?: ScrollContainerToElement['behavior']): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { scrollContainerToElement } from '../../../utils/scrollContainerToElement';
|
|
3
|
+
export function useScrollContainerToElement(container, element, behavior) {
|
|
4
|
+
useEffect(function () {
|
|
5
|
+
scrollContainerToElement({
|
|
6
|
+
container: container.current,
|
|
7
|
+
element: element.current,
|
|
8
|
+
behavior: behavior,
|
|
9
|
+
});
|
|
10
|
+
}, [container, element]);
|
|
11
|
+
}
|
|
@@ -5,11 +5,12 @@ import type { PolymorphicComponentPropsWithRef, PolymorphicComponentRef } from '
|
|
|
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 DataListValue = string | number;
|
|
9
|
+
export type DataListSelected<MULTIPLE extends boolean> = (MULTIPLE extends true ? DataListValue[] : DataListValue) | undefined;
|
|
8
10
|
export type DataListPayload<MULTIPLE extends boolean> = {
|
|
9
11
|
name?: string;
|
|
10
|
-
value: MULTIPLE
|
|
12
|
+
value: DataListSelected<MULTIPLE>;
|
|
11
13
|
};
|
|
12
|
-
export type DataListSelected<MULTIPLE extends boolean> = (MULTIPLE extends true ? string[] : string) | undefined;
|
|
13
14
|
export type DataListOnSelect<MULTIPLE extends boolean> = (event: React.SyntheticEvent | KeyboardEvent, payload: DataListPayload<MULTIPLE>) => void;
|
|
14
15
|
export type DataListBaseProps<MULTIPLE extends boolean = false> = {
|
|
15
16
|
/** Имя списка */
|
|
@@ -33,8 +34,6 @@ export type DataListBaseProps<MULTIPLE extends boolean = false> = {
|
|
|
33
34
|
/** Свойства компонента List */
|
|
34
35
|
listProps?: ListProps;
|
|
35
36
|
} & 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
37
|
export type DataListRef = PolymorphicComponentRef<typeof DATA_LIST_DEFAULT_TAG>;
|
|
39
38
|
export type DataListProps<As extends ElementType = typeof DATA_LIST_DEFAULT_TAG, MULTIPLE extends boolean = false> = PolymorphicComponentPropsWithRef<DataListBaseProps<MULTIPLE>, As>;
|
|
40
39
|
export type DataListComponent = <As extends ElementType = typeof DATA_LIST_DEFAULT_TAG, MULTIPLE extends boolean = false>(props: PolymorphicComponentPropsWithRef<DataListBaseProps<MULTIPLE>, As>) => React.ReactElement | null;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export var isNotMultipleParams = function (params) { return !params.multiple; };
|
|
1
|
+
export {};
|
|
@@ -18,7 +18,7 @@ export var Input = forwardRef(function (inProps, ref) {
|
|
|
18
18
|
props: inProps,
|
|
19
19
|
name: 'Input',
|
|
20
20
|
});
|
|
21
|
-
var _a = props.size, size = _a === void 0 ? 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,
|
|
21
|
+
var _a = props.size, size = _a === void 0 ? 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, fullWidth = props.fullWidth, disabled = props.disabled, hint = props.hint, required = props.required, className = props.className, value = props.value, defaultValue = props.defaultValue, onChange = props.onChange, inputProps = props.inputProps, bodyProps = props.bodyProps, labelProps = props.labelProps, inputRef = props.inputRef, labelRef = props.labelRef, other = __rest(props, ["size", "label", "error", "autoFocus", "placeholder", "id", "name", "type", "renderLeft", "renderRight", "fullWidth", "disabled", "hint", "required", "className", "value", "defaultValue", "onChange", "inputProps", "bodyProps", "labelProps", "inputRef", "labelRef"]);
|
|
22
22
|
var bodyInnerRef = useRef(null);
|
|
23
23
|
var fieldInnerRef = useRef(null);
|
|
24
24
|
/* Хук useEventListener необходим для того, чтобы при нажатии на кнопку мыши
|
|
@@ -8,12 +8,13 @@ export type InputTypeVariant = (typeof inputTypeVariant)[number];
|
|
|
8
8
|
export type InputSizeVariant = FormElementSizeVariant;
|
|
9
9
|
type InputPropsDeprecated = {
|
|
10
10
|
/**
|
|
11
|
-
* deprecated
|
|
12
11
|
* Ссылка на FieldLabel
|
|
12
|
+
* @deprecated Используйте labelProps.ref
|
|
13
13
|
* */
|
|
14
14
|
labelRef?: FieldLabelProps['ref'];
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
16
|
* Ссылка на элемент input
|
|
17
|
+
* @deprecated Используйте inputProps.ref
|
|
17
18
|
* */
|
|
18
19
|
inputRef?: Ref<HTMLInputElement>;
|
|
19
20
|
};
|