@snack-uikit/list 0.3.0 → 0.3.1-preview-744f94d0.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.
@@ -23,7 +23,7 @@ export function BaseItem(_a) {
23
23
  const { option, caption, description } = content || {};
24
24
  const interactive = !inactive;
25
25
  const { parentResetActiveFocusIndex } = useParentListContext();
26
- const { size, marker } = useListContext();
26
+ const { size, marker, parent } = useListContext();
27
27
  const { level = 0 } = useCollapseContext();
28
28
  const { value, onChange, mode, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
29
29
  const isChecked = isSelectionSingle ? value === id : value === null || value === void 0 ? void 0 : value.includes(id);
@@ -68,7 +68,7 @@ export function BaseItem(_a) {
68
68
  e.stopPropagation();
69
69
  };
70
70
  const props = extractSupportProps(rest);
71
- const item = (_jsxs("li", { role: 'menuitem', "data-test-id": props['data-test-id'] || 'list__base-item_' + id, ref: itemRef, className: cn(commonStyles.listItem, styles.droplistItem, className), "data-size": size, onClick: handleItemClick, tabIndex: -1, "data-non-pointer": inactive && !onClick, "data-inactive": inactive || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "aria-disabled": disabled || undefined, onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, children: [!switchProp && isSelectionSingle && marker && !isParentNode && interactive && (_jsx("div", { className: styles.markerContainer, "data-test-id": 'list__base-item-marker' })), !switchProp && isSelectionMultiple && interactive && (_jsx("div", { className: styles.checkbox, children: _jsx(Checkbox, { size: CHECKBOX_SIZE_MAP[size !== null && size !== void 0 ? size : 's'], disabled: disabled, tabIndex: -1, onChange: handleCheckboxChange, checked: isChecked, "data-test-id": 'list__base-item-checkbox', onClick: handleCheckboxClick, indeterminate: indeterminate }) })), beforeContent && _jsx("div", { className: styles.beforeContent, children: beforeContent }), _jsxs("div", { className: styles.content, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.option, children: _jsx(TruncateString, { text: option, maxLines: 1 }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: 2 }) }))] }), afterContent, switchProp && interactive && (_jsx(Switch, { disabled: disabled, checked: isChecked, "data-test-id": 'list__base-item-switch' })), !switchProp && expandIcon && _jsx("span", { className: styles.expandableIcon, children: expandIcon })] }));
71
+ const item = (_jsxs("li", { role: 'menuitem', "data-test-id": props['data-test-id'] || 'list__base-item_' + id, ref: itemRef, className: cn(commonStyles.listItem, styles.droplistItem, className), "data-size": size, onClick: handleItemClick, tabIndex: -1, "data-non-pointer": inactive && !onClick, "data-inactive": inactive || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "aria-disabled": disabled || undefined, "data-parent": parent || 'list', onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, children: [!switchProp && isSelectionSingle && marker && !isParentNode && interactive && (_jsx("div", { className: styles.markerContainer, "data-test-id": 'list__base-item-marker' })), !switchProp && isSelectionMultiple && interactive && (_jsx("div", { className: styles.checkbox, children: _jsx(Checkbox, { size: CHECKBOX_SIZE_MAP[size !== null && size !== void 0 ? size : 's'], disabled: disabled, tabIndex: -1, onChange: handleCheckboxChange, checked: isChecked, "data-test-id": 'list__base-item-checkbox', onClick: handleCheckboxClick, indeterminate: indeterminate }) })), beforeContent && _jsx("div", { className: styles.beforeContent, children: beforeContent }), _jsxs("div", { className: styles.content, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.option, children: _jsx(TruncateString, { text: option, maxLines: 1 }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: 2 }) }))] }), afterContent, switchProp && interactive && (_jsx(Switch, { disabled: disabled, checked: isChecked, "data-test-id": 'list__base-item-switch' })), !switchProp && expandIcon && _jsx("span", { className: styles.expandableIcon, children: expandIcon })] }));
72
72
  if (!itemWrapRender) {
73
73
  return item;
74
74
  }
@@ -72,6 +72,7 @@
72
72
  }
73
73
 
74
74
  .content{
75
+ overflow:hidden;
75
76
  flex-grow:1;
76
77
  flex-shrink:1;
77
78
  box-sizing:border-box;
@@ -170,6 +171,13 @@
170
171
  letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
171
172
  paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
172
173
  }
174
+ .droplistItem[data-parent=list]{
175
+ width:100%;
176
+ }
177
+ .droplistItem[data-parent=droplist]{
178
+ width:-moz-max-content;
179
+ width:max-content;
180
+ }
173
181
  .droplistItem[data-non-pointer]{
174
182
  cursor:inherit;
175
183
  }
@@ -95,7 +95,7 @@ export function Droplist(_a) {
95
95
  parentResetNestedIndex: resetNestedIndex,
96
96
  parentResetActiveFocusIndex: resetActiveFocusIndex,
97
97
  toggleOpenCollapsedItems: id => setOpenCollapsedItems((items = []) => items.includes(id) ? items.filter(item => item !== id) : items === null || items === void 0 ? void 0 : items.concat([id])),
98
- }, children: _jsx(Dropdown, Object.assign({ content: _jsx(ListPrivate, Object.assign({ onKeyDown: handleListKeyDown, tabIndex: 0, ref: listRef, search: search, limitedScrollHeight: true }, slicedItems, props)), trigger: trigger, placement: placement, widthStrategy: widthStrategy }, (triggerElemRefProp
98
+ }, children: _jsx(Dropdown, Object.assign({ content: _jsx(ListPrivate, Object.assign({}, slicedItems, props, { onKeyDown: handleListKeyDown, tabIndex: 0, ref: listRef, search: search, limitedScrollHeight: true, parent: 'droplist' })), trigger: trigger, placement: placement, widthStrategy: widthStrategy }, (triggerElemRefProp
99
99
  ? {}
100
100
  : {
101
101
  triggerRef: triggerElemRef,
@@ -87,5 +87,5 @@ export const List = forwardRef((_a, ref) => {
87
87
  parentResetActiveFocusIndex: resetActiveFocusIndex,
88
88
  openCollapsedItems,
89
89
  toggleOpenCollapsedItems: id => setOpenCollapsedItems((items = []) => items.includes(id) ? items.filter(item => item !== id) : items === null || items === void 0 ? void 0 : items.concat([id])),
90
- }, children: _jsxs("div", { className: cn(styles.wrapper, className), "data-active": isActive || undefined, children: [_jsx(ListPrivate, Object.assign({}, props, slicedItems, { ref: mergeRefs(ref, listRef), onFocus: handleOnFocus, onKeyDown: mergedHandlerKeyDown, tabIndex: tabIndex, search: search, nested: false })), _jsx(HiddenTabButton, { ref: btnRef, listRef: listRef, tabIndex: tabIndex })] }) }) })));
90
+ }, children: _jsxs("div", { className: cn(styles.wrapper, className), "data-active": isActive || undefined, children: [_jsx(ListPrivate, Object.assign({}, props, slicedItems, { ref: mergeRefs(ref, listRef), onFocus: handleOnFocus, onKeyDown: mergedHandlerKeyDown, tabIndex: tabIndex, search: search, nested: false, parent: 'list' })), _jsx(HiddenTabButton, { ref: btnRef, listRef: listRef, tabIndex: tabIndex })] }) }) })));
91
91
  });
@@ -19,7 +19,7 @@ export declare const ListPrivate: import("react").ForwardRefExoticComponent<{
19
19
  } | undefined;
20
20
  className?: string | undefined;
21
21
  onKeyDown?(e: import("react").KeyboardEvent<HTMLElement>): void;
22
- } & import("../contexts").SelectionState & import("../contexts").ListContextType & import("../../../types").ScrollProps & {
22
+ } & import("../contexts").SelectionState & import("../contexts").ListContextType & import("../../../types").ScrollProps & import("../contexts").ListContextPrivateType & {
23
23
  nested?: boolean | undefined;
24
24
  active?: boolean | undefined;
25
25
  tabIndex?: number | undefined;
@@ -22,7 +22,7 @@ import commonStyles from '../styles.module.css';
22
22
  import styles from './styles.module.css';
23
23
  export const ListPrivate = forwardRef((_a, ref) => {
24
24
  var _b, _c;
25
- var { items, pinTop, pinBottom, onKeyDown, onBlur, onFocus, tabIndex, active, scroll, nested, search, scrollRef, scrollContainerRef, footer, loading, noData = 'No data', noResults = 'No results', size = 's', marker, limitedScrollHeight, className } = _a, props = __rest(_a, ["items", "pinTop", "pinBottom", "onKeyDown", "onBlur", "onFocus", "tabIndex", "active", "scroll", "nested", "search", "scrollRef", "scrollContainerRef", "footer", "loading", "noData", "noResults", "size", "marker", "limitedScrollHeight", "className"]);
25
+ var { items, pinTop, pinBottom, onKeyDown, onBlur, onFocus, tabIndex, active, scroll, nested, search, scrollRef, scrollContainerRef, footer, loading, noData = 'No data', noResults = 'No results', size = 's', marker, limitedScrollHeight, className, parent = 'list' } = _a, props = __rest(_a, ["items", "pinTop", "pinBottom", "onKeyDown", "onBlur", "onFocus", "tabIndex", "active", "scroll", "nested", "search", "scrollRef", "scrollContainerRef", "footer", "loading", "noData", "noResults", "size", "marker", "limitedScrollHeight", "className", "parent"]);
26
26
  const itemsJSX = useRenderItems(items);
27
27
  const itemsPinTopJSX = useRenderItems(pinTop !== null && pinTop !== void 0 ? pinTop : []);
28
28
  const itemsPinBottomJSX = useRenderItems(pinBottom !== null && pinBottom !== void 0 ? pinBottom : []);
@@ -35,7 +35,7 @@ export const ListPrivate = forwardRef((_a, ref) => {
35
35
  [commonStyles.scrollContainerL]: scroll && limitedScrollHeight && size === 'l',
36
36
  }), barHideStrategy: 'leave', size: size === 's' ? 's' : 'm', ref: scrollContainerRef, children: [content, _jsx("div", { className: styles.scrollStub, ref: scrollRef })] })) : (_jsx(_Fragment, { children: content })), (Number(pinBottom === null || pinBottom === void 0 ? void 0 : pinBottom.length) > 0 || footer) && (_jsxs(PinBottomGroupItem, { children: [Number(pinBottom === null || pinBottom === void 0 ? void 0 : pinBottom.length) > 0 && itemsPinBottomJSX, footer && _jsx("div", { className: styles.footer, children: footer })] }))] }) })));
37
37
  if (!nested) {
38
- return (_jsx(ListContextProvider, { size: size, marker: marker, children: listJSX }));
38
+ return (_jsx(ListContextProvider, { size: size, marker: marker, parent: parent, children: listJSX }));
39
39
  }
40
40
  return (_jsx("li", { style: { listStyleType: 'none' }, role: 'menuitem', children: listJSX }));
41
41
  });
@@ -38,9 +38,6 @@
38
38
  .footer{
39
39
  display:flex;
40
40
  flex-direction:column;
41
- gap:var(--dimension-050m, 4px);
42
- align-items:center;
43
- justify-content:center;
44
41
  box-sizing:border-box;
45
42
  padding:var(--dimension-050m, 4px);
46
43
  }
@@ -5,10 +5,13 @@ export type ListContextType = {
5
5
  /** Отображать ли маркер у выбранного жлемента списка */
6
6
  marker?: boolean;
7
7
  };
8
+ export type ListContextPrivateType = {
9
+ parent?: 'list' | 'droplist';
10
+ };
8
11
  type Child = {
9
12
  children: ReactNode;
10
13
  };
11
- export declare const ListContext: import("react").Context<ListContextType>;
12
- export declare const useListContext: () => ListContextType;
13
- export declare function ListContextProvider({ children, ...props }: ListContextType & Child): import("react/jsx-runtime").JSX.Element;
14
+ export declare const ListContext: import("react").Context<ListContextType & ListContextPrivateType>;
15
+ export declare const useListContext: () => ListContextType & ListContextPrivateType;
16
+ export declare function ListContextProvider({ children, ...props }: ListContextType & Child & ListContextPrivateType): import("react/jsx-runtime").JSX.Element;
14
17
  export {};
@@ -13,8 +13,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { createContext, useContext } from 'react';
14
14
  export const ListContext = createContext({});
15
15
  export const useListContext = () => useContext(ListContext);
16
- function extractListProps({ size, marker }) {
17
- return { size, marker };
16
+ function extractListProps({ size, marker, parent }) {
17
+ return { size, marker, parent };
18
18
  }
19
19
  export function ListContextProvider(_a) {
20
20
  var { children } = _a, props = __rest(_a, ["children"]);
@@ -3,7 +3,7 @@ import { DropdownProps } from '@snack-uikit/dropdown';
3
3
  import { WithSupportProps } from '@snack-uikit/utils';
4
4
  import { ScrollProps, SearchState } from '../../types';
5
5
  import { ItemProps } from '../Items';
6
- import { ListContextType, SelectionState } from './contexts';
6
+ import { ListContextPrivateType, ListContextType, SelectionState } from './contexts';
7
7
  type CollapseState = {
8
8
  value?: (string | number)[];
9
9
  onChange?(value: (string | number)[]): void;
@@ -45,7 +45,7 @@ export type DroplistProps = {
45
45
  /** Триггер для дроплиста */
46
46
  children?: ReactNode;
47
47
  } & Pick<DropdownProps, 'trigger' | 'placement' | 'widthStrategy' | 'open' | 'onOpenChange'> & Omit<ListProps, 'tabIndex' | 'onKeyDown'>;
48
- export type ListPrivateProps = ListProps & {
48
+ export type ListPrivateProps = ListProps & ListContextPrivateType & {
49
49
  nested?: boolean;
50
50
  active?: boolean;
51
51
  tabIndex?: number;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "List",
7
- "version": "0.3.0",
7
+ "version": "0.3.1-preview-744f94d0.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -45,5 +45,5 @@
45
45
  "merge-refs": "1.2.2",
46
46
  "uncontrollable": "8.0.4"
47
47
  },
48
- "gitHead": "88a44a8f4c6490f3004f7feac3d50d17ff03f31c"
48
+ "gitHead": "66388dea37bc61fd867e4231d413486aa687bc48"
49
49
  }
@@ -39,7 +39,7 @@ export function BaseItem({
39
39
  const interactive = !inactive;
40
40
 
41
41
  const { parentResetActiveFocusIndex } = useParentListContext();
42
- const { size, marker } = useListContext();
42
+ const { size, marker, parent } = useListContext();
43
43
  const { level = 0 } = useCollapseContext();
44
44
  const { value, onChange, mode, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
45
45
 
@@ -112,6 +112,7 @@ export function BaseItem({
112
112
  data-variant={mode || undefined}
113
113
  data-open={open || undefined}
114
114
  aria-disabled={disabled || undefined}
115
+ data-parent={parent || 'list'}
115
116
  onKeyDown={handleItemKeyDown}
116
117
  onFocus={handleItemFocus}
117
118
  style={{ '--level': level }}
@@ -104,6 +104,7 @@ $typography: (
104
104
  }
105
105
 
106
106
  .content {
107
+ overflow: hidden;
107
108
  flex-grow: 1;
108
109
  flex-shrink: 1;
109
110
  box-sizing: border-box;
@@ -134,6 +135,14 @@ $typography: (
134
135
  }
135
136
  }
136
137
 
138
+ &[data-parent='list'] {
139
+ width: 100%;
140
+ }
141
+
142
+ &[data-parent='droplist'] {
143
+ width: max-content;
144
+ }
145
+
137
146
  &[data-non-pointer] {
138
147
  cursor: inherit;
139
148
  }
@@ -147,13 +147,14 @@ export function Droplist({
147
147
  <Dropdown
148
148
  content={
149
149
  <ListPrivate
150
+ {...slicedItems}
151
+ {...props}
150
152
  onKeyDown={handleListKeyDown}
151
153
  tabIndex={0}
152
154
  ref={listRef}
153
155
  search={search}
154
156
  limitedScrollHeight
155
- {...slicedItems}
156
- {...props}
157
+ parent='droplist'
157
158
  />
158
159
  }
159
160
  trigger={trigger}
@@ -141,6 +141,7 @@ export const List = forwardRef<HTMLElement, ListProps>(
141
141
  tabIndex={tabIndex}
142
142
  search={search}
143
143
  nested={false}
144
+ parent='list'
144
145
  />
145
146
 
146
147
  <HiddenTabButton ref={btnRef} listRef={listRef} tabIndex={tabIndex} />
@@ -36,6 +36,7 @@ export const ListPrivate = forwardRef<HTMLElement, ListPrivateProps>(
36
36
  marker,
37
37
  limitedScrollHeight,
38
38
  className,
39
+ parent = 'list',
39
40
  ...props
40
41
  },
41
42
  ref,
@@ -135,7 +136,7 @@ export const ListPrivate = forwardRef<HTMLElement, ListPrivateProps>(
135
136
 
136
137
  if (!nested) {
137
138
  return (
138
- <ListContextProvider size={size} marker={marker}>
139
+ <ListContextProvider size={size} marker={marker} parent={parent}>
139
140
  {listJSX}
140
141
  </ListContextProvider>
141
142
  );
@@ -39,10 +39,6 @@ $loader-height: (
39
39
  .footer {
40
40
  display: flex;
41
41
  flex-direction: column;
42
- gap: $dimension-050m;
43
- align-items: center;
44
- justify-content: center;
45
-
46
42
  box-sizing: border-box;
47
43
  padding: $dimension-050m;
48
44
  }
@@ -7,18 +7,22 @@ export type ListContextType = {
7
7
  marker?: boolean;
8
8
  };
9
9
 
10
+ export type ListContextPrivateType = {
11
+ parent?: 'list' | 'droplist';
12
+ };
13
+
10
14
  type Child = {
11
15
  children: ReactNode;
12
16
  };
13
17
 
14
- export const ListContext = createContext<ListContextType>({});
18
+ export const ListContext = createContext<ListContextType & ListContextPrivateType>({});
15
19
 
16
20
  export const useListContext = () => useContext(ListContext);
17
21
 
18
- function extractListProps<T extends ListContextType>({ size, marker }: T) {
19
- return { size, marker };
22
+ function extractListProps<T extends ListContextType & ListContextPrivateType>({ size, marker, parent }: T) {
23
+ return { size, marker, parent };
20
24
  }
21
25
 
22
- export function ListContextProvider({ children, ...props }: ListContextType & Child) {
26
+ export function ListContextProvider({ children, ...props }: ListContextType & Child & ListContextPrivateType) {
23
27
  return <ListContext.Provider value={extractListProps(props)}>{children}</ListContext.Provider>;
24
28
  }
@@ -5,7 +5,7 @@ import { WithSupportProps } from '@snack-uikit/utils';
5
5
 
6
6
  import { ScrollProps, SearchState } from '../../types';
7
7
  import { ItemProps } from '../Items';
8
- import { ListContextType, SelectionState } from './contexts';
8
+ import { ListContextPrivateType, ListContextType, SelectionState } from './contexts';
9
9
 
10
10
  type CollapseState = {
11
11
  value?: (string | number)[];
@@ -56,12 +56,13 @@ export type DroplistProps = {
56
56
  } & Pick<DropdownProps, 'trigger' | 'placement' | 'widthStrategy' | 'open' | 'onOpenChange'> &
57
57
  Omit<ListProps, 'tabIndex' | 'onKeyDown'>;
58
58
 
59
- export type ListPrivateProps = ListProps & {
60
- nested?: boolean;
61
- active?: boolean;
62
- tabIndex?: number;
63
- onFocus?(e: FocusEvent<HTMLElement>): void;
64
- onBlur?(e: FocusEvent<HTMLElement>): void;
65
- onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
66
- limitedScrollHeight?: boolean;
67
- };
59
+ export type ListPrivateProps = ListProps &
60
+ ListContextPrivateType & {
61
+ nested?: boolean;
62
+ active?: boolean;
63
+ tabIndex?: number;
64
+ onFocus?(e: FocusEvent<HTMLElement>): void;
65
+ onBlur?(e: FocusEvent<HTMLElement>): void;
66
+ onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
67
+ limitedScrollHeight?: boolean;
68
+ };