@snack-uikit/list 0.7.2 → 0.8.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.8.0 (2024-03-11)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-4491:** add truncate prop to droplist items, add test-ids to caption and description ([c321e1b](https://github.com/cloud-ru-tech/snack-uikit/commit/c321e1bb199fc7997a0cfb8467f98b0acd7f8b6a))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.7.2 (2024-03-07)
7
18
 
8
19
 
@@ -19,8 +19,9 @@ import commonStyles from '../styles.module.css';
19
19
  import { CHECKBOX_SIZE_MAP } from './constants';
20
20
  import styles from './styles.module.css';
21
21
  export function BaseItem(_a) {
22
+ var _b, _c;
22
23
  var { beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "onMouseDown", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "onSelect", "isParentNode", "className", "inactive", "itemWrapRender"]);
23
- const { option, caption, description } = content || {};
24
+ const { option, caption, description, truncate: contentTruncate } = content || {};
24
25
  const interactive = !inactive;
25
26
  const { parentResetActiveFocusIndex } = useParentListContext();
26
27
  const { size, marker, parent } = useListContext();
@@ -70,7 +71,7 @@ export function BaseItem(_a) {
70
71
  e.stopPropagation();
71
72
  };
72
73
  const props = extractSupportProps(rest);
73
- 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, onMouseDown: onMouseDown, 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, "data-disabled": disabled || 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 })] }));
74
+ 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, onMouseDown: onMouseDown, 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, "data-disabled": disabled || 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: (_b = contentTruncate === null || contentTruncate === void 0 ? void 0 : contentTruncate.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 = contentTruncate === null || contentTruncate === void 0 ? void 0 : contentTruncate.description) !== null && _c !== void 0 ? _c : 2, "data-test-id": 'list__base-item-description' }) }))] }), 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 })] }));
74
75
  if (!itemWrapRender) {
75
76
  return item;
76
77
  }
@@ -6,6 +6,10 @@ export type ItemContentProps = {
6
6
  option: string;
7
7
  caption?: string;
8
8
  description?: string;
9
+ truncate?: {
10
+ option?: number;
11
+ description?: number;
12
+ };
9
13
  };
10
14
  export type BaseItemPrivateProps = {
11
15
  expandIcon?: ReactNode;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "List",
7
- "version": "0.7.2",
7
+ "version": "0.8.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -54,5 +54,5 @@
54
54
  "peerDependencies": {
55
55
  "@snack-uikit/locale": "*"
56
56
  },
57
- "gitHead": "abae3f94b848eff630e5079163d84e67feae7f3a"
57
+ "gitHead": "113e80e60c1a5ce1ce6957d48d37a6181991c5fd"
58
58
  }
@@ -36,7 +36,7 @@ export function BaseItem({
36
36
  itemWrapRender,
37
37
  ...rest
38
38
  }: AllBaseItemProps) {
39
- const { option, caption, description } = content || {};
39
+ const { option, caption, description, truncate: contentTruncate } = content || {};
40
40
  const interactive = !inactive;
41
41
 
42
42
  const { parentResetActiveFocusIndex } = useParentListContext();
@@ -145,14 +145,22 @@ export function BaseItem({
145
145
  <div className={styles.content}>
146
146
  <div className={styles.headline}>
147
147
  <span className={styles.option}>
148
- <TruncateString text={option} maxLines={1} />
148
+ <TruncateString
149
+ text={option}
150
+ maxLines={contentTruncate?.option ?? 1}
151
+ data-test-id='list__base-item-option'
152
+ />
149
153
  </span>
150
154
  {caption && <span className={styles.caption}>{caption}</span>}
151
155
  </div>
152
156
 
153
157
  {description && (
154
158
  <div className={styles.description}>
155
- <TruncateString text={description} maxLines={2} />
159
+ <TruncateString
160
+ text={description}
161
+ maxLines={contentTruncate?.description ?? 2}
162
+ data-test-id='list__base-item-description'
163
+ />
156
164
  </div>
157
165
  )}
158
166
  </div>
@@ -9,6 +9,10 @@ export type ItemContentProps = {
9
9
  option: string;
10
10
  caption?: string;
11
11
  description?: string;
12
+ truncate?: {
13
+ option?: number;
14
+ description?: number;
15
+ };
12
16
  };
13
17
 
14
18
  export type BaseItemPrivateProps = {