@snack-uikit/list 0.9.2-preview-0a44b2fc.0 → 0.9.2-preview-2855fb42.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.
@@ -21,7 +21,7 @@ export function AccordionItem(_a) {
21
21
  const { level = 1 } = useCollapseLevelContext();
22
22
  const { openCollapseItems = [], toggleOpenCollapseItem } = useCollapseContext();
23
23
  const { flattenedItems } = useNewListContext();
24
- const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({
24
+ const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({
25
25
  items,
26
26
  id,
27
27
  disabled,
@@ -37,5 +37,5 @@ export function AccordionItem(_a) {
37
37
  toggleOpenCollapseItem === null || toggleOpenCollapseItem === void 0 ? void 0 : toggleOpenCollapseItem(id !== null && id !== void 0 ? id : '');
38
38
  (_a = option.onClick) === null || _a === void 0 ? void 0 : _a.call(option, e);
39
39
  };
40
- return (_jsx(CollapseBlockPrivate, { header: _jsx(BaseItem, Object.assign({}, option, { id: id, disabled: disabled, expandIcon: isOpen ? _jsx(ChevronUpSVG, {}) : _jsx(ChevronDownSVG, {}), onClick: handleItemClick, isParentNode: true, onOpenNestedList: handleKeyDown, indeterminate: isIndeterminate && !checked, onSelect: !disabled ? handleOnSelect : undefined })), expanded: isOpen, "data-test-id": `list__accordion-item-${id}`, children: _jsx(CollapseLevelContext.Provider, { value: { level: level + 1 }, children: itemsJSX }) }));
40
+ return (_jsx(CollapseBlockPrivate, { header: _jsx(BaseItem, Object.assign({}, option, { id: id, disabled: disabled, expandIcon: isOpen ? _jsx(ChevronUpSVG, {}) : _jsx(ChevronDownSVG, {}), onClick: handleItemClick, isParentNode: true, onOpenNestedList: handleKeyDown, checked: checked, indeterminate: indeterminate, onSelect: !disabled ? handleOnSelect : undefined })), expanded: isOpen, "data-test-id": `list__accordion-item-${id}`, children: _jsx(CollapseLevelContext.Provider, { value: { level: level + 1 }, children: itemsJSX }) }));
41
41
  }
@@ -2,9 +2,10 @@ import { KeyboardEvent } from 'react';
2
2
  import { AnyType, BaseItemPrivateProps, BaseItemProps } from '../types';
3
3
  type AllBaseItemProps<Meta = AnyType> = BaseItemProps<Meta> & BaseItemPrivateProps & {
4
4
  indeterminate?: boolean;
5
+ checked?: boolean;
5
6
  onSelect?(): void;
6
7
  isParentNode?: boolean;
7
8
  onOpenNestedList?(e?: KeyboardEvent<HTMLElement>): void;
8
9
  };
9
- export declare function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, onOpenNestedList, isParentNode, className, inactive, itemWrapRender, meta, ...rest }: AllBaseItemProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
10
+ export declare function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, checked: checkedProp, onSelect, onOpenNestedList, isParentNode, className, inactive, itemWrapRender, meta, ...rest }: AllBaseItemProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
10
11
  export {};
@@ -21,13 +21,13 @@ import { CHECKBOX_SIZE_MAP } from './constants';
21
21
  import styles from './styles.module.css';
22
22
  export function BaseItem(_a) {
23
23
  var _b;
24
- var { beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, onOpenNestedList, isParentNode, className, inactive, itemWrapRender, meta } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "onMouseDown", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "onSelect", "onOpenNestedList", "isParentNode", "className", "inactive", "itemWrapRender", "meta"]);
24
+ var { beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, checked: checkedProp, onSelect, onOpenNestedList, isParentNode, className, inactive, itemWrapRender, meta } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "onMouseDown", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "checked", "onSelect", "onOpenNestedList", "isParentNode", "className", "inactive", "itemWrapRender", "meta"]);
25
25
  const interactive = !inactive;
26
26
  const { size = 's', marker, contentRender } = useNewListContext();
27
27
  const { level = 0 } = useCollapseLevelContext();
28
28
  const { forceUpdateActiveItemId } = useFocusListContext();
29
29
  const { value, onChange, mode, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
30
- const isChecked = isSelectionSingle ? value === id : value === null || value === void 0 ? void 0 : value.includes(id !== null && id !== void 0 ? id : '');
30
+ const isChecked = isSelectionSingle ? value === id : checkedProp !== null && checkedProp !== void 0 ? checkedProp : value === null || value === void 0 ? void 0 : value.includes(id !== null && id !== void 0 ? id : '');
31
31
  const handleChange = () => {
32
32
  onChange === null || onChange === void 0 ? void 0 : onChange(id !== null && id !== void 0 ? id : '', meta);
33
33
  };
@@ -47,7 +47,7 @@ export function NextListItem(_a) {
47
47
  return;
48
48
  }
49
49
  }, [handleListKeyDownFactory, ids, expandedIds, id, forceUpdateActiveItemId]);
50
- const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({ items, id, disabled, allChildIds });
50
+ const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({ items, id, disabled, allChildIds });
51
51
  const handleOutsideClick = useCallback(() => {
52
52
  forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId('~drop-focus');
53
53
  setOpen(false);
@@ -58,7 +58,7 @@ export function NextListItem(_a) {
58
58
  return (_jsx(Dropdown, { outsideClick: handleOutsideClick, fallbackPlacements: FALLBACK_PLACEMENTS, content: _jsx(ListPrivate, { onKeyDown: handleListKeyDown, items: { flattenedItems, items }, nested: true, search: search, scroll: scroll, tabIndex: 0, ref: listRef, onFocus: e => {
59
59
  e.stopPropagation();
60
60
  forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId(ids[0]);
61
- }, scrollRef: scrollRef, limitedScrollHeight: true }), trigger: 'hover', open: isOpen || open, onOpenChange: setOpen, placement: placement, children: _jsx(BaseItem, Object.assign({}, option, { disabled: disabled, open: open, expandIcon: _jsx(ChevronRightSVG, {}), id: id, isParentNode: true, indeterminate: isIndeterminate && !checked, onOpenNestedList: () => {
61
+ }, scrollRef: scrollRef, limitedScrollHeight: true }), trigger: 'hover', open: isOpen || open, onOpenChange: setOpen, placement: placement, children: _jsx(BaseItem, Object.assign({}, option, { disabled: disabled, open: open, expandIcon: _jsx(ChevronRightSVG, {}), id: id, isParentNode: true, indeterminate: indeterminate, checked: checked, onOpenNestedList: () => {
62
62
  setOpen(true);
63
63
  setTimeout(() => {
64
64
  var _a;
@@ -19,9 +19,9 @@ type UseGroupItemSelectionProps = {
19
19
  id: ItemId;
20
20
  disabled?: boolean;
21
21
  };
22
- export declare function useGroupItemSelection({ id, disabled, allChildIds }: UseGroupItemSelectionProps): {
22
+ export declare function useGroupItemSelection({ id, allChildIds }: UseGroupItemSelectionProps): {
23
23
  checked: boolean | undefined;
24
- isIndeterminate: boolean;
24
+ indeterminate: boolean;
25
25
  handleOnSelect: () => void;
26
26
  };
27
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { createElement as _createElement } from "react";
2
- import { createRef, useEffect, useMemo } from 'react';
2
+ import { createRef, useMemo } from 'react';
3
3
  import { useNewListContext, useSelectionContext } from '../Lists/contexts';
4
4
  import { AccordionItem } from './AccordionItem';
5
5
  import { BaseItem } from './BaseItem';
@@ -44,34 +44,20 @@ export function useCreateBaseItems({ footerActiveElementsRefs }) {
44
44
  });
45
45
  }, [footerActiveElementsRefs]);
46
46
  }
47
- export function useGroupItemSelection({ id, disabled, allChildIds }) {
47
+ export function useGroupItemSelection({ id, allChildIds }) {
48
48
  const { value, setValue, isSelectionMultiple } = useSelectionContext();
49
49
  const { flattenedItems } = useNewListContext();
50
50
  const baseChildIds = useMemo(() => allChildIds.filter(itemId => isBaseItemProps(flattenedItems[itemId])), [allChildIds, flattenedItems]);
51
- const isIndeterminate = isSelectionMultiple
52
- ? baseChildIds.some(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
53
- : baseChildIds.includes(value !== null && value !== void 0 ? value : '');
54
51
  const checked = isSelectionMultiple ? baseChildIds.every(childId => value === null || value === void 0 ? void 0 : value.includes(childId)) : undefined;
55
- useEffect(() => {
56
- if (isSelectionMultiple) {
57
- if (checked && !(value === null || value === void 0 ? void 0 : value.includes(id))) {
58
- setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([id !== null && id !== void 0 ? id : '']));
59
- }
60
- if (!checked && (value === null || value === void 0 ? void 0 : value.includes(id))) {
61
- setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id));
62
- }
63
- }
64
- }, [checked, disabled, id, isSelectionMultiple, setValue, value]);
52
+ const indeterminate = isSelectionMultiple
53
+ ? !checked && baseChildIds.some(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
54
+ : baseChildIds.includes(value !== null && value !== void 0 ? value : '');
65
55
  const handleOnSelect = () => {
66
56
  if (checked) {
67
57
  setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id && !baseChildIds.includes(itemId)));
68
58
  return;
69
59
  }
70
- if (isIndeterminate) {
71
- setValue === null || setValue === void 0 ? void 0 : setValue((value) => Array.from(new Set([...(value !== null && value !== void 0 ? value : []), ...baseChildIds, id])));
72
- return;
73
- }
74
- setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([...baseChildIds, id !== null && id !== void 0 ? id : '']));
60
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => Array.from(new Set([...(value !== null && value !== void 0 ? value : []), ...baseChildIds])));
75
61
  };
76
- return { checked, isIndeterminate, handleOnSelect };
62
+ return { checked, indeterminate, handleOnSelect };
77
63
  }
@@ -19,5 +19,5 @@ export function ItemContent(_a) {
19
19
  var _b, _c;
20
20
  var { truncate, caption, description, option, className, disabled } = _a, rest = __rest(_a, ["truncate", "caption", "description", "option", "className", "disabled"]);
21
21
  const { size = 's' } = useNewListContext();
22
- return (_jsxs("div", Object.assign({ className: cn(styles.content, className) }, extractSupportProps(rest), { "data-size": size !== null && size !== void 0 ? size : 's', "data-disabled": disabled !== null && disabled !== void 0 ? disabled : undefined, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.label, children: _jsx(TruncateString, { variant: truncate === null || truncate === void 0 ? void 0 : truncate.variant, text: String(option), maxLines: (_b = truncate === null || truncate === void 0 ? void 0 : truncate.option) !== null && _b !== void 0 ? _b : 1, "data-test-id": 'list__base-item-option' }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: (_c = truncate === null || truncate === void 0 ? void 0 : truncate.description) !== null && _c !== void 0 ? _c : 2, "data-test-id": 'list__base-item-description' }) }))] })));
22
+ return (_jsxs("div", Object.assign({ className: cn(styles.content, className) }, extractSupportProps(rest), { "data-size": size !== null && size !== void 0 ? size : 's', "data-disabled": disabled || undefined, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.label, children: _jsx(TruncateString, { variant: truncate === null || truncate === void 0 ? void 0 : truncate.variant, text: String(option), maxLines: (_b = truncate === null || truncate === void 0 ? void 0 : truncate.option) !== null && _b !== void 0 ? _b : 1, "data-test-id": 'list__base-item-option' }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: (_c = truncate === null || truncate === void 0 ? void 0 : truncate.description) !== null && _c !== void 0 ? _c : 2, "data-test-id": 'list__base-item-description' }) }))] })));
23
23
  }
@@ -110,7 +110,7 @@
110
110
  letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
111
111
  paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
112
112
  }
113
- .content[data-disabled] .option,
113
+ .content[data-disabled] .label,
114
114
  .content[data-disabled] .description,
115
115
  .content[data-disabled] .caption{
116
116
  color:var(--sys-neutral-text-disabled, #b3b6bf);
@@ -11,4 +11,4 @@ export type ListEmptyState = {
11
11
  dataFiltered?: boolean;
12
12
  hasNoItems: boolean;
13
13
  };
14
- export declare function ListEmptyState({ dataError, dataFiltered, hasNoItems, emptyStates, loading }: ListEmptyState): null;
14
+ export declare function ListEmptyState({ dataError, dataFiltered, hasNoItems, emptyStates, loading }: ListEmptyState): import("react/jsx-runtime").JSX.Element | null;
@@ -6,13 +6,13 @@ export function ListEmptyState({ dataError, dataFiltered, hasNoItems, emptyState
6
6
  return null;
7
7
  }
8
8
  if (dataError) {
9
- _jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.errorDataState, { size: 's', align: 'vertical' })) });
9
+ return (_jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.errorDataState, { size: 's', align: 'vertical' })) }));
10
10
  }
11
11
  if (dataFiltered && hasNoItems) {
12
- _jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.noResultsState, { size: 's', align: 'vertical', "data-test-id": 'list__no-results' })) });
12
+ return (_jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.noResultsState, { size: 's', align: 'vertical', "data-test-id": 'list__no-results' })) }));
13
13
  }
14
14
  if (!dataFiltered && hasNoItems) {
15
- _jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.noDataState, { size: 's', align: 'vertical', "data-test-id": 'list__no-data' })) });
15
+ return (_jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.noDataState, { size: 's', align: 'vertical', "data-test-id": 'list__no-data' })) }));
16
16
  }
17
17
  return null;
18
18
  }
package/dist/utils.js CHANGED
@@ -13,8 +13,9 @@ export function kindFlattenItems({ items, prefix, parentId }) {
13
13
  let allChildIds = [];
14
14
  const closeChildIds = [];
15
15
  const { items } = item;
16
+ const childActiveParent = isGroupItemProps(item) ? parentId !== null && parentId !== void 0 ? parentId : '~main' : itemId;
16
17
  for (let idx = 0; idx < items.length; idx++) {
17
- const { id, children } = flatten({ item: items[idx], idx, prefix: itemId, parentId: itemId });
18
+ const { id, children } = flatten({ item: items[idx], idx, prefix: itemId, parentId: childActiveParent });
18
19
  closeChildIds.push(id);
19
20
  allChildIds = allChildIds.concat(children);
20
21
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "List",
7
- "version": "0.9.2-preview-0a44b2fc.0",
7
+ "version": "0.9.2-preview-2855fb42.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,17 +32,17 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/divider": "3.0.3-preview-0a44b2fc.0",
36
- "@snack-uikit/dropdown": "0.2.2-preview-0a44b2fc.0",
35
+ "@snack-uikit/divider": "3.0.3-preview-2855fb42.0",
36
+ "@snack-uikit/dropdown": "0.2.2-preview-2855fb42.0",
37
37
  "@snack-uikit/icons": "0.20.1",
38
- "@snack-uikit/info-block": "0.3.4-preview-0a44b2fc.0",
39
- "@snack-uikit/loaders": "0.5.2-preview-0a44b2fc.0",
40
- "@snack-uikit/locale": "0.6.1-preview-0a44b2fc.0",
41
- "@snack-uikit/scroll": "0.5.3-preview-0a44b2fc.0",
42
- "@snack-uikit/search-private": "0.1.6-preview-0a44b2fc.0",
43
- "@snack-uikit/toggles": "0.9.8-preview-0a44b2fc.0",
44
- "@snack-uikit/truncate-string": "0.4.13-preview-0a44b2fc.0",
45
- "@snack-uikit/utils": "3.2.1-preview-0a44b2fc.0",
38
+ "@snack-uikit/info-block": "0.3.4-preview-2855fb42.0",
39
+ "@snack-uikit/loaders": "0.5.2-preview-2855fb42.0",
40
+ "@snack-uikit/locale": "0.6.1-preview-2855fb42.0",
41
+ "@snack-uikit/scroll": "0.5.3-preview-2855fb42.0",
42
+ "@snack-uikit/search-private": "0.1.6-preview-2855fb42.0",
43
+ "@snack-uikit/toggles": "0.9.8-preview-2855fb42.0",
44
+ "@snack-uikit/truncate-string": "0.4.13-preview-2855fb42.0",
45
+ "@snack-uikit/utils": "3.2.1-preview-2855fb42.0",
46
46
  "classnames": "2.5.1",
47
47
  "fuzzy-search": "3.2.1",
48
48
  "merge-refs": "1.2.2",
@@ -54,5 +54,5 @@
54
54
  "peerDependencies": {
55
55
  "@snack-uikit/locale": "*"
56
56
  },
57
- "gitHead": "318167bcb09619d0d40263ec844b38b1014838f4"
57
+ "gitHead": "0fd00988eca0e7cc798a3b7a11fe1b306ebbc4e2"
58
58
  }
@@ -18,7 +18,7 @@ export function AccordionItem<Meta>({ items, id, disabled, allChildIds, ...optio
18
18
  const { openCollapseItems = [], toggleOpenCollapseItem } = useCollapseContext();
19
19
 
20
20
  const { flattenedItems } = useNewListContext<Meta>();
21
- const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({
21
+ const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({
22
22
  items,
23
23
  id,
24
24
  disabled,
@@ -49,7 +49,8 @@ export function AccordionItem<Meta>({ items, id, disabled, allChildIds, ...optio
49
49
  onClick={handleItemClick}
50
50
  isParentNode
51
51
  onOpenNestedList={handleKeyDown}
52
- indeterminate={isIndeterminate && !checked}
52
+ checked={checked}
53
+ indeterminate={indeterminate}
53
54
  onSelect={!disabled ? handleOnSelect : undefined}
54
55
  />
55
56
  }
@@ -20,6 +20,7 @@ import styles from './styles.module.scss';
20
20
  type AllBaseItemProps<Meta = AnyType> = BaseItemProps<Meta> &
21
21
  BaseItemPrivateProps & {
22
22
  indeterminate?: boolean;
23
+ checked?: boolean;
23
24
  onSelect?(): void;
24
25
  isParentNode?: boolean;
25
26
  onOpenNestedList?(e?: KeyboardEvent<HTMLElement>): void;
@@ -40,6 +41,7 @@ export function BaseItem({
40
41
  onKeyDown,
41
42
  onFocus,
42
43
  indeterminate,
44
+ checked: checkedProp,
43
45
  onSelect,
44
46
  onOpenNestedList,
45
47
  isParentNode,
@@ -56,7 +58,7 @@ export function BaseItem({
56
58
  const { forceUpdateActiveItemId } = useFocusListContext();
57
59
  const { value, onChange, mode, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
58
60
 
59
- const isChecked = isSelectionSingle ? value === id : value?.includes(id ?? '');
61
+ const isChecked = isSelectionSingle ? value === id : checkedProp ?? value?.includes(id ?? '');
60
62
 
61
63
  const handleChange = () => {
62
64
  onChange?.(id ?? '', meta);
@@ -60,7 +60,7 @@ export function NextListItem<Meta = AnyType>({
60
60
  [handleListKeyDownFactory, ids, expandedIds, id, forceUpdateActiveItemId],
61
61
  );
62
62
 
63
- const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({ items, id, disabled, allChildIds });
63
+ const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({ items, id, disabled, allChildIds });
64
64
 
65
65
  const handleOutsideClick = useCallback(() => {
66
66
  forceUpdateActiveItemId?.('~drop-focus');
@@ -108,7 +108,8 @@ export function NextListItem<Meta = AnyType>({
108
108
  expandIcon={<ChevronRightSVG />}
109
109
  id={id}
110
110
  isParentNode
111
- indeterminate={isIndeterminate && !checked}
111
+ indeterminate={indeterminate}
112
+ checked={checked}
112
113
  onOpenNestedList={() => {
113
114
  setOpen(true);
114
115
  setTimeout(() => {
@@ -1,4 +1,4 @@
1
- import { createRef, RefObject, useEffect, useMemo } from 'react';
1
+ import { createRef, RefObject, useMemo } from 'react';
2
2
 
3
3
  import { useNewListContext, useSelectionContext } from '../Lists/contexts';
4
4
  import { AccordionItem } from './AccordionItem';
@@ -83,7 +83,7 @@ type UseGroupItemSelectionProps = {
83
83
  disabled?: boolean;
84
84
  };
85
85
 
86
- export function useGroupItemSelection({ id, disabled, allChildIds }: UseGroupItemSelectionProps) {
86
+ export function useGroupItemSelection({ id, allChildIds }: UseGroupItemSelectionProps) {
87
87
  const { value, setValue, isSelectionMultiple } = useSelectionContext();
88
88
  const { flattenedItems } = useNewListContext();
89
89
 
@@ -92,21 +92,11 @@ export function useGroupItemSelection({ id, disabled, allChildIds }: UseGroupIte
92
92
  [allChildIds, flattenedItems],
93
93
  );
94
94
 
95
- const isIndeterminate = isSelectionMultiple
96
- ? baseChildIds.some(childId => value?.includes(childId))
97
- : baseChildIds.includes(value ?? '');
98
95
  const checked = isSelectionMultiple ? baseChildIds.every(childId => value?.includes(childId)) : undefined;
99
96
 
100
- useEffect(() => {
101
- if (isSelectionMultiple) {
102
- if (checked && !value?.includes(id)) {
103
- setValue?.((value: ItemId[]) => (value ?? []).concat([id ?? '']));
104
- }
105
- if (!checked && value?.includes(id)) {
106
- setValue?.((value: ItemId[]) => (value ?? []).filter(itemId => itemId !== id));
107
- }
108
- }
109
- }, [checked, disabled, id, isSelectionMultiple, setValue, value]);
97
+ const indeterminate = isSelectionMultiple
98
+ ? !checked && baseChildIds.some(childId => value?.includes(childId))
99
+ : baseChildIds.includes(value ?? '');
110
100
 
111
101
  const handleOnSelect = () => {
112
102
  if (checked) {
@@ -114,13 +104,8 @@ export function useGroupItemSelection({ id, disabled, allChildIds }: UseGroupIte
114
104
  return;
115
105
  }
116
106
 
117
- if (isIndeterminate) {
118
- setValue?.((value: ItemId[]) => Array.from(new Set([...(value ?? []), ...baseChildIds, id])));
119
- return;
120
- }
121
-
122
- setValue?.((value: ItemId[]) => (value ?? []).concat([...baseChildIds, id ?? '']));
107
+ setValue?.((value: ItemId[]) => Array.from(new Set([...(value ?? []), ...baseChildIds])));
123
108
  };
124
109
 
125
- return { checked, isIndeterminate, handleOnSelect };
110
+ return { checked, indeterminate, handleOnSelect };
126
111
  }
@@ -35,7 +35,7 @@ export function ItemContent({
35
35
  className={cn(styles.content, className)}
36
36
  {...extractSupportProps(rest)}
37
37
  data-size={size ?? 's'}
38
- data-disabled={disabled ?? undefined}
38
+ data-disabled={disabled || undefined}
39
39
  >
40
40
  <div className={styles.headline}>
41
41
  <span className={styles.label}>
@@ -69,7 +69,7 @@ $typography: (
69
69
  }
70
70
 
71
71
  &[data-disabled] {
72
- .option,
72
+ .label,
73
73
  .description,
74
74
  .caption {
75
75
  color: $sys-neutral-text-disabled;
@@ -22,21 +22,27 @@ export function ListEmptyState({ dataError, dataFiltered, hasNoItems, emptyState
22
22
  }
23
23
 
24
24
  if (dataError) {
25
- <div className={styles.listEmptyStateWrapper}>
26
- <InfoBlock {...emptyStates.errorDataState} size='s' align='vertical' />
27
- </div>;
25
+ return (
26
+ <div className={styles.listEmptyStateWrapper}>
27
+ <InfoBlock {...emptyStates.errorDataState} size='s' align='vertical' />
28
+ </div>
29
+ );
28
30
  }
29
31
 
30
32
  if (dataFiltered && hasNoItems) {
31
- <div className={styles.listEmptyStateWrapper}>
32
- <InfoBlock {...emptyStates.noResultsState} size='s' align='vertical' data-test-id='list__no-results' />
33
- </div>;
33
+ return (
34
+ <div className={styles.listEmptyStateWrapper}>
35
+ <InfoBlock {...emptyStates.noResultsState} size='s' align='vertical' data-test-id='list__no-results' />
36
+ </div>
37
+ );
34
38
  }
35
39
 
36
40
  if (!dataFiltered && hasNoItems) {
37
- <div className={styles.listEmptyStateWrapper}>
38
- <InfoBlock {...emptyStates.noDataState} size='s' align='vertical' data-test-id='list__no-data' />
39
- </div>;
41
+ return (
42
+ <div className={styles.listEmptyStateWrapper}>
43
+ <InfoBlock {...emptyStates.noDataState} size='s' align='vertical' data-test-id='list__no-data' />
44
+ </div>
45
+ );
40
46
  }
41
47
 
42
48
  return null;
package/src/utils.ts CHANGED
@@ -52,9 +52,10 @@ export function kindFlattenItems<Meta = AnyType>({ items, prefix, parentId }: Ki
52
52
  const closeChildIds: Array<number | string> = [];
53
53
 
54
54
  const { items } = item;
55
+ const childActiveParent = isGroupItemProps<Meta>(item) ? parentId ?? '~main' : itemId;
55
56
 
56
57
  for (let idx = 0; idx < items.length; idx++) {
57
- const { id, children } = flatten({ item: items[idx], idx, prefix: itemId, parentId: itemId });
58
+ const { id, children } = flatten({ item: items[idx], idx, prefix: itemId, parentId: childActiveParent });
58
59
 
59
60
  closeChildIds.push(id);
60
61
  allChildIds = allChildIds.concat(children);