@cloud-ru/ds-list 2.3.6 → 2.3.7-preview-d9442369.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/README.md +6 -0
- package/dist/cjs/components/Items/BaseItem/BaseItem.js +59 -8
- package/dist/cjs/components/Items/BaseItem/styles.module.css +9 -9
- package/dist/cjs/components/Lists/List/List.js +2 -2
- package/dist/cjs/components/Lists/contexts/NewListProvider.d.ts +87 -4
- package/dist/cjs/components/Lists/contexts/NewListProvider.js +34 -4
- package/dist/cjs/helperComponents/DesktopDroplist/DesktopDroplist.d.ts +1 -1
- package/dist/cjs/helperComponents/DesktopDroplist/DesktopDroplist.js +2 -2
- package/dist/cjs/helperComponents/MobileDroplist/MobileDroplist.js +5 -0
- package/dist/cjs/helperComponents/Separator/Separator.js +14 -1
- package/dist/cjs/style.css +9 -9
- package/dist/esm/components/Items/BaseItem/BaseItem.js +60 -9
- package/dist/esm/components/Items/BaseItem/styles.module.css +9 -9
- package/dist/esm/components/Lists/List/List.js +2 -2
- package/dist/esm/components/Lists/contexts/NewListProvider.d.ts +87 -4
- package/dist/esm/components/Lists/contexts/NewListProvider.js +35 -5
- package/dist/esm/helperComponents/DesktopDroplist/DesktopDroplist.d.ts +1 -1
- package/dist/esm/helperComponents/DesktopDroplist/DesktopDroplist.js +2 -2
- package/dist/esm/helperComponents/MobileDroplist/MobileDroplist.js +5 -0
- package/dist/esm/helperComponents/Separator/Separator.js +15 -2
- package/dist/esm/style.css +9 -9
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +18 -18
- package/src/components/Items/BaseItem/BaseItem.tsx +134 -55
- package/src/components/Items/BaseItem/styles.module.scss +16 -16
- package/src/components/Lists/List/List.tsx +4 -0
- package/src/components/Lists/contexts/NewListProvider.tsx +137 -6
- package/src/helperComponents/DesktopDroplist/DesktopDroplist.tsx +4 -0
- package/src/helperComponents/MobileDroplist/MobileDroplist.tsx +5 -0
- package/src/helperComponents/Separator/Separator.tsx +19 -1
package/README.md
CHANGED
|
@@ -589,9 +589,11 @@ export function ListItemWrap() {
|
|
|
589
589
|
| `footer` | `ReactNode ;` | — | Кастомизируемый элемент в конце списка |
|
|
590
590
|
| `footerActiveElementsRefs` | `RefObject<HTMLElement>[]` | — | Список ссылок на кастомные элементы, помещенные в специальную секцию внизу списка |
|
|
591
591
|
| `footerDivider` | `boolean` | — | Показывать divider между body и footer (Figma `dropdownContainer.dividerWrapper` снизу) |
|
|
592
|
+
| `groupItemRender` | `((props: GroupItemRenderProps) => ReactNode)` | — | Рендер-функция заголовка группы вместо дефолтной разметки `Separator`. <br/> Не задана — заголовок/разделитель рисуются как раньше. |
|
|
592
593
|
| `hasListInFocusChain` | `boolean` | `true` | Флаг, отвечающий за включение самого родительского контейнера листа в цепочку фокусирующихся элементов |
|
|
593
594
|
| `header` | `ReactNode ;` | — | Кастомизируемый элемент в начале списка — Figma `dropdownContainer.topBar`. <br/> Подходит для заголовка / справочного блока над поиском. |
|
|
594
595
|
| `headerDivider` | `boolean` | — | Показывать divider между header и body (Figma `dropdownContainer.dividerWrapper` сверху) |
|
|
596
|
+
| `itemRender` | `((props: ItemRenderProps) => ReactNode)` | — | Рендер-функция оболочки строки вместо дефолтной разметки `BaseItem`. <br/> Не задана — строка рисуется как раньше. `itemWrapRender` по-прежнему оборачивает результат. |
|
|
595
597
|
| `items` | `Item[]` | `[]` | Основные элементы списка |
|
|
596
598
|
| `keyboardNavigationRef` | `RefObject<{ focusItem(id: ItemId): void; }>` | — | Ссылка на управление навигацией листа с клавиатуры |
|
|
597
599
|
| `limitedScrollHeight` | `boolean` | — | Ограничить максимальную высоту скролл-контейнера в зависимости от `size` |
|
|
@@ -958,8 +960,10 @@ export function DroplistWithHeader() {
|
|
|
958
960
|
| `footer` | `ReactNode ;` | — | Кастомизируемый элемент в конце списка |
|
|
959
961
|
| `footerActiveElementsRefs` | `RefObject<HTMLElement>[]` | — | Список ссылок на кастомные элементы, помещенные в специальную секцию внизу списка |
|
|
960
962
|
| `footerDivider` | `boolean` | — | Показывать divider между body и footer (Figma `dropdownContainer.dividerWrapper` снизу) |
|
|
963
|
+
| `groupItemRender` | `((props: GroupItemRenderProps) => ReactNode)` | — | Рендер-функция заголовка группы вместо дефолтной разметки `Separator`. <br/> Не задана — заголовок/разделитель рисуются как раньше. |
|
|
961
964
|
| `header` | `ReactNode ;` | — | Кастомизируемый элемент в начале списка — Figma `dropdownContainer.topBar`. <br/> Подходит для заголовка / справочного блока над поиском. |
|
|
962
965
|
| `headerDivider` | `boolean` | — | Показывать divider между header и body (Figma `dropdownContainer.dividerWrapper` сверху) |
|
|
966
|
+
| `itemRender` | `((props: ItemRenderProps) => ReactNode)` | — | Рендер-функция оболочки строки вместо дефолтной разметки `BaseItem`. <br/> Не задана — строка рисуется как раньше. `itemWrapRender` по-прежнему оборачивает результат. |
|
|
963
967
|
| `items` | `BaseItemWithoutNonGroup` \| `CommonGroupItem` \| `Item` \| `ScrollProps` | — | Основные элементы списка |
|
|
964
968
|
| `label` | `string` | — | Только mobile (`BottomSheet`): заголовок шапки. |
|
|
965
969
|
| `limitedScrollHeight` | `boolean` | — | Ограничить максимальную высоту скролл-контейнера в зависимости от `size` |
|
|
@@ -1475,9 +1479,11 @@ export function ListReorder() {
|
|
|
1475
1479
|
| `footer` | `ReactNode ;` | — | Кастомизируемый элемент в конце списка |
|
|
1476
1480
|
| `footerActiveElementsRefs` | `RefObject<HTMLElement>[]` | — | Список ссылок на кастомные элементы, помещенные в специальную секцию внизу списка |
|
|
1477
1481
|
| `footerDivider` | `boolean` | — | Показывать divider между body и footer (Figma `dropdownContainer.dividerWrapper` снизу) |
|
|
1482
|
+
| `groupItemRender` | `((props: GroupItemRenderProps) => ReactNode)` | — | Рендер-функция заголовка группы вместо дефолтной разметки `Separator`. <br/> Не задана — заголовок/разделитель рисуются как раньше. |
|
|
1478
1483
|
| `hasListInFocusChain` | `boolean` | `true` | Флаг, отвечающий за включение самого родительского контейнера листа в цепочку фокусирующихся элементов |
|
|
1479
1484
|
| `header` | `ReactNode ;` | — | Кастомизируемый элемент в начале списка — Figma `dropdownContainer.topBar`. <br/> Подходит для заголовка / справочного блока над поиском. |
|
|
1480
1485
|
| `headerDivider` | `boolean` | — | Показывать divider между header и body (Figma `dropdownContainer.dividerWrapper` сверху) |
|
|
1486
|
+
| `itemRender` | `((props: ItemRenderProps) => ReactNode)` | — | Рендер-функция оболочки строки вместо дефолтной разметки `BaseItem`. <br/> Не задана — строка рисуется как раньше. `itemWrapRender` по-прежнему оборачивает результат. |
|
|
1481
1487
|
| `items` | `ReorderItem[]` | `[]` | Основные элементы списка: строки `SimpleItem` и/или группы с заголовком `SimpleGroupItem` <br/> (`type: 'group'` + `label` + сортируемые `items`). |
|
|
1482
1488
|
| `keyboardNavigationRef` | `RefObject<{ focusItem(id: ItemId): void; }>` | — | Ссылка на управление навигацией листа с клавиатуры |
|
|
1483
1489
|
| `limitedScrollHeight` | `boolean` | — | Ограничить максимальную высоту скролл-контейнера в зависимости от `size` |
|
|
@@ -17,7 +17,7 @@ const constants_2 = require("./constants");
|
|
|
17
17
|
const styles_module_scss_2 = __importDefault(require('./styles.module.css'));
|
|
18
18
|
function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, showSwitchIcon, onKeyDown, onFocus, indeterminate, checked: checkedProp, onSelect, onOpenNestedList, onToggleExpand, onExpandIconClick, isParentNode, className, inactive, itemWrapRender, dragHandle, ...rest }) {
|
|
19
19
|
const interactive = !inactive;
|
|
20
|
-
const { size = constants_1.DEFAULT_SIZE, marker, contentRender, firstItemId, focusFlattenItems } = (0, contexts_1.useNewListContext)();
|
|
20
|
+
const { size = constants_1.DEFAULT_SIZE, marker, contentRender, itemRender, firstItemId, focusFlattenItems, } = (0, contexts_1.useNewListContext)();
|
|
21
21
|
const { level = 0 } = (0, contexts_1.useCollapseLevelContext)();
|
|
22
22
|
const { closeDroplist, closeDroplistOnItemClick } = (0, contexts_1.useOpenListContext)();
|
|
23
23
|
const { value, onChange, mode, isSelectionSingle, isSelectionMultiple } = (0, contexts_1.useSelectionContext)();
|
|
@@ -105,25 +105,76 @@ function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown,
|
|
|
105
105
|
};
|
|
106
106
|
const props = (0, utils_1.extractSupportProps)(rest);
|
|
107
107
|
let contentNode;
|
|
108
|
+
let contentFromRender = Boolean(contentRender);
|
|
108
109
|
if (content && (0, utils_2.isContentItem)(content)) {
|
|
109
110
|
contentNode = contentRender?.({ id, content, disabled }) ?? (0, jsx_runtime_1.jsx)(helperComponents_1.ItemContent, { disabled: disabled, ...content });
|
|
110
111
|
}
|
|
111
112
|
else if ((0, utils_2.isPrimitiveContent)(content)) {
|
|
112
113
|
// Примитивный content — шорткат `{ label: content }`: рендерим через ItemContent,
|
|
113
114
|
// чтобы строка получила размерную высоту, а не схлопывалась до высоты текста.
|
|
114
|
-
|
|
115
|
+
const primitiveContent = { label: content };
|
|
116
|
+
contentNode = contentRender?.({ id, content: primitiveContent, disabled }) ?? ((0, jsx_runtime_1.jsx)(helperComponents_1.ItemContent, { disabled: disabled, label: content }));
|
|
115
117
|
}
|
|
116
118
|
else {
|
|
117
|
-
contentNode = (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_2.default.content, children: [" ", content, " "] });
|
|
119
|
+
contentNode = contentRender?.({ id, content, disabled }) ?? (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_2.default.content, children: [" ", content, " "] });
|
|
120
|
+
// Неструктурный content оболочка не разберёт на label/caption — отдаём готовый узел.
|
|
121
|
+
contentFromRender = true;
|
|
118
122
|
}
|
|
119
123
|
const stateLayerState = isSelectionSingle && isChecked && !switchProp && !isParentNode
|
|
120
124
|
? 'activatedOnBackground'
|
|
121
125
|
: 'emptyNeutralOnBackground';
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
const dataTestId = (typeof props['data-test-id'] === 'string' ? props['data-test-id'] : undefined) || `${constants_1.TEST_IDS.baseItem}_${id}`;
|
|
127
|
+
const tabIndex = firstItemId && id === focusFlattenItems[firstItemId]?.originalId ? 0 : -1;
|
|
128
|
+
const dragHandleNode = dragHandle ? (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.dragHandle, children: dragHandle }) : undefined;
|
|
129
|
+
// Маркер/чекбокс/шеврон-обёртка нужны только дефолтной разметке; при `itemRender`
|
|
130
|
+
// оболочка рисует индикаторы сама по `selectionMode`.
|
|
131
|
+
const markerNode = !itemRender && !switchProp && isSelectionSingle && marker && !isParentNode && interactive ? ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.markerContainer, "data-test-id": constants_1.TEST_IDS.baseItemMarker, "data-checked": isChecked || undefined, "data-disabled": disabled || undefined })) : undefined;
|
|
132
|
+
const checkboxNode = !itemRender && !switchProp && isSelectionMultiple && interactive ? ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.checkbox, children: (0, jsx_runtime_1.jsx)(toggles_1.Checkbox, { size: constants_2.TOGGLE_SIZE_MAP[size], disabled: disabled, tabIndex: -1, onChange: isParentNode ? handleCheckboxChange : undefined, checked: isChecked, "data-test-id": constants_1.TEST_IDS.baseItemCheckbox, onClick: handleCheckboxClick, indeterminate: indeterminate }) })) : undefined;
|
|
133
|
+
const switchControlNode = switchProp && interactive ? ((0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_2.default.switchWrapper, children: (0, jsx_runtime_1.jsx)(toggles_1.Switch, { size: constants_2.TOGGLE_SIZE_MAP[size], disabled: disabled, checked: isChecked, "data-test-id": constants_1.TEST_IDS.baseItemSwitch, showIcon: showSwitchIcon }) })) : undefined;
|
|
134
|
+
const expandIconNode = !itemRender && !switchProp && expandIcon ? (
|
|
135
|
+
// Интерактивный шеврон не получает роль и фокус намеренно: клавиатурный путь идёт
|
|
136
|
+
// через строку, у неё же живёт `aria-expanded`. Лишний таб-стоп сломал бы порядок
|
|
137
|
+
// фокуса списка, а озвучивать AT недостижимый с клавиатуры элемент незачем.
|
|
138
|
+
(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_2.default.groupIndicator, "data-open": open || undefined, "data-interactive": Boolean(onExpandIconClick) || undefined, "data-test-id": constants_1.TEST_IDS.groupIndicator, onClick: onExpandIconClick && handleExpandIconClick, "aria-hidden": true, children: expandIcon })) : undefined;
|
|
139
|
+
const isRowChecked = Boolean((isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp));
|
|
140
|
+
let selectionMode = constants_1.MODE.None;
|
|
141
|
+
if (isSelectionMultiple) {
|
|
142
|
+
selectionMode = constants_1.MODE.Multiple;
|
|
143
|
+
}
|
|
144
|
+
else if (isSelectionSingle) {
|
|
145
|
+
selectionMode = constants_1.MODE.Single;
|
|
146
|
+
}
|
|
147
|
+
const itemJSX = itemRender ? (itemRender({
|
|
148
|
+
id,
|
|
149
|
+
content,
|
|
150
|
+
contentNode,
|
|
151
|
+
contentFromRender,
|
|
152
|
+
beforeContent,
|
|
153
|
+
afterContent,
|
|
154
|
+
dragHandle: dragHandleNode,
|
|
155
|
+
switchControl: switchControlNode,
|
|
156
|
+
// Сырой слот: обёртку centeredWrapper/groupIndicator рисует кастомная оболочка.
|
|
157
|
+
expandIcon: !switchProp && expandIcon ? expandIcon : undefined,
|
|
158
|
+
selectionMode,
|
|
159
|
+
disabled,
|
|
160
|
+
inactive,
|
|
161
|
+
checked: isRowChecked,
|
|
162
|
+
open,
|
|
163
|
+
isParentNode,
|
|
164
|
+
size,
|
|
165
|
+
level,
|
|
166
|
+
className,
|
|
167
|
+
itemRef: itemRef,
|
|
168
|
+
tabIndex,
|
|
169
|
+
'data-test-id': dataTestId,
|
|
170
|
+
style: { '--level': level },
|
|
171
|
+
onClick: handleItemClick,
|
|
172
|
+
onMouseDown: handleItemMouseDown,
|
|
173
|
+
onKeyDown: handleItemKeyDown,
|
|
174
|
+
onFocus: handleItemFocus,
|
|
175
|
+
onExpandIconClick: onExpandIconClick ? handleExpandIconClick : undefined,
|
|
176
|
+
expandIconInteractive: Boolean(onExpandIconClick),
|
|
177
|
+
})) : ((0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)(styles_module_scss_1.default.itemWrapper, styles_module_scss_2.default.innerWrapper, className), "data-size": size, "data-inactive": inactive || undefined, "data-disabled": disabled || undefined, "data-variant": mode || undefined, "data-checked": (isParentNode && isChecked) || (!isParentNode && isChecked && !switchProp) || undefined, children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.stateLayer, "aria-hidden": true, "data-state": stateLayerState }), (0, jsx_runtime_1.jsxs)("li", { "data-type": 'outside', role: 'menuitem', "data-test-id": dataTestId, ref: itemRef, className: (0, classnames_1.default)(styles_module_scss_1.default.listItem, styles_module_scss_2.default.droplistItem), "data-size": size, onClick: handleItemClick, onMouseDown: handleItemMouseDown, tabIndex: tabIndex, "data-non-pointer": (inactive && !onClick) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "aria-expanded": isParentNode ? Boolean(open) : undefined, onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, "data-level-one": level === 1 || undefined, "data-level-more-one": level > 1 || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, children: [dragHandleNode, markerNode, checkboxNode, (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_2.default.contentWrapper, children: [beforeContent && (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.beforeContent, children: beforeContent }), contentNode, afterContent && (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.afterContent, children: afterContent })] }), switchControlNode, expandIconNode] })] }));
|
|
127
178
|
if (!itemWrapRender) {
|
|
128
179
|
return itemJSX;
|
|
129
180
|
}
|
|
@@ -89,6 +89,15 @@
|
|
|
89
89
|
width:100%;
|
|
90
90
|
height:100%;
|
|
91
91
|
}
|
|
92
|
+
.markerContainer[data-checked]::before{
|
|
93
|
+
background-color:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-50, #222222));
|
|
94
|
+
}
|
|
95
|
+
.markerContainer[data-checked][data-disabled]{
|
|
96
|
+
opacity:var(--sn-theme-effect-opacity-disabled, 0.4);
|
|
97
|
+
}
|
|
98
|
+
.markerContainer[data-checked][data-disabled]::before{
|
|
99
|
+
background-color:var(--sn-theme-color-neutral-accent, var(--sn-brand-color-neutral-50, var(--sn-brand-palette-gray-50, #222222)));
|
|
100
|
+
}
|
|
92
101
|
|
|
93
102
|
.droplistItem{
|
|
94
103
|
position:relative;
|
|
@@ -262,18 +271,9 @@
|
|
|
262
271
|
.innerWrapper[data-disabled] .droplistItem{
|
|
263
272
|
cursor:not-allowed;
|
|
264
273
|
}
|
|
265
|
-
.innerWrapper[data-has-checked] .markerContainer::before, .innerWrapper[data-checked] .markerContainer::before{
|
|
266
|
-
background-color:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-50, #222222));
|
|
267
|
-
}
|
|
268
274
|
.innerWrapper[data-has-checked] .droplistItem:focus-visible, .innerWrapper[data-checked] .droplistItem:focus-visible{
|
|
269
275
|
outline-color:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-50, #222222));
|
|
270
276
|
}
|
|
271
|
-
.innerWrapper[data-has-checked][data-disabled] .markerContainer, .innerWrapper[data-checked][data-disabled] .markerContainer{
|
|
272
|
-
opacity:var(--sn-theme-effect-opacity-disabled, 0.4);
|
|
273
|
-
}
|
|
274
|
-
.innerWrapper[data-has-checked][data-disabled] .markerContainer::before, .innerWrapper[data-checked][data-disabled] .markerContainer::before{
|
|
275
|
-
background-color:var(--sn-theme-color-neutral-accent, var(--sn-brand-color-neutral-50, var(--sn-brand-palette-gray-50, #222222)));
|
|
276
|
-
}
|
|
277
277
|
|
|
278
278
|
.content{
|
|
279
279
|
overflow:hidden;
|
|
@@ -16,7 +16,7 @@ const hooks_1 = require("../hooks");
|
|
|
16
16
|
const ListPrivate_1 = require("../ListPrivate");
|
|
17
17
|
const styles_module_scss_1 = __importDefault(require('../styles.module.css'));
|
|
18
18
|
const EMPTY_ITEMS = [];
|
|
19
|
-
const ListImpl = (0, react_1.forwardRef)(({ items: itemsProp = EMPTY_ITEMS, search, pinBottom: pinBottomProp = EMPTY_ITEMS, pinTop: pinTopProp = EMPTY_ITEMS, footerActiveElementsRefs, onKeyDown, tabIndex = 0, className, collapse = {}, selection, contentRender, size = constants_1.DEFAULT_SIZE, marker = true, keyboardNavigationRef, hasListInFocusChain = true, onItemsReorder, ...props }, ref) => {
|
|
19
|
+
const ListImpl = (0, react_1.forwardRef)(({ items: itemsProp = EMPTY_ITEMS, search, pinBottom: pinBottomProp = EMPTY_ITEMS, pinTop: pinTopProp = EMPTY_ITEMS, footerActiveElementsRefs, onKeyDown, tabIndex = 0, className, collapse = {}, selection, contentRender, itemRender, groupItemRender, size = constants_1.DEFAULT_SIZE, marker = true, keyboardNavigationRef, hasListInFocusChain = true, onItemsReorder, ...props }, ref) => {
|
|
20
20
|
const { openCollapseItems, toggleOpenCollapseItem, searchItem, flattenItems, focusFlattenItems, memorizedItems, ids, expandedIds, firstItemId, onDragEnd, sortableIds, } = (0, hooks_1.useListItemsModel)({
|
|
21
21
|
items: itemsProp,
|
|
22
22
|
pinTop: pinTopProp,
|
|
@@ -48,7 +48,7 @@ const ListImpl = (0, react_1.forwardRef)(({ items: itemsProp = EMPTY_ITEMS, sear
|
|
|
48
48
|
};
|
|
49
49
|
const collapseContextValue = (0, react_1.useMemo)(() => ({ openCollapseItems, toggleOpenCollapseItem, toggleOn: collapse.toggleOn }), [openCollapseItems, toggleOpenCollapseItem, collapse.toggleOn]);
|
|
50
50
|
const focusListContextValue = (0, react_1.useMemo)(() => ({ activeItemId, handleListKeyDownFactory, forceUpdateActiveItemId }), [activeItemId, handleListKeyDownFactory, forceUpdateActiveItemId]);
|
|
51
|
-
return ((0, jsx_runtime_1.jsx)(contexts_1.NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, firstItemId: firstItemId, virtualized: props.virtualized, children: (0, jsx_runtime_1.jsx)(contexts_1.SelectionProvider, { ...selection, children: (0, jsx_runtime_1.jsx)(contexts_1.CollapseContext.Provider, { value: collapseContextValue, children: (0, jsx_runtime_1.jsx)(contexts_1.FocusListContext.Provider, { value: focusListContextValue, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)(styles_module_scss_1.default.wrapper, className), "data-active": isActive || undefined, children: [(0, jsx_runtime_1.jsx)(ListPrivate_1.ListPrivate, { ...props, items: memorizedItems.items.focusCloseChildIds, pinTop: memorizedItems.pinTop.focusCloseChildIds, pinBottom: memorizedItems.pinBottom.focusCloseChildIds, searchItem: searchItem, ref: (0, merge_refs_1.default)(ref, listRef), onFocus: handleOnFocus, onKeyDown: mergedHandlerKeyDown, tabIndex: hasListInFocusChain ? tabIndex : undefined, search: search, nested: false, onDragEnd: onDragEnd, sortableIds: sortableIds }), hasListInFocusChain && (0, jsx_runtime_1.jsx)(helperComponents_1.HiddenTabButton, { ref: btnRef, listRef: listRef, tabIndex: tabIndex })] }) }) }) }) }));
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(contexts_1.NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, itemRender: itemRender, groupItemRender: groupItemRender, size: size, marker: marker, firstItemId: firstItemId, virtualized: props.virtualized, children: (0, jsx_runtime_1.jsx)(contexts_1.SelectionProvider, { ...selection, children: (0, jsx_runtime_1.jsx)(contexts_1.CollapseContext.Provider, { value: collapseContextValue, children: (0, jsx_runtime_1.jsx)(contexts_1.FocusListContext.Provider, { value: focusListContextValue, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)(styles_module_scss_1.default.wrapper, className), "data-active": isActive || undefined, children: [(0, jsx_runtime_1.jsx)(ListPrivate_1.ListPrivate, { ...props, items: memorizedItems.items.focusCloseChildIds, pinTop: memorizedItems.pinTop.focusCloseChildIds, pinBottom: memorizedItems.pinBottom.focusCloseChildIds, searchItem: searchItem, ref: (0, merge_refs_1.default)(ref, listRef), onFocus: handleOnFocus, onKeyDown: mergedHandlerKeyDown, tabIndex: hasListInFocusChain ? tabIndex : undefined, search: search, nested: false, onDragEnd: onDragEnd, sortableIds: sortableIds }), hasListInFocusChain && (0, jsx_runtime_1.jsx)(helperComponents_1.HiddenTabButton, { ref: btnRef, listRef: listRef, tabIndex: tabIndex })] }) }) }) }) }));
|
|
52
52
|
});
|
|
53
53
|
ListImpl.displayName = 'ListImpl';
|
|
54
54
|
/** Список айтемов: base / collapse / group / next-list, с опциональной виртуализацией. */
|
|
@@ -1,12 +1,85 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TruncateStringProps } from '@cloud-ru/ds-truncate-string';
|
|
2
|
+
import { CSSProperties, FocusEvent, ForwardedRef, KeyboardEvent, MouseEvent, ReactNode, RefObject } from 'react';
|
|
2
3
|
import { ItemContentProps } from '../../../helperComponents';
|
|
3
|
-
import { Size } from '../../../types';
|
|
4
|
+
import { Mode, Size } from '../../../types';
|
|
4
5
|
import { FlattenItem, FocusFlattenItem, ItemId } from '../../Items';
|
|
5
|
-
type ContentRenderProps = {
|
|
6
|
+
export type ContentRenderProps = {
|
|
6
7
|
id?: ItemId;
|
|
7
8
|
content?: ItemContentProps | ReactNode;
|
|
8
9
|
disabled?: boolean;
|
|
9
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Данные строки для кастомной оболочки (`itemRender`).
|
|
13
|
+
* Логика клика/выбора остаётся в `BaseItem`. Индикаторы выбора (маркер/чекбокс)
|
|
14
|
+
* оболочка рисует сама по `selectionMode` / `checked` / `disabled`.
|
|
15
|
+
*/
|
|
16
|
+
export type ItemRenderProps = {
|
|
17
|
+
id?: ItemId;
|
|
18
|
+
/** Исходный `content` айтема (пропсы `ItemContent` или произвольный узел) */
|
|
19
|
+
content?: ItemContentProps | ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Уже собранный контент: результат `contentRender`, либо дефолтный `ItemContent`,
|
|
22
|
+
* либо обёртка над произвольным `content`. Кастомная оболочка может использовать его
|
|
23
|
+
* как есть или пересобрать разметку из `content`.
|
|
24
|
+
*/
|
|
25
|
+
contentNode: ReactNode;
|
|
26
|
+
/**
|
|
27
|
+
* `true`, если `contentNode` собран через `contentRender` (или это неструктурный
|
|
28
|
+
* `content`). Тогда оболочка должна вставить `contentNode` как есть, а не
|
|
29
|
+
* пересобирать текст из полей `content`.
|
|
30
|
+
*/
|
|
31
|
+
contentFromRender?: boolean;
|
|
32
|
+
beforeContent?: ReactNode;
|
|
33
|
+
afterContent?: ReactNode;
|
|
34
|
+
dragHandle?: ReactNode;
|
|
35
|
+
switchControl?: ReactNode;
|
|
36
|
+
/** Сырая иконка шеврона — обёртку рисует оболочка */
|
|
37
|
+
expandIcon?: ReactNode;
|
|
38
|
+
/** Режим выбора списка (`none` / `single` / `multiple`) */
|
|
39
|
+
selectionMode: Mode;
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
inactive?: boolean;
|
|
42
|
+
checked?: boolean;
|
|
43
|
+
open?: boolean;
|
|
44
|
+
isParentNode?: boolean;
|
|
45
|
+
size: Size;
|
|
46
|
+
level: number;
|
|
47
|
+
className?: string;
|
|
48
|
+
itemRef?: RefObject<HTMLElement>;
|
|
49
|
+
tabIndex: number;
|
|
50
|
+
'data-test-id'?: string;
|
|
51
|
+
/** CSS-переменная `--level` и прочие инлайн-стили корня строки */
|
|
52
|
+
style?: CSSProperties;
|
|
53
|
+
onClick?(e: MouseEvent<HTMLElement>): void;
|
|
54
|
+
onMouseDown?(e: MouseEvent<HTMLElement>): void;
|
|
55
|
+
onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
|
|
56
|
+
onFocus?(e: FocusEvent<HTMLElement>): void;
|
|
57
|
+
onExpandIconClick?(e: MouseEvent<HTMLElement>): void;
|
|
58
|
+
expandIconInteractive?: boolean;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Данные заголовка группы для кастомной оболочки (`groupItemRender`).
|
|
62
|
+
* `selectButtonNode` — уже собранная кнопка массового выбора (если есть).
|
|
63
|
+
*/
|
|
64
|
+
export type GroupItemRenderProps = {
|
|
65
|
+
label?: string;
|
|
66
|
+
beforeContent?: ReactNode;
|
|
67
|
+
truncate?: {
|
|
68
|
+
variant?: TruncateStringProps['variant'];
|
|
69
|
+
};
|
|
70
|
+
groupVariant?: 'subtitle' | 'subtitleTertiary';
|
|
71
|
+
divider?: boolean;
|
|
72
|
+
selectButtonNode?: ReactNode;
|
|
73
|
+
selectButton?: {
|
|
74
|
+
onClick?(e: MouseEvent<HTMLElement>): void;
|
|
75
|
+
indeterminate?: boolean;
|
|
76
|
+
checked?: boolean;
|
|
77
|
+
itemRef?: ForwardedRef<HTMLElement>;
|
|
78
|
+
label?: string;
|
|
79
|
+
};
|
|
80
|
+
size: Size;
|
|
81
|
+
level: number;
|
|
82
|
+
};
|
|
10
83
|
export type PublicListContextType = {
|
|
11
84
|
/** Размер списка */
|
|
12
85
|
size?: Size;
|
|
@@ -16,6 +89,16 @@ export type PublicListContextType = {
|
|
|
16
89
|
* Рендер функция основного контента айтема
|
|
17
90
|
*/
|
|
18
91
|
contentRender?(props: ContentRenderProps): ReactNode;
|
|
92
|
+
/**
|
|
93
|
+
* Рендер-функция оболочки строки вместо дефолтной разметки `BaseItem`.
|
|
94
|
+
* Не задана — строка рисуется как раньше. `itemWrapRender` по-прежнему оборачивает результат.
|
|
95
|
+
*/
|
|
96
|
+
itemRender?(props: ItemRenderProps): ReactNode;
|
|
97
|
+
/**
|
|
98
|
+
* Рендер-функция заголовка группы вместо дефолтной разметки `Separator`.
|
|
99
|
+
* Не задана — заголовок/разделитель рисуются как раньше.
|
|
100
|
+
*/
|
|
101
|
+
groupItemRender?(props: GroupItemRenderProps): ReactNode;
|
|
19
102
|
virtualized?: boolean;
|
|
20
103
|
};
|
|
21
104
|
export type PrivateListContextType = {
|
|
@@ -29,5 +112,5 @@ type Child = {
|
|
|
29
112
|
type ListContextType = PublicListContextType & PrivateListContextType;
|
|
30
113
|
export declare const ListContext: import("react").Context<ListContextType>;
|
|
31
114
|
export declare function useNewListContext(): ListContextType;
|
|
32
|
-
export declare function NewListContextProvider({ children, size, marker, flattenItems, focusFlattenItems, contentRender, firstItemId, virtualized, }: ListContextType & Child): import("react/jsx-runtime").JSX.Element;
|
|
115
|
+
export declare function NewListContextProvider({ children, size, marker, flattenItems, focusFlattenItems, contentRender, itemRender, groupItemRender, firstItemId, virtualized, }: ListContextType & Child): import("react/jsx-runtime").JSX.Element;
|
|
33
116
|
export {};
|
|
@@ -14,10 +14,40 @@ exports.ListContext = (0, react_1.createContext)({
|
|
|
14
14
|
function useNewListContext() {
|
|
15
15
|
return (0, react_1.useContext)(exports.ListContext);
|
|
16
16
|
}
|
|
17
|
-
function extractListProps({ size, marker, flattenItems, focusFlattenItems, contentRender, firstItemId, virtualized, }) {
|
|
18
|
-
return {
|
|
17
|
+
function extractListProps({ size, marker, flattenItems, focusFlattenItems, contentRender, itemRender, groupItemRender, firstItemId, virtualized, }) {
|
|
18
|
+
return {
|
|
19
|
+
size,
|
|
20
|
+
marker,
|
|
21
|
+
contentRender,
|
|
22
|
+
itemRender,
|
|
23
|
+
groupItemRender,
|
|
24
|
+
flattenItems,
|
|
25
|
+
focusFlattenItems,
|
|
26
|
+
firstItemId,
|
|
27
|
+
virtualized,
|
|
28
|
+
};
|
|
19
29
|
}
|
|
20
|
-
function NewListContextProvider({ children, size, marker, flattenItems, focusFlattenItems, contentRender, firstItemId, virtualized, }) {
|
|
21
|
-
const value = (0, react_1.useMemo)(() => extractListProps({
|
|
30
|
+
function NewListContextProvider({ children, size, marker, flattenItems, focusFlattenItems, contentRender, itemRender, groupItemRender, firstItemId, virtualized, }) {
|
|
31
|
+
const value = (0, react_1.useMemo)(() => extractListProps({
|
|
32
|
+
size,
|
|
33
|
+
marker,
|
|
34
|
+
flattenItems,
|
|
35
|
+
focusFlattenItems,
|
|
36
|
+
contentRender,
|
|
37
|
+
itemRender,
|
|
38
|
+
groupItemRender,
|
|
39
|
+
firstItemId,
|
|
40
|
+
virtualized,
|
|
41
|
+
}), [
|
|
42
|
+
size,
|
|
43
|
+
marker,
|
|
44
|
+
flattenItems,
|
|
45
|
+
focusFlattenItems,
|
|
46
|
+
contentRender,
|
|
47
|
+
itemRender,
|
|
48
|
+
groupItemRender,
|
|
49
|
+
firstItemId,
|
|
50
|
+
virtualized,
|
|
51
|
+
]);
|
|
22
52
|
return (0, jsx_runtime_1.jsx)(exports.ListContext.Provider, { value: value, children: children });
|
|
23
53
|
}
|
|
@@ -4,4 +4,4 @@ import { DesktopDroplistProps } from '../../components/Lists/types';
|
|
|
4
4
|
* не реэкспортится; рендерится адаптивным `Droplist` на не-mobile раскладке. Так как вызывается
|
|
5
5
|
* только на desktop-раскладке, внутренний адаптивный `Dropdown` всегда рендерит popover.
|
|
6
6
|
*/
|
|
7
|
-
export declare function DesktopDroplist({ items: itemsProp, search, pinBottom: pinBottomProp, pinTop: pinTopProp, footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, container, open: openProp, onOpenChange, collapse, triggerClassName, disableSpanWrapper, selection, contentRender, size, marker, closeDroplistOnItemClick, className, listRef: listRefProp, untouchableScrollbars, virtualized, closeOnPopstate, header, headerDivider, footer, footerDivider, onItemsReorder, ...props }: DesktopDroplistProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function DesktopDroplist({ items: itemsProp, search, pinBottom: pinBottomProp, pinTop: pinTopProp, footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, container, open: openProp, onOpenChange, collapse, triggerClassName, disableSpanWrapper, selection, contentRender, itemRender, groupItemRender, size, marker, closeDroplistOnItemClick, className, listRef: listRefProp, untouchableScrollbars, virtualized, closeOnPopstate, header, headerDivider, footer, footerDivider, onItemsReorder, ...props }: DesktopDroplistProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -21,7 +21,7 @@ const styles_module_scss_1 = __importDefault(require('../../components/Lists/sty
|
|
|
21
21
|
* не реэкспортится; рендерится адаптивным `Droplist` на не-mobile раскладке. Так как вызывается
|
|
22
22
|
* только на desktop-раскладке, внутренний адаптивный `Dropdown` всегда рендерит popover.
|
|
23
23
|
*/
|
|
24
|
-
function DesktopDroplist({ items: itemsProp, search, pinBottom: pinBottomProp = [], pinTop: pinTopProp = [], footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, container, open: openProp, onOpenChange, collapse = {}, triggerClassName, disableSpanWrapper, selection, contentRender, size = constants_1.DEFAULT_SIZE, marker = true, closeDroplistOnItemClick = false, className, listRef: listRefProp, untouchableScrollbars = false, virtualized = false, closeOnPopstate, header, headerDivider, footer, footerDivider, onItemsReorder, ...props }) {
|
|
24
|
+
function DesktopDroplist({ items: itemsProp, search, pinBottom: pinBottomProp = [], pinTop: pinTopProp = [], footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, container, open: openProp, onOpenChange, collapse = {}, triggerClassName, disableSpanWrapper, selection, contentRender, itemRender, groupItemRender, size = constants_1.DEFAULT_SIZE, marker = true, closeDroplistOnItemClick = false, className, listRef: listRefProp, untouchableScrollbars = false, virtualized = false, closeOnPopstate, header, headerDivider, footer, footerDivider, onItemsReorder, ...props }) {
|
|
25
25
|
const { hasSearch, openCollapseItems, toggleOpenCollapseItem, searchItem, flattenItems, focusFlattenItems, memorizedItems, ids, expandedIds, firstItemId, onDragEnd, sortableIds, } = (0, hooks_1.useListItemsModel)({
|
|
26
26
|
items: itemsProp,
|
|
27
27
|
pinTop: pinTopProp,
|
|
@@ -128,7 +128,7 @@ function DesktopDroplist({ items: itemsProp, search, pinBottom: pinBottomProp =
|
|
|
128
128
|
// (ширина ≥ триггера). Узкую ширину такой список получает не через `auto`, а явным
|
|
129
129
|
// `width` (например, `dropDownClassName` у ChipChoice — сам он не virtualized).
|
|
130
130
|
const effectiveWidthStrategy = virtualized && (widthStrategy === undefined || widthStrategy === 'auto') ? 'gte' : widthStrategy;
|
|
131
|
-
return ((0, jsx_runtime_1.jsx)(contexts_1.NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, firstItemId: firstItemId, virtualized: virtualized, children: (0, jsx_runtime_1.jsx)(contexts_1.SelectionProvider, { ...selection, children: (0, jsx_runtime_1.jsx)(contexts_1.CollapseContext.Provider, { value: collapseContextValue, children: (0, jsx_runtime_1.jsx)(contexts_1.FocusListContext.Provider, { value: focusListContextValue, children: (0, jsx_runtime_1.jsx)(contexts_1.OpenListContext.Provider, { value: openListContextValue, children: (0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { content:
|
|
131
|
+
return ((0, jsx_runtime_1.jsx)(contexts_1.NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, itemRender: itemRender, groupItemRender: groupItemRender, size: size, marker: marker, firstItemId: firstItemId, virtualized: virtualized, children: (0, jsx_runtime_1.jsx)(contexts_1.SelectionProvider, { ...selection, children: (0, jsx_runtime_1.jsx)(contexts_1.CollapseContext.Provider, { value: collapseContextValue, children: (0, jsx_runtime_1.jsx)(contexts_1.FocusListContext.Provider, { value: focusListContextValue, children: (0, jsx_runtime_1.jsx)(contexts_1.OpenListContext.Provider, { value: openListContextValue, children: (0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { content:
|
|
132
132
|
// onKeyDown — пассивный детектор Escape для возврата фокуса на триггер
|
|
133
133
|
// (см. handleContentKeyDown). Контейнер презентационный, не интерактивный.
|
|
134
134
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
@@ -120,6 +120,11 @@ footer, onItemsReorder, withDividers, ...rest }) {
|
|
|
120
120
|
noDataState: rest.noDataState,
|
|
121
121
|
noResultsState: rest.noResultsState,
|
|
122
122
|
errorDataState: rest.errorDataState,
|
|
123
|
+
// Оболочки строк/групп и contentRender нужны на каждом уровне drill-down, не только на корне.
|
|
124
|
+
contentRender: rest.contentRender,
|
|
125
|
+
itemRender: rest.itemRender,
|
|
126
|
+
groupItemRender: rest.groupItemRender,
|
|
127
|
+
marker: rest.marker,
|
|
123
128
|
...(isRoot ? rest : null),
|
|
124
129
|
// Контролируемые scroll-пропсы идут после `...rest`, чтобы их не перебило значениями
|
|
125
130
|
// с десктопа. В sheet'е список заполняет body и скроллится внутри себя (`sheetScroll`,
|
|
@@ -15,7 +15,7 @@ const locale_1 = require("../../locale");
|
|
|
15
15
|
const utils_1 = require("../../utils");
|
|
16
16
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
17
17
|
function Separator({ label, beforeContent, truncate, divider, groupVariant = 'subtitleTertiary', selectButton, }) {
|
|
18
|
-
const { size = 'm' } = (0, contexts_1.useNewListContext)();
|
|
18
|
+
const { size = 'm', groupItemRender } = (0, contexts_1.useNewListContext)();
|
|
19
19
|
const { level = 0 } = (0, contexts_1.useCollapseLevelContext)();
|
|
20
20
|
const { t } = locale_1.listLocale.useTranslations();
|
|
21
21
|
const selectButtonJSX = (0, react_1.useMemo)(() => {
|
|
@@ -29,6 +29,19 @@ function Separator({ label, beforeContent, truncate, divider, groupVariant = 'su
|
|
|
29
29
|
e.stopPropagation();
|
|
30
30
|
}, onFocus: utils_1.stopPropagation, innerRef: itemRef, label: label ?? (checked ? t('groupSelectButton.reset') : t('groupSelectButton.select')) }) }));
|
|
31
31
|
}, [selectButton, size, t]);
|
|
32
|
+
if (groupItemRender && (label || divider)) {
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: groupItemRender({
|
|
34
|
+
label,
|
|
35
|
+
beforeContent,
|
|
36
|
+
truncate,
|
|
37
|
+
groupVariant,
|
|
38
|
+
divider,
|
|
39
|
+
selectButton,
|
|
40
|
+
selectButtonNode: selectButtonJSX,
|
|
41
|
+
size,
|
|
42
|
+
level,
|
|
43
|
+
}) }));
|
|
44
|
+
}
|
|
32
45
|
if (label) {
|
|
33
46
|
return ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.separatorWithLabel, "data-size": size, "data-level-one": level === 1 || undefined, "data-level-more-one": level > 1 || undefined, style: { '--level': level }, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.contentWrapper, children: [beforeContent && ((0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.centeredWrapper, "aria-hidden": true, children: beforeContent })), (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.textWrapper, children: [(0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.textContent, children: (0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.headline, "data-group-variant": groupVariant, children: (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, { variant: truncate?.variant, text: label, maxLines: 1 }) }) }), selectButtonJSX] })] }), divider && ((0, jsx_runtime_1.jsx)(divider_1.Divider, { className: styles_module_scss_1.default.divider, variant: groupVariant === 'subtitle' ? divider_1.VARIANT.Regular : divider_1.VARIANT.Thin }))] }));
|
|
34
47
|
}
|
package/dist/cjs/style.css
CHANGED
|
@@ -89,6 +89,15 @@
|
|
|
89
89
|
width:100%;
|
|
90
90
|
height:100%;
|
|
91
91
|
}
|
|
92
|
+
.markerContainer[data-checked]::before{
|
|
93
|
+
background-color:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-50, #222222));
|
|
94
|
+
}
|
|
95
|
+
.markerContainer[data-checked][data-disabled]{
|
|
96
|
+
opacity:var(--sn-theme-effect-opacity-disabled, 0.4);
|
|
97
|
+
}
|
|
98
|
+
.markerContainer[data-checked][data-disabled]::before{
|
|
99
|
+
background-color:var(--sn-theme-color-neutral-accent, var(--sn-brand-color-neutral-50, var(--sn-brand-palette-gray-50, #222222)));
|
|
100
|
+
}
|
|
92
101
|
|
|
93
102
|
.droplistItem{
|
|
94
103
|
position:relative;
|
|
@@ -262,18 +271,9 @@
|
|
|
262
271
|
.innerWrapper[data-disabled] .droplistItem{
|
|
263
272
|
cursor:not-allowed;
|
|
264
273
|
}
|
|
265
|
-
.innerWrapper[data-has-checked] .markerContainer::before, .innerWrapper[data-checked] .markerContainer::before{
|
|
266
|
-
background-color:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-50, #222222));
|
|
267
|
-
}
|
|
268
274
|
.innerWrapper[data-has-checked] .droplistItem:focus-visible, .innerWrapper[data-checked] .droplistItem:focus-visible{
|
|
269
275
|
outline-color:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-50, #222222));
|
|
270
276
|
}
|
|
271
|
-
.innerWrapper[data-has-checked][data-disabled] .markerContainer, .innerWrapper[data-checked][data-disabled] .markerContainer{
|
|
272
|
-
opacity:var(--sn-theme-effect-opacity-disabled, 0.4);
|
|
273
|
-
}
|
|
274
|
-
.innerWrapper[data-has-checked][data-disabled] .markerContainer::before, .innerWrapper[data-checked][data-disabled] .markerContainer::before{
|
|
275
|
-
background-color:var(--sn-theme-color-neutral-accent, var(--sn-brand-color-neutral-50, var(--sn-brand-palette-gray-50, #222222)));
|
|
276
|
-
}
|
|
277
277
|
|
|
278
278
|
.content{
|
|
279
279
|
overflow:hidden;
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Checkbox, Switch } from '@cloud-ru/ds-toggles';
|
|
3
3
|
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
4
4
|
import cn from 'classnames';
|
|
5
|
-
import { DEFAULT_SIZE, TEST_IDS } from '../../../constants.js';
|
|
5
|
+
import { DEFAULT_SIZE, MODE, TEST_IDS } from '../../../constants.js';
|
|
6
6
|
import { ItemContent } from '../../../helperComponents/index.js';
|
|
7
7
|
import { useCollapseLevelContext, useNewListContext, useOpenListContext, useSelectionContext, } from '../../Lists/contexts/index.js';
|
|
8
8
|
import commonStyles from '../styles.module.css';
|
|
@@ -11,7 +11,7 @@ import { TOGGLE_SIZE_MAP } from './constants.js';
|
|
|
11
11
|
import styles from './styles.module.css';
|
|
12
12
|
export function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, showSwitchIcon, onKeyDown, onFocus, indeterminate, checked: checkedProp, onSelect, onOpenNestedList, onToggleExpand, onExpandIconClick, isParentNode, className, inactive, itemWrapRender, dragHandle, ...rest }) {
|
|
13
13
|
const interactive = !inactive;
|
|
14
|
-
const { size = DEFAULT_SIZE, marker, contentRender, firstItemId, focusFlattenItems } = useNewListContext();
|
|
14
|
+
const { size = DEFAULT_SIZE, marker, contentRender, itemRender, firstItemId, focusFlattenItems, } = useNewListContext();
|
|
15
15
|
const { level = 0 } = useCollapseLevelContext();
|
|
16
16
|
const { closeDroplist, closeDroplistOnItemClick } = useOpenListContext();
|
|
17
17
|
const { value, onChange, mode, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
|
|
@@ -99,25 +99,76 @@ export function BaseItem({ beforeContent, afterContent, content, onClick, onMous
|
|
|
99
99
|
};
|
|
100
100
|
const props = extractSupportProps(rest);
|
|
101
101
|
let contentNode;
|
|
102
|
+
let contentFromRender = Boolean(contentRender);
|
|
102
103
|
if (content && isContentItem(content)) {
|
|
103
104
|
contentNode = contentRender?.({ id, content, disabled }) ?? _jsx(ItemContent, { disabled: disabled, ...content });
|
|
104
105
|
}
|
|
105
106
|
else if (isPrimitiveContent(content)) {
|
|
106
107
|
// Примитивный content — шорткат `{ label: content }`: рендерим через ItemContent,
|
|
107
108
|
// чтобы строка получила размерную высоту, а не схлопывалась до высоты текста.
|
|
108
|
-
|
|
109
|
+
const primitiveContent = { label: content };
|
|
110
|
+
contentNode = contentRender?.({ id, content: primitiveContent, disabled }) ?? (_jsx(ItemContent, { disabled: disabled, label: content }));
|
|
109
111
|
}
|
|
110
112
|
else {
|
|
111
|
-
contentNode = _jsxs("div", { className: styles.content, children: [" ", content, " "] });
|
|
113
|
+
contentNode = contentRender?.({ id, content, disabled }) ?? _jsxs("div", { className: styles.content, children: [" ", content, " "] });
|
|
114
|
+
// Неструктурный content оболочка не разберёт на label/caption — отдаём готовый узел.
|
|
115
|
+
contentFromRender = true;
|
|
112
116
|
}
|
|
113
117
|
const stateLayerState = isSelectionSingle && isChecked && !switchProp && !isParentNode
|
|
114
118
|
? 'activatedOnBackground'
|
|
115
119
|
: 'emptyNeutralOnBackground';
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
const dataTestId = (typeof props['data-test-id'] === 'string' ? props['data-test-id'] : undefined) || `${TEST_IDS.baseItem}_${id}`;
|
|
121
|
+
const tabIndex = firstItemId && id === focusFlattenItems[firstItemId]?.originalId ? 0 : -1;
|
|
122
|
+
const dragHandleNode = dragHandle ? _jsx("div", { className: styles.dragHandle, children: dragHandle }) : undefined;
|
|
123
|
+
// Маркер/чекбокс/шеврон-обёртка нужны только дефолтной разметке; при `itemRender`
|
|
124
|
+
// оболочка рисует индикаторы сама по `selectionMode`.
|
|
125
|
+
const markerNode = !itemRender && !switchProp && isSelectionSingle && marker && !isParentNode && interactive ? (_jsx("div", { className: styles.markerContainer, "data-test-id": TEST_IDS.baseItemMarker, "data-checked": isChecked || undefined, "data-disabled": disabled || undefined })) : undefined;
|
|
126
|
+
const checkboxNode = !itemRender && !switchProp && isSelectionMultiple && interactive ? (_jsx("div", { className: styles.checkbox, children: _jsx(Checkbox, { size: TOGGLE_SIZE_MAP[size], disabled: disabled, tabIndex: -1, onChange: isParentNode ? handleCheckboxChange : undefined, checked: isChecked, "data-test-id": TEST_IDS.baseItemCheckbox, onClick: handleCheckboxClick, indeterminate: indeterminate }) })) : undefined;
|
|
127
|
+
const switchControlNode = switchProp && interactive ? (_jsx("span", { className: styles.switchWrapper, children: _jsx(Switch, { size: TOGGLE_SIZE_MAP[size], disabled: disabled, checked: isChecked, "data-test-id": TEST_IDS.baseItemSwitch, showIcon: showSwitchIcon }) })) : undefined;
|
|
128
|
+
const expandIconNode = !itemRender && !switchProp && expandIcon ? (
|
|
129
|
+
// Интерактивный шеврон не получает роль и фокус намеренно: клавиатурный путь идёт
|
|
130
|
+
// через строку, у неё же живёт `aria-expanded`. Лишний таб-стоп сломал бы порядок
|
|
131
|
+
// фокуса списка, а озвучивать AT недостижимый с клавиатуры элемент незачем.
|
|
132
|
+
_jsx("span", { className: styles.groupIndicator, "data-open": open || undefined, "data-interactive": Boolean(onExpandIconClick) || undefined, "data-test-id": TEST_IDS.groupIndicator, onClick: onExpandIconClick && handleExpandIconClick, "aria-hidden": true, children: expandIcon })) : undefined;
|
|
133
|
+
const isRowChecked = Boolean((isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp));
|
|
134
|
+
let selectionMode = MODE.None;
|
|
135
|
+
if (isSelectionMultiple) {
|
|
136
|
+
selectionMode = MODE.Multiple;
|
|
137
|
+
}
|
|
138
|
+
else if (isSelectionSingle) {
|
|
139
|
+
selectionMode = MODE.Single;
|
|
140
|
+
}
|
|
141
|
+
const itemJSX = itemRender ? (itemRender({
|
|
142
|
+
id,
|
|
143
|
+
content,
|
|
144
|
+
contentNode,
|
|
145
|
+
contentFromRender,
|
|
146
|
+
beforeContent,
|
|
147
|
+
afterContent,
|
|
148
|
+
dragHandle: dragHandleNode,
|
|
149
|
+
switchControl: switchControlNode,
|
|
150
|
+
// Сырой слот: обёртку centeredWrapper/groupIndicator рисует кастомная оболочка.
|
|
151
|
+
expandIcon: !switchProp && expandIcon ? expandIcon : undefined,
|
|
152
|
+
selectionMode,
|
|
153
|
+
disabled,
|
|
154
|
+
inactive,
|
|
155
|
+
checked: isRowChecked,
|
|
156
|
+
open,
|
|
157
|
+
isParentNode,
|
|
158
|
+
size,
|
|
159
|
+
level,
|
|
160
|
+
className,
|
|
161
|
+
itemRef: itemRef,
|
|
162
|
+
tabIndex,
|
|
163
|
+
'data-test-id': dataTestId,
|
|
164
|
+
style: { '--level': level },
|
|
165
|
+
onClick: handleItemClick,
|
|
166
|
+
onMouseDown: handleItemMouseDown,
|
|
167
|
+
onKeyDown: handleItemKeyDown,
|
|
168
|
+
onFocus: handleItemFocus,
|
|
169
|
+
onExpandIconClick: onExpandIconClick ? handleExpandIconClick : undefined,
|
|
170
|
+
expandIconInteractive: Boolean(onExpandIconClick),
|
|
171
|
+
})) : (_jsxs("div", { className: cn(commonStyles.itemWrapper, styles.innerWrapper, className), "data-size": size, "data-inactive": inactive || undefined, "data-disabled": disabled || undefined, "data-variant": mode || undefined, "data-checked": (isParentNode && isChecked) || (!isParentNode && isChecked && !switchProp) || undefined, children: [_jsx("span", { className: commonStyles.stateLayer, "aria-hidden": true, "data-state": stateLayerState }), _jsxs("li", { "data-type": 'outside', role: 'menuitem', "data-test-id": dataTestId, ref: itemRef, className: cn(commonStyles.listItem, styles.droplistItem), "data-size": size, onClick: handleItemClick, onMouseDown: handleItemMouseDown, tabIndex: tabIndex, "data-non-pointer": (inactive && !onClick) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "aria-expanded": isParentNode ? Boolean(open) : undefined, onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, "data-level-one": level === 1 || undefined, "data-level-more-one": level > 1 || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, children: [dragHandleNode, markerNode, checkboxNode, _jsxs("div", { className: styles.contentWrapper, children: [beforeContent && _jsx("div", { className: styles.beforeContent, children: beforeContent }), contentNode, afterContent && _jsx("div", { className: styles.afterContent, children: afterContent })] }), switchControlNode, expandIconNode] })] }));
|
|
121
172
|
if (!itemWrapRender) {
|
|
122
173
|
return itemJSX;
|
|
123
174
|
}
|