@synerise/ds-item-picker 1.0.7 → 1.1.1

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,26 @@
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
+ ## [1.1.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-item-picker@1.1.0...@synerise/ds-item-picker@1.1.1) (2025-04-24)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-item-picker
9
+
10
+
11
+
12
+
13
+
14
+ # [1.1.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-item-picker@1.0.7...@synerise/ds-item-picker@1.1.0) (2025-04-16)
15
+
16
+
17
+ ### Features
18
+
19
+ * **form-field:** add form-field component ([7f6b191](https://github.com/Synerise/synerise-design/commit/7f6b191132a3b0d694c21fb4d649f4deea6acb89))
20
+ * **item-picker:** custom limit per section ([d45ec39](https://github.com/Synerise/synerise-design/commit/d45ec3951828811a03ca89bdbb3f39c91a120e22))
21
+
22
+
23
+
24
+
25
+
6
26
  ## [1.0.7](https://github.com/Synerise/synerise-design/compare/@synerise/ds-item-picker@1.0.6...@synerise/ds-item-picker@1.0.7) (2025-04-08)
7
27
 
8
28
  **Note:** Version bump only for package @synerise/ds-item-picker
@@ -1,6 +1,3 @@
1
1
  export declare const ItemPickerWrapper: import("styled-components").StyledComponent<"div", any, {
2
2
  disabled?: boolean | undefined;
3
3
  }, never>;
4
- export declare const Error: import("styled-components").StyledComponent<"div", any, {
5
- disabled?: boolean | undefined;
6
- }, never>;
@@ -1,12 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { Description } from '@synerise/ds-typography';
3
2
  export var ItemPickerWrapper = styled.div.withConfig({
4
3
  displayName: "ItemPickerstyles__ItemPickerWrapper",
5
4
  componentId: "sc-1dxa5ip-0"
6
- })(["display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;position:relative;& > label{margin-bottom:8px;}", "{margin-top:8px;}"], Description);
7
- export var Error = styled(Description).withConfig({
8
- displayName: "ItemPickerstyles__Error",
9
- componentId: "sc-1dxa5ip-1"
10
- })(["color:", ";"], function (props) {
11
- return props.theme.palette['red-600'];
12
- });
5
+ })(["position:relative;"]);
@@ -3,5 +3,5 @@ import { ItemPickerProps } from './ItemPickerLegacy.types';
3
3
  /**
4
4
  * @deprecated - use new ItemPicker
5
5
  */
6
- declare const ItemPickerLegacy: ({ dataSource, onChange, onClear, placeholder, changeButtonLabel, clear, clearConfirmTitle, closeOnBottomAction, description, disabled, dropdownBottomAction, dropdownProps, dropdownRowHeight, dropdownVisibleRows, error, errorMessage, label, onBlur, onFocus, noResults, noText, placeholderIcon, searchPlaceholder, searchBarProps, selectedItem, tooltip, size, yesText, withClearConfirmation, scrollbarProps, informationCardTooltipProps, hideSearchBar, }: ItemPickerProps) => React.JSX.Element;
6
+ declare const ItemPickerLegacy: ({ dataSource, onChange, onClear, placeholder, changeButtonLabel, clear, clearConfirmTitle, closeOnBottomAction, description, disabled, dropdownBottomAction, dropdownProps, dropdownRowHeight, dropdownVisibleRows, error, errorMessage, label, onBlur, onFocus, noResults, noText, placeholderIcon, searchPlaceholder, searchBarProps, selectedItem, tooltip, tooltipConfig, size, yesText, withClearConfirmation, scrollbarProps, informationCardTooltipProps, hideSearchBar, }: ItemPickerProps) => React.JSX.Element;
7
7
  export default ItemPickerLegacy;
@@ -1,8 +1,7 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  import React, { useState, useCallback, useMemo, useRef } from 'react';
3
3
  import { useIntl } from 'react-intl';
4
- import { Label } from '@synerise/ds-input';
5
- import { Description } from '@synerise/ds-typography';
4
+ import FormField from '@synerise/ds-form-field';
6
5
  import Dropdown from '@synerise/ds-dropdown';
7
6
  import * as S from '../../ItemPicker.styles';
8
7
  import ItemPickerDropdown from '../ItemPickerDropdown/ItemPickerDropdown';
@@ -39,6 +38,7 @@ var ItemPickerLegacy = function ItemPickerLegacy(_ref) {
39
38
  searchBarProps = _ref.searchBarProps,
40
39
  selectedItem = _ref.selectedItem,
41
40
  tooltip = _ref.tooltip,
41
+ tooltipConfig = _ref.tooltipConfig,
42
42
  _ref$size = _ref.size,
43
43
  size = _ref$size === void 0 ? 'small' : _ref$size,
44
44
  yesText = _ref.yesText,
@@ -143,15 +143,18 @@ var ItemPickerLegacy = function ItemPickerLegacy(_ref) {
143
143
  return /*#__PURE__*/React.createElement(S.ItemPickerWrapper, {
144
144
  className: "ds-items-picker",
145
145
  disabled: disabled
146
- }, label && /*#__PURE__*/React.createElement(Label, {
146
+ }, /*#__PURE__*/React.createElement(FormField, {
147
147
  label: label,
148
- tooltip: tooltip
149
- }), /*#__PURE__*/React.createElement(Dropdown, _extends({
148
+ tooltip: tooltip,
149
+ tooltipConfig: tooltipConfig,
150
+ errorText: errorMessage,
151
+ description: description
152
+ }, /*#__PURE__*/React.createElement(Dropdown, _extends({
150
153
  visible: dropdownOpened,
151
154
  disabled: disabled,
152
155
  trigger: ['click'],
153
156
  overlay: dropdownOverlay,
154
157
  onVisibleChange: onVisibilityChange
155
- }, dropdownProps), renderTrigger), error && errorMessage && /*#__PURE__*/React.createElement(S.Error, null, errorMessage), description && /*#__PURE__*/React.createElement(Description, null, description));
158
+ }, dropdownProps), renderTrigger)));
156
159
  };
157
160
  export default ItemPickerLegacy;
@@ -5,6 +5,7 @@ import type { DropdownProps } from '@synerise/ds-dropdown';
5
5
  import type { InformationCardTooltipProps } from '@synerise/ds-information-card';
6
6
  import type { ListItemProps } from '@synerise/ds-list-item';
7
7
  import type { ScrollbarAdditionalProps } from '@synerise/ds-scrollbar';
8
+ import type { FormFieldCommonProps } from '@synerise/ds-form-field';
8
9
  export type ItemPickerSize = 'small' | 'large';
9
10
  export type ItemPickerProps<ItemType extends ListItemProps = ListItemProps> = {
10
11
  dataSource: ItemType[];
@@ -16,15 +17,13 @@ export type ItemPickerProps<ItemType extends ListItemProps = ListItemProps> = {
16
17
  clear?: ReactNode;
17
18
  clearConfirmTitle?: string;
18
19
  closeOnBottomAction?: boolean;
19
- description?: ReactNode;
20
20
  disabled?: boolean;
21
21
  dropdownBottomAction?: ReactNode;
22
22
  dropdownProps?: Partial<DropdownProps>;
23
23
  dropdownRowHeight?: number;
24
24
  dropdownVisibleRows?: number;
25
25
  error?: boolean;
26
- errorMessage?: ReactNode;
27
- label?: ReactNode;
26
+ errorMessage?: FormFieldCommonProps['errorText'];
28
27
  onBlur?: () => void;
29
28
  onFocus?: () => void;
30
29
  noResults?: string;
@@ -35,9 +34,8 @@ export type ItemPickerProps<ItemType extends ListItemProps = ListItemProps> = {
35
34
  selectedItem?: ItemType | undefined;
36
35
  hideSearchBar?: boolean;
37
36
  size?: ItemPickerSize;
38
- tooltip?: ReactNode;
39
37
  informationCardTooltipProps?: Omit<InformationCardTooltipProps, 'children'>;
40
38
  withClearConfirmation?: boolean;
41
39
  yesText?: string;
42
40
  scrollbarProps?: ScrollbarAdditionalProps;
43
- };
41
+ } & Omit<FormFieldCommonProps, 'errorText'>;
@@ -174,7 +174,7 @@ export var ItemPickerList = function ItemPickerList(_ref) {
174
174
  component: /*#__PURE__*/React.createElement(ArrowLeftM, null)
175
175
  })]
176
176
  },
177
- label: currentPath ? currentPath.slice(1).join(' - ') : currentSection.text,
177
+ label: currentPath ? currentPath.join(' - ') : currentSection.text,
178
178
  onClick: goBack
179
179
  }), (mergedItemsList == null ? void 0 : mergedItemsList.length) === 0 ? /*#__PURE__*/React.createElement(EmptyListMessage, {
180
180
  buttonOnClick: function buttonOnClick() {
@@ -3,7 +3,7 @@ import type { ListItemProps } from '@synerise/ds-list-item';
3
3
  import type { ScrollbarAdditionalProps } from '@synerise/ds-scrollbar';
4
4
  import type { SearchBarProps } from '@synerise/ds-search-bar';
5
5
  import type { WithHTMLAttributes } from '@synerise/ds-utils';
6
- import type { BaseSectionType, BaseSectionTypeWithFolders, ItemLoaderConfig, ActionType, ContainerHeightType, BaseItemType } from '../ItemPickerNew/ItemPickerNew.types';
6
+ import type { BaseSectionType, BaseSectionTypeWithFolders, ItemLoaderConfig, ActionType, ContainerHeightType, BaseItemType, ItemsConfig } from '../ItemPickerNew/ItemPickerNew.types';
7
7
  type TextsAsReactNode = 'searchPlaceholder' | 'refreshButtonLabel' | 'showMoreResultsLabel' | 'noItems' | 'noResults' | 'noResultsInSection' | 'searchAllFoldersButtonLabel' | 'recentsSectionLabel' | 'actionsSectionLabel' | 'resultsSectionLabel' | 'noActions' | 'itemsSectionLabel' | 'infiniteScrollLoadingMore' | 'infiniteScrollLoadingError' | 'errorMessageTitle' | 'errorMessageDetails' | 'backTooltip' | 'clearSearchTooltip' | 'infiniteScrollAllLoaded';
8
8
  export type ItemPickerListTexts = {
9
9
  [key in TextsAsReactNode]: ReactNode;
@@ -23,7 +23,7 @@ export type ItemPickerListProps<ItemType extends BaseItemType, SectionType exten
23
23
  scrollbarProps?: ScrollbarAdditionalProps;
24
24
  searchBarProps?: Omit<SearchBarProps, 'value' | 'onSearchChange' | 'placeholder'>;
25
25
  onRefresh?: () => void;
26
- items: ItemType[] | ItemLoaderConfig<ItemType>;
26
+ items: ItemType[] | ItemsConfig<ItemType> | ItemLoaderConfig<ItemType>;
27
27
  isLoading?: boolean;
28
28
  isVisible?: boolean;
29
29
  sections?: SectionType extends BaseSectionType ? BaseSectionTypeWithFolders<SectionType>[] : undefined;
@@ -5,7 +5,22 @@ type NestedFoldersProps<SectionType extends BaseSectionType | undefined> = {
5
5
  sections?: SectionType extends BaseSectionType ? BaseSectionTypeWithFolders<SectionType>[] : undefined;
6
6
  };
7
7
  export declare const useFlattenFolders: <SectionType extends BaseSectionType | undefined>({ currentSection, sections, }: NestedFoldersProps<SectionType>) => {
8
- allFolders: ({
8
+ allFolders: {
9
+ titles: ReactNode[] | undefined;
10
+ type?: import("@synerise/ds-list-item").ItemType | undefined;
11
+ id: string;
12
+ selected?: boolean | undefined;
13
+ highlight?: string | undefined;
14
+ hoverTooltipProps?: (import("rc-trigger").TriggerProps & {
15
+ ref?: import("react").LegacyRef<import("@synerise/ds-list-item/dist/ListItem.types").TriggerHandle> | undefined;
16
+ }) | undefined;
17
+ prefixel?: ReactNode | import("@synerise/ds-list-item/dist/ListItem.types").AddonRenderer;
18
+ renderHoverTooltip?: (() => JSX.Element) | undefined;
19
+ timeToHideTooltip?: number | undefined;
20
+ text: string;
21
+ folders?: BaseSectionTypeWithFolders<BaseSectionType>[] | undefined;
22
+ }[] | undefined;
23
+ childFolders: ({
9
24
  type?: import("@synerise/ds-list-item").ItemType | undefined;
10
25
  id?: string | undefined;
11
26
  selected?: boolean | undefined;
@@ -24,7 +39,8 @@ export declare const useFlattenFolders: <SectionType extends BaseSectionType | u
24
39
  } & {
25
40
  titles?: ReactNode[] | undefined;
26
41
  })[] | undefined;
27
- childFolders: ({
42
+ parentFolder: BaseSectionTypeWithFolders<BaseSectionType> | undefined;
43
+ currentFolders: ({
28
44
  type?: import("@synerise/ds-list-item").ItemType | undefined;
29
45
  id?: string | undefined;
30
46
  selected?: boolean | undefined;
@@ -43,7 +59,7 @@ export declare const useFlattenFolders: <SectionType extends BaseSectionType | u
43
59
  } & {
44
60
  titles?: ReactNode[] | undefined;
45
61
  })[] | undefined;
46
- parentFolder: BaseSectionTypeWithFolders<BaseSectionType> | undefined;
62
+ currentSectionHasFolders: boolean;
47
63
  currentPath: ReactNode[] | undefined;
48
64
  };
49
65
  export {};
@@ -28,11 +28,6 @@ export var useFlattenFolders = function useFlattenFolders(_ref) {
28
28
  var _allItemFolders$find;
29
29
  var currentSection = _ref.currentSection,
30
30
  sections = _ref.sections;
31
- var allItemFolders = useMemo(function () {
32
- return sections == null ? void 0 : sections.flatMap(function (section) {
33
- return _getFolders(section);
34
- });
35
- }, [sections]);
36
31
  var folderParentMap = useMemo(function () {
37
32
  return sections == null ? void 0 : sections.flatMap(function (section) {
38
33
  return section.folders ? section.folders.flatMap(function (f) {
@@ -40,10 +35,22 @@ export var useFlattenFolders = function useFlattenFolders(_ref) {
40
35
  }) : [];
41
36
  });
42
37
  }, [sections]);
38
+ var titlePathIndex = folderParentMap != null && folderParentMap.length ? 1 : 0;
39
+ var allItemFolders = useMemo(function () {
40
+ var mappedFolders = sections == null ? void 0 : sections.flatMap(function (section) {
41
+ return _getFolders(section);
42
+ });
43
+ return mappedFolders == null ? void 0 : mappedFolders.map(function (folder) {
44
+ var _folder$titles;
45
+ return _extends({}, folder, {
46
+ titles: (_folder$titles = folder.titles) == null ? void 0 : _folder$titles.slice(titlePathIndex)
47
+ });
48
+ });
49
+ }, [sections, titlePathIndex]);
43
50
  var childFolders = useMemo(function () {
44
51
  var _currentSection$folde;
45
52
  return currentSection == null || (_currentSection$folde = currentSection.folders) == null ? void 0 : _currentSection$folde.flatMap(function (folder) {
46
- return _getFolders(folder, [currentSection == null ? void 0 : currentSection.text]);
53
+ return _getFolders(folder);
47
54
  });
48
55
  }, [currentSection]);
49
56
  var parentFolder = useMemo(function () {
@@ -55,10 +62,15 @@ export var useFlattenFolders = function useFlattenFolders(_ref) {
55
62
  var currentTitlePath = allItemFolders == null || (_allItemFolders$find = allItemFolders.find(function (folder) {
56
63
  return folder.id === (currentSection == null ? void 0 : currentSection.id);
57
64
  })) == null ? void 0 : _allItemFolders$find.titles;
65
+ var currentFolders = useMemo(function () {
66
+ return currentSection ? childFolders : allItemFolders;
67
+ }, [allItemFolders, childFolders, currentSection]);
58
68
  return {
59
69
  allFolders: allItemFolders,
60
70
  childFolders: childFolders,
61
71
  parentFolder: parentFolder,
72
+ currentFolders: currentFolders,
73
+ currentSectionHasFolders: !!(childFolders != null && childFolders.length),
62
74
  currentPath: currentTitlePath
63
75
  };
64
76
  };
@@ -4,7 +4,7 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
4
4
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
5
  import { itemSizes } from '@synerise/ds-list-item';
6
6
  import { FIRST_PAGE, ITEMS_PER_PAGE, ITEMS_PER_SECTION, ITEMS_PER_SECTION_IN_SEARCH, GET_ITEM_KEY, ITEM_SIZE, SECTION_HEADER_HEIGHT } from '../constants';
7
- import { isItems, isWithOutSections } from '../utils';
7
+ import { isItems, isItemsConfig, isWithOutSections } from '../utils';
8
8
  import { matchesSearchQuery, getSectionActionItems, getActionItems, getRecentItems, getFolderItems, getItems } from './useItemsInSections.utils';
9
9
  import { useFlattenFolders } from './useFlattenFolders';
10
10
  var getSectionHeight = function getSectionHeight(itemsCount, withTitle) {
@@ -40,13 +40,13 @@ export var useItemsInSections = function useItemsInSections(_ref) {
40
40
  currentSection: currentSection,
41
41
  sections: sections
42
42
  }),
43
- childFolders = _useFlattenFolders.childFolders,
43
+ currentSectionHasFolders = _useFlattenFolders.currentSectionHasFolders,
44
+ currentFolders = _useFlattenFolders.currentFolders,
44
45
  parentFolder = _useFlattenFolders.parentFolder,
45
- allFolders = _useFlattenFolders.allFolders,
46
46
  currentPath = _useFlattenFolders.currentPath;
47
47
  var loadedPage = useRef(FIRST_PAGE);
48
48
  var sectionTotals = useRef({});
49
- var isFixedItemsList = isItems(items);
49
+ var isFixedItemsList = isItems(items) || isItemsConfig(items);
50
50
  var _useState3 = useState(),
51
51
  contentHeight = _useState3[0],
52
52
  setContentHeight = _useState3[1];
@@ -70,12 +70,13 @@ export var useItemsInSections = function useItemsInSections(_ref) {
70
70
  setIsLoadedAll = _useState9[1];
71
71
  var _useState10 = useState(function () {
72
72
  if (isFixedItemsList) {
73
+ var fixedItems = isItemsConfig(items) ? items.items : items;
73
74
  if (searchQuery) {
74
- return items.filter(function (item) {
75
+ return fixedItems.filter(function (item) {
75
76
  return item.text && matchesSearchQuery(item.text, searchQuery);
76
77
  });
77
78
  }
78
- return items;
79
+ return fixedItems;
79
80
  }
80
81
  return [];
81
82
  }),
@@ -92,45 +93,40 @@ export var useItemsInSections = function useItemsInSections(_ref) {
92
93
  }));
93
94
  }, [hasSections, sections]);
94
95
  var itemsLimitPerSection = useMemo(function () {
95
- if (isFixedItemsList) return searchQuery ? ITEMS_PER_SECTION : ITEMS_PER_SECTION_IN_SEARCH;
96
- return items.limitPerSection || (searchQuery ? ITEMS_PER_SECTION : ITEMS_PER_SECTION_IN_SEARCH);
96
+ var _items$limitPerSectio2;
97
+ var fallbackLimit = searchQuery ? ITEMS_PER_SECTION_IN_SEARCH : ITEMS_PER_SECTION;
98
+ if (isFixedItemsList) {
99
+ var _items$limitPerSectio;
100
+ return isItemsConfig(items) ? (_items$limitPerSectio = items.limitPerSection) != null ? _items$limitPerSectio : fallbackLimit : fallbackLimit;
101
+ }
102
+ return (_items$limitPerSectio2 = items.limitPerSection) != null ? _items$limitPerSectio2 : fallbackLimit;
97
103
  }, [isFixedItemsList, searchQuery, items]);
98
- var currentSectionHasFolders = !!(childFolders != null && childFolders.length);
99
104
  var _useMemo = useMemo(function () {
100
105
  if (hasSectionsAndFolders) {
101
106
  if (hasCurrentSection) {
102
107
  if (!currentSectionHasFolders) {
103
108
  return {
104
- listRenderingMode: RENDER_MODES.LIST_ITEMS,
105
- titlePathIndex: 1
109
+ listRenderingMode: RENDER_MODES.LIST_ITEMS
106
110
  };
107
111
  }
108
112
  return {
109
- listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS,
110
- titlePathIndex: 1
113
+ listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS
111
114
  };
112
115
  }
113
116
  return {
114
- listRenderingMode: hasSearchQuery ? RENDER_MODES.LIST_ITEMS_IN_SECTIONS : RENDER_MODES.LIST_FOLDERS_IN_SECTIONS,
115
- titlePathIndex: 1
117
+ listRenderingMode: hasSearchQuery ? RENDER_MODES.LIST_ITEMS_IN_SECTIONS : RENDER_MODES.LIST_FOLDERS_IN_SECTIONS
116
118
  };
117
119
  }
118
- if (hasSections && (!hasCurrentSection || hasSearchQuery)) {
120
+ if (hasSections && !hasCurrentSection) {
119
121
  return {
120
- listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS,
121
- titlePathIndex: 0
122
+ listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS
122
123
  };
123
124
  }
124
125
  return {
125
- listRenderingMode: RENDER_MODES.LIST_ITEMS,
126
- titlePathIndex: 0
126
+ listRenderingMode: RENDER_MODES.LIST_ITEMS
127
127
  };
128
128
  }, [hasCurrentSection, hasSections, hasSearchQuery, hasSectionsAndFolders, currentSectionHasFolders]),
129
- listRenderingMode = _useMemo.listRenderingMode,
130
- titlePathIndex = _useMemo.titlePathIndex;
131
- var flattenedFolders = useMemo(function () {
132
- return currentSection ? childFolders : allFolders;
133
- }, [allFolders, childFolders, currentSection]);
129
+ listRenderingMode = _useMemo.listRenderingMode;
134
130
  var globalActionsLength = (actions == null ? void 0 : actions.filter(function (action) {
135
131
  return !action.sectionId;
136
132
  }).length) || 0;
@@ -260,11 +256,11 @@ export var useItemsInSections = function useItemsInSections(_ref) {
260
256
  return _context.abrupt("return");
261
257
  case 22:
262
258
  fetchedItems = [];
263
- requests = listRenderingMode === RENDER_MODES.LIST_FOLDERS_IN_SECTIONS ? [Promise.resolve()] : flattenedFolders == null ? void 0 : flattenedFolders.map(function (folder) {
259
+ requests = listRenderingMode === RENDER_MODES.LIST_FOLDERS_IN_SECTIONS ? [Promise.resolve()] : currentFolders == null ? void 0 : currentFolders.map(function (folder) {
264
260
  return items.loadItems({
265
261
  page: FIRST_PAGE,
266
262
  searchQuery: searchQuery,
267
- limit: (items.limitPerSection || ITEMS_PER_SECTION) + +!!searchQuery,
263
+ limit: (items.limitPerSection || ITEMS_PER_SECTION) + 1,
268
264
  sectionId: folder.id
269
265
  }).then(function (_ref3) {
270
266
  var sectionItems = _ref3.items,
@@ -313,22 +309,26 @@ export var useItemsInSections = function useItemsInSections(_ref) {
313
309
  return _context.stop();
314
310
  }
315
311
  }, _callee, null, [[5, 16], [24, 41]]);
316
- })), [currentSection, isFixedItemsList, flattenedFolders, listRenderingMode, isLoading, items, listActions, searchQuery]);
312
+ })), [currentSection, isFixedItemsList, currentFolders, listRenderingMode, isLoading, items, listActions, searchQuery]);
317
313
  useEffect(function () {
318
314
  if (listActions) {
319
315
  return;
320
316
  }
321
317
  if (isFixedItemsList) {
318
+ var allItems = isItemsConfig(items) ? items.items : items;
319
+ var itemsInSection = currentSection && !currentSectionHasFolders ? allItems.filter(function (item) {
320
+ return item.sectionId === currentSection.id;
321
+ }) : allItems;
322
322
  if (searchQuery) {
323
- var matchingItems = items.filter(function (item) {
323
+ var matchingItems = itemsInSection.filter(function (item) {
324
324
  return item.text && matchesSearchQuery(item.text, searchQuery);
325
325
  });
326
326
  setCurrentItems(matchingItems);
327
327
  return;
328
328
  }
329
- setCurrentItems(items);
329
+ setCurrentItems(itemsInSection);
330
330
  }
331
- }, [isFixedItemsList, isLoading, isLoadingError, currentItemsLength, items, listActions, searchQuery]);
331
+ }, [isFixedItemsList, isLoading, currentSection, isLoadingError, currentSectionHasFolders, currentItemsLength, items, listActions, searchQuery]);
332
332
  useEffect(function () {
333
333
  loadedPage.current = FIRST_PAGE;
334
334
  setIsLoadedAll(false);
@@ -418,14 +418,13 @@ export var useItemsInSections = function useItemsInSections(_ref) {
418
418
  sections: sections,
419
419
  handleSectionChange: handleSectionChange
420
420
  }) : [];
421
- var listItems = flattenedFolders ? flattenedFolders.flatMap(function (folder) {
422
- var _folder$titles;
421
+ var listItems = currentFolders ? currentFolders.flatMap(function (folder) {
423
422
  var itemsInFolder = currentItems.filter(function (item) {
424
423
  return item.sectionId === folder.id;
425
424
  });
426
425
  return getItems({
427
426
  items: itemsInFolder,
428
- titlePath: (_folder$titles = folder.titles) == null ? void 0 : _folder$titles.slice(titlePathIndex),
427
+ titlePath: folder.titles,
429
428
  texts: texts,
430
429
  searchQuery: searchQuery,
431
430
  maxItems: itemsLimitPerSection,
@@ -454,9 +453,9 @@ export var useItemsInSections = function useItemsInSections(_ref) {
454
453
  default:
455
454
  return [].concat(composedList, listItems);
456
455
  }
457
- }, [listActions, currentSection, actions, texts, searchQuery, recents, currentItems, showItemsSectionLabel, sections, flattenedFolders, itemsLimitPerSection, listRenderingMode, titlePathIndex, isSelected, handleItemSelect, handleSectionChange]);
456
+ }, [listActions, currentSection, actions, texts, searchQuery, recents, currentItems, showItemsSectionLabel, sections, currentFolders, itemsLimitPerSection, listRenderingMode, isSelected, handleItemSelect, handleSectionChange]);
458
457
  return {
459
- currentSection: currentSection,
458
+ currentSection: !listActions ? currentSection : undefined,
460
459
  currentPath: currentPath,
461
460
  goBack: goBack,
462
461
  resetCurrentSection: resetCurrentSection,
@@ -98,9 +98,10 @@ export var getItems = function getItems(_ref4) {
98
98
  return getListItem(item, isSelected, searchQuery, handleItemSelect, getInformationCardTooltip(item));
99
99
  })) : [];
100
100
  if (maxItems) {
101
- var hasMore = results.splice(maxItems, Infinity, getShowMoreItem(texts.showMoreResultsLabel, showMoreOnClick));
102
- if (!hasMore.length) {
103
- results.pop();
101
+ var maxItemsWithTitle = maxItems + (sectionTitle.length ? 1 : 0);
102
+ var hasMore = results.splice(maxItemsWithTitle, Infinity);
103
+ if (hasMore.length) {
104
+ results.push(getShowMoreItem(texts.showMoreResultsLabel, showMoreOnClick));
104
105
  }
105
106
  }
106
107
  return results;
@@ -41,7 +41,7 @@ export var useListHeight = function useListHeight(_ref) {
41
41
  outerWrapperHeight = '100%';
42
42
  listWrapperHeight = measuredHeight - offsetSpace;
43
43
  } else if (heightConfig === 'fitContent' && calculatedContentHeight) {
44
- listWrapperHeight = Math.min(calculatedContentHeight, outerHeight) + 2 * LIST_INNER_PADDING;
44
+ listWrapperHeight = calculatedContentHeight + 2 * LIST_INNER_PADDING;
45
45
  outerWrapperHeight = listWrapperHeight + offsetSpace + "px";
46
46
  } else {
47
47
  listWrapperHeight = outerHeight - offsetSpace;
@@ -1,6 +1,7 @@
1
1
  import { ListItemProps } from '@synerise/ds-list-item';
2
2
  import { TitleListItemProps } from '../ItemPickerList.types';
3
- import { BaseItemType, BaseSectionType, BaseSectionTypeWithFolders, ItemLoaderConfig } from '../../ItemPickerNew/ItemPickerNew.types';
3
+ import { BaseItemType, BaseSectionType, BaseSectionTypeWithFolders, ItemLoaderConfig, ItemsConfig } from '../../ItemPickerNew/ItemPickerNew.types';
4
4
  export declare const isTitle: (item: TitleListItemProps | ListItemProps) => item is TitleListItemProps;
5
- export declare const isItems: <ItemType extends BaseItemType>(items: ItemLoaderConfig<ItemType> | ItemType[]) => items is ItemType[];
5
+ export declare const isItems: <ItemType extends BaseItemType>(items: ItemsConfig<ItemType> | ItemLoaderConfig<ItemType> | ItemType[]) => items is ItemType[];
6
+ export declare const isItemsConfig: <ItemType extends BaseItemType>(items: ItemsConfig<ItemType> | ItemLoaderConfig<ItemType> | ItemType[]) => items is ItemsConfig<ItemType>;
6
7
  export declare const isWithOutSections: <SectionType extends BaseSectionTypeWithFolders<BaseSectionType> | undefined>(sections?: SectionType[] | undefined) => sections is undefined;
@@ -7,6 +7,12 @@ export var isItems = function isItems(items) {
7
7
  }
8
8
  return false;
9
9
  };
10
+ export var isItemsConfig = function isItemsConfig(items) {
11
+ if ('items' in items && Array.isArray(items.items)) {
12
+ return true;
13
+ }
14
+ return false;
15
+ };
10
16
  export var isWithOutSections = function isWithOutSections(sections) {
11
17
  return sections === undefined;
12
18
  };
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import type { BaseItemType, BaseSectionType, ItemPickerProps } from './ItemPickerNew.types';
3
- export declare const ItemPickerNew: <ItemType extends BaseItemType, SectionType extends BaseSectionType>({ onFocus, onBlur, selectedItem, onChange, dropdownProps, texts, triggerProps, renderTrigger, placeholder, placeholderIcon, label, description, error, errorMessage, disabled, tooltip, ...rest }: ItemPickerProps<ItemType, SectionType>) => React.JSX.Element;
3
+ export declare const ItemPickerNew: <ItemType extends BaseItemType, SectionType extends BaseSectionType>({ onFocus, onBlur, selectedItem, onChange, dropdownProps, texts, triggerProps, renderTrigger, placeholder, placeholderIcon, label, description, error, errorMessage, errorText, disabled, tooltip, tooltipConfig, ...rest }: ItemPickerProps<ItemType, SectionType>) => React.JSX.Element;
@@ -1,11 +1,10 @@
1
- var _excluded = ["onFocus", "onBlur", "selectedItem", "onChange", "dropdownProps", "texts", "triggerProps", "renderTrigger", "placeholder", "placeholderIcon", "label", "description", "error", "errorMessage", "disabled", "tooltip"];
1
+ var _excluded = ["onFocus", "onBlur", "selectedItem", "onChange", "dropdownProps", "texts", "triggerProps", "renderTrigger", "placeholder", "placeholderIcon", "label", "description", "error", "errorMessage", "errorText", "disabled", "tooltip", "tooltipConfig"];
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
4
  import React, { useEffect, useMemo, useRef, useState } from 'react';
5
5
  import Dropdown from '@synerise/ds-dropdown';
6
- import { Label } from '@synerise/ds-input';
7
- import { Description } from '@synerise/ds-typography';
8
6
  import { useOnClickOutside } from '@synerise/ds-utils';
7
+ import FormField from '@synerise/ds-form-field';
9
8
  import Trigger from '../ItemPickerTrigger/Trigger';
10
9
  import { useDefaultTexts } from '../../hooks/useDefaultTexts';
11
10
  import * as S from '../../ItemPicker.styles';
@@ -25,8 +24,10 @@ export var ItemPickerNew = function ItemPickerNew(_ref) {
25
24
  description = _ref.description,
26
25
  error = _ref.error,
27
26
  errorMessage = _ref.errorMessage,
27
+ errorText = _ref.errorText,
28
28
  disabled = _ref.disabled,
29
29
  tooltip = _ref.tooltip,
30
+ tooltipConfig = _ref.tooltipConfig,
30
31
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
31
32
  var overlayRef = useRef(null);
32
33
  useOnClickOutside(overlayRef, function () {
@@ -83,10 +84,13 @@ export var ItemPickerNew = function ItemPickerNew(_ref) {
83
84
  return /*#__PURE__*/React.createElement(S.ItemPickerWrapper, {
84
85
  className: "ds-items-picker",
85
86
  disabled: disabled
86
- }, label && /*#__PURE__*/React.createElement(Label, {
87
+ }, /*#__PURE__*/React.createElement(FormField, {
87
88
  label: label,
88
- tooltip: tooltip
89
- }), /*#__PURE__*/React.createElement(Dropdown, _extends({
89
+ tooltip: tooltip,
90
+ tooltipConfig: tooltipConfig,
91
+ errorText: errorText || errorMessage,
92
+ description: description
93
+ }, /*#__PURE__*/React.createElement(Dropdown, _extends({
90
94
  overlayStyle: {
91
95
  width: '400px'
92
96
  }
@@ -101,5 +105,5 @@ export var ItemPickerNew = function ItemPickerNew(_ref) {
101
105
  onItemSelect: handleItemSelect,
102
106
  containerRef: overlayRef
103
107
  }))
104
- }), trigger), error && errorMessage && /*#__PURE__*/React.createElement(S.Error, null, errorMessage), description && /*#__PURE__*/React.createElement(Description, null, description));
108
+ }), trigger)));
105
109
  };
@@ -3,6 +3,7 @@ import type { ListItemProps } from '@synerise/ds-list-item';
3
3
  import type { InformationCardProps } from '@synerise/ds-information-card';
4
4
  import type { WithHTMLAttributes } from '@synerise/ds-utils';
5
5
  import type { DropdownProps } from '@synerise/ds-dropdown';
6
+ import type { FormFieldCommonProps } from '@synerise/ds-form-field';
6
7
  import type { ItemPickerListProps, ItemPickerListTexts } from '../ItemPickerList/ItemPickerList.types';
7
8
  import type { ItemPickerTriggerProps, ItemPickerTriggerTexts } from '../ItemPickerTrigger/Trigger.types';
8
9
  type HeightConfig = {
@@ -39,6 +40,10 @@ export type ItemLoaderConfig<ItemType extends BaseItemType> = {
39
40
  limitPerSection?: number;
40
41
  loadItems: (props: LoaderProps) => Promise<ItemLoaderResponse<ItemType>>;
41
42
  };
43
+ export type ItemsConfig<ItemType extends BaseItemType> = {
44
+ limitPerSection?: number;
45
+ items: ItemType[];
46
+ };
42
47
  type RedirectActionType = {
43
48
  actionType: 'redirect';
44
49
  };
@@ -63,15 +68,15 @@ export type ItemPickerProps<ItemType extends BaseItemType, SectionType extends B
63
68
  withChangeButton?: ItemPickerTriggerProps['withChangeButton'];
64
69
  withClearConfirmation?: ItemPickerTriggerProps['withClearConfirmation'];
65
70
  };
66
- label?: ReactNode;
67
- description?: ReactNode;
68
- errorMessage?: ReactNode;
71
+ /**
72
+ * @deprecated - use errorText prop instead
73
+ */
74
+ errorMessage?: FormFieldCommonProps['errorText'];
69
75
  error?: boolean;
70
76
  disabled?: boolean;
71
- tooltip?: ReactNode;
72
77
  onChange?: (item: ItemType) => void;
73
78
  onFocus?: () => void;
74
79
  onBlur?: () => void;
75
80
  dropdownProps?: Partial<DropdownProps>;
76
- } & Pick<ItemPickerListProps<ItemType, SectionType>, 'items' | 'actions' | 'recents' | 'sections' | 'isLoading' | 'onRefresh' | 'onSectionChange' | 'containerHeight' | 'showItemsSectionLabel' | 'noResultsIcon' | 'emptyListIcon' | 'selectedItem' | 'getItemHeight' | 'scrollbarProps' | 'searchBarProps' | 'includeFooter' | 'includeSearchBar'>> & Partial<Pick<ItemPickerTriggerProps, 'placeholder' | 'placeholderIcon' | 'onClear'>>;
81
+ } & Pick<ItemPickerListProps<ItemType, SectionType>, 'items' | 'actions' | 'recents' | 'sections' | 'isLoading' | 'onRefresh' | 'onSectionChange' | 'containerHeight' | 'showItemsSectionLabel' | 'noResultsIcon' | 'emptyListIcon' | 'selectedItem' | 'getItemHeight' | 'scrollbarProps' | 'searchBarProps' | 'includeFooter' | 'includeSearchBar'>> & FormFieldCommonProps & Partial<Pick<ItemPickerTriggerProps, 'placeholder' | 'placeholderIcon' | 'onClear'>>;
77
82
  export {};
@@ -14,7 +14,7 @@ export var useDefaultTexts = function useDefaultTexts(texts) {
14
14
  }, "/")
15
15
  },
16
16
  id: "DS.ITEM-PICKER-DROPDOWN.SEARCH-PLACEHOLDER",
17
- defaultMessage: "Search for object or type {shortCutKey} to show actions "
17
+ defaultMessage: "Search for object or type {shortCutKey} to show actions"
18
18
  }),
19
19
  yes: intl.formatMessage({
20
20
  id: 'DS.ITEM-PICKER.YES-TEXT',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-item-picker",
3
- "version": "1.0.7",
3
+ "version": "1.1.1",
4
4
  "description": "ItemPicker UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -34,26 +34,25 @@
34
34
  ],
35
35
  "types": "dist/index.d.ts",
36
36
  "dependencies": {
37
- "@synerise/ds-alert": "^1.0.4",
38
- "@synerise/ds-avatar": "^1.0.4",
39
- "@synerise/ds-button": "^1.1.3",
40
- "@synerise/ds-dropdown": "^1.0.4",
41
- "@synerise/ds-empty-states": "^1.0.4",
37
+ "@synerise/ds-alert": "^1.0.6",
38
+ "@synerise/ds-avatar": "^1.0.6",
39
+ "@synerise/ds-button": "^1.1.5",
40
+ "@synerise/ds-dropdown": "^1.0.6",
41
+ "@synerise/ds-empty-states": "^1.0.6",
42
42
  "@synerise/ds-flag": "^1.0.0",
43
- "@synerise/ds-icon": "^1.3.0",
44
- "@synerise/ds-information-card": "^1.0.6",
45
- "@synerise/ds-input": "^1.0.4",
46
- "@synerise/ds-list-item": "^1.0.4",
43
+ "@synerise/ds-form-field": "^1.1.1",
44
+ "@synerise/ds-icon": "^1.4.1",
45
+ "@synerise/ds-information-card": "^1.0.8",
46
+ "@synerise/ds-list-item": "^1.0.6",
47
47
  "@synerise/ds-loader": "^1.0.1",
48
- "@synerise/ds-popconfirm": "^1.0.4",
49
- "@synerise/ds-result": "^1.0.4",
50
- "@synerise/ds-scrollbar": "^1.0.4",
51
- "@synerise/ds-search": "^1.1.1",
52
- "@synerise/ds-search-bar": "^1.0.4",
53
- "@synerise/ds-short-cuts": "^1.0.4",
54
- "@synerise/ds-skeleton": "^1.0.4",
55
- "@synerise/ds-tooltip": "^1.1.3",
56
- "@synerise/ds-typography": "^1.0.4",
48
+ "@synerise/ds-popconfirm": "^1.0.6",
49
+ "@synerise/ds-result": "^1.0.6",
50
+ "@synerise/ds-scrollbar": "^1.0.6",
51
+ "@synerise/ds-search": "^1.1.3",
52
+ "@synerise/ds-search-bar": "^1.1.1",
53
+ "@synerise/ds-short-cuts": "^1.0.6",
54
+ "@synerise/ds-skeleton": "^1.0.6",
55
+ "@synerise/ds-tooltip": "^1.1.5",
57
56
  "@synerise/ds-utils": "^1.0.1",
58
57
  "lodash": "^4.17.21",
59
58
  "react-window": "^1.8.5",
@@ -65,5 +64,5 @@
65
64
  "react-intl": ">=3.12.0 <= 6.8",
66
65
  "styled-components": "^5.3.3"
67
66
  },
68
- "gitHead": "7586f8946fc312eae130021f8ae4ad4b9455e8d4"
67
+ "gitHead": "fc601270d3c84a5a52b62473a01f1b3c1c7014a7"
69
68
  }