ag-common 0.0.368 → 0.0.369

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.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { ISearchDialog, TSearchModalRes } from './types';
3
- export declare const SearchBase: <T>({ onSelectItem, onSearchTextChange, placeholderText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, }: ISearchDialog<T> & {
3
+ export declare const SearchBase: <T>({ onSelectItem, onSearchTextChange, placeholderText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, maxDisplayItems, }: ISearchDialog<T> & {
4
4
  onSearchTextChange?: ((v: string) => void) | undefined;
5
5
  onSelectItem?: ((v: TSearchModalRes<T>) => void) | undefined;
6
6
  }) => JSX.Element;
@@ -34,6 +34,7 @@ const styles_1 = require("../../styles");
34
34
  const styled_components_1 = __importDefault(require("styled-components"));
35
35
  const react_1 = __importStar(require("react"));
36
36
  const Magnify_1 = require("../../icons/Magnify");
37
+ const common_1 = require("../../../common");
37
38
  const Base = styled_components_1.default.div `
38
39
  display: flex;
39
40
  flex-flow: column;
@@ -93,7 +94,7 @@ const CrossIconStyled = (0, styled_components_1.default)(CrossIcon_1.CrossIcon)
93
94
  right: 2rem;
94
95
  }
95
96
  `;
96
- const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, }) => {
97
+ const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, maxDisplayItems = 20, }) => {
97
98
  var _a, _b;
98
99
  const [searchText, setSearchText] = (0, react_1.useState)('');
99
100
  const resWrap = (foundItem) => {
@@ -104,7 +105,8 @@ const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, renderI
104
105
  onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem({ foundItem, searchText });
105
106
  }
106
107
  };
107
- const filteredItems = displayItems.filter((i) => willDisplayItem(searchText, i));
108
+ const filteredItemsRaw = displayItems.filter((i) => willDisplayItem(searchText, i));
109
+ const { part: filteredItems } = (0, common_1.take)(filteredItemsRaw, maxDisplayItems);
108
110
  const showText = (_b = (_a = texts === null || texts === void 0 ? void 0 : texts.totalItems) === null || _a === void 0 ? void 0 : _a.call(texts, filteredItems.length, displayItems.length)) !== null && _b !== void 0 ? _b : `Showing ${filteredItems.length} out of ${displayItems.length} total
109
111
  items`;
110
112
  const textEditRef = (0, react_1.createRef)();
@@ -17,6 +17,8 @@ export interface ISearchDialog<T> {
17
17
  * run to filter items by search text
18
18
  */
19
19
  willDisplayItem: (searchText: string, item: T) => boolean;
20
+ /** how many search items to return at most. default 20 */
21
+ maxDisplayItems?: number;
20
22
  /**
21
23
  * get unique render key
22
24
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.368",
3
+ "version": "0.0.369",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -26,7 +26,8 @@
26
26
  "react": "18.2.0",
27
27
  "react-dom": "18.2.0",
28
28
  "react-hot-toast": "2.x",
29
- "typescript": "4.x"
29
+ "typescript": "4.x",
30
+ "eslint-import-resolver-typescript": "3.x"
30
31
  },
31
32
  "peerDependencies": {
32
33
  "styled-components": ">=5"
@@ -47,7 +48,7 @@
47
48
  "@types/react-dom": "18.0.9",
48
49
  "@types/styled-components": "5.1.26",
49
50
  "cross-env": "7.0.3",
50
- "eslint-config-e7npm": "0.0.5",
51
+ "eslint-config-e7npm": "0.0.6",
51
52
  "rimraf": "3.0.2",
52
53
  "styled-components": "5.3.6"
53
54
  },