@chayns-components/core 5.5.37 → 5.5.40

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.
@@ -0,0 +1,32 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { searchList } from './searchBox';
3
+ const items = [{
4
+ id: '2',
5
+ text: 'Zweite'
6
+ }, {
7
+ id: '1',
8
+ text: 'Erste'
9
+ }];
10
+ describe('searchList', () => {
11
+ it('uses the custom sort function instead of the default sort', () => {
12
+ const result = searchList({
13
+ customSortFunction: (a, b) => b.id.localeCompare(a.id),
14
+ items,
15
+ searchString: ''
16
+ });
17
+ expect(result.map(({
18
+ id
19
+ }) => id)).toEqual(['2', '1']);
20
+ });
21
+ it('still filters before applying the custom sort function', () => {
22
+ const result = searchList({
23
+ customSortFunction: (a, b) => a.id.localeCompare(b.id),
24
+ items,
25
+ searchString: 'e'
26
+ });
27
+ expect(result.map(({
28
+ id
29
+ }) => id)).toEqual(['1', '2']);
30
+ });
31
+ });
32
+ //# sourceMappingURL=searchBox.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchBox.test.js","names":["describe","expect","it","searchList","items","id","text","result","customSortFunction","a","b","localeCompare","searchString","map","toEqual"],"sources":["../../../src/utils/searchBox.test.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest';\nimport type { ISearchBoxItem } from '../types/searchBox';\nimport { searchList } from './searchBox';\n\nconst items: ISearchBoxItem[] = [\n { id: '2', text: 'Zweite' },\n { id: '1', text: 'Erste' },\n];\n\ndescribe('searchList', () => {\n it('uses the custom sort function instead of the default sort', () => {\n const result = searchList({\n customSortFunction: (a, b) => b.id.localeCompare(a.id),\n items,\n searchString: '',\n });\n\n expect(result.map(({ id }) => id)).toEqual(['2', '1']);\n });\n\n it('still filters before applying the custom sort function', () => {\n const result = searchList({\n customSortFunction: (a, b) => a.id.localeCompare(b.id),\n items,\n searchString: 'e',\n });\n\n expect(result.map(({ id }) => id)).toEqual(['1', '2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ventHandler } from 'react';
2
2
  import type { ISearchBoxItem, ISearchBoxItems } from '../../types/searchBox';
3
+ import { type SearchBoxSortFunction } from '../../utils/searchBox';
3
4
  import { type InputProps } from '../input/Input';
4
5
  import { TagInputProps } from '../tag-input/TagInput';
5
6
  import type { DropdownDirection } from '../../types/dropdown';
@@ -22,6 +23,10 @@ export type SearchBoxProps = {
22
23
  * An optional callback function to filter the elements to be displayed
23
24
  */
24
25
  customFilter?: (item: ISearchBoxItem) => boolean;
26
+ /**
27
+ * An optional callback function to sort the filtered elements to be displayed
28
+ */
29
+ customSortFunction?: SearchBoxSortFunction;
25
30
  /**
26
31
  * If true, the custom filter replaces the built-in text search instead of narrowing its results.
27
32
  */
@@ -88,6 +88,7 @@ export type { IListItemRightElements } from './types/list';
88
88
  export type { PopupRef } from './types/popup';
89
89
  export type { RadioButtonItem } from './types/radioButton';
90
90
  export type { ISearchBoxItem as SearchBoxItem, ISearchBoxItems as SearchBoxItems, } from './types/searchBox';
91
+ export type { SearchBoxSortFunction } from './utils/searchBox';
91
92
  export type { SelectButtonItem } from './types/selectButton';
92
93
  export type { SliderButtonItem } from './types/slider-button';
93
94
  export { type MultiActionButtonAction, type MultiActionButtonActionEvent, type MultiActionButtonActionStatus, MultiActionButtonHeight, type MultiActionButtonProps, type MultiActionButtonSecondaryContextMenu, MultiActionButtonStatusType, } from './components/multi-action-button/MultiActionButton.types';
@@ -1,9 +1,11 @@
1
1
  import type { ISearchBoxItem } from '../types/searchBox';
2
2
  export declare const getCurrentGroupName: (element: HTMLElement) => string;
3
+ export type SearchBoxSortFunction = (a: ISearchBoxItem, b: ISearchBoxItem) => number;
3
4
  interface SearchListOptions {
5
+ customSortFunction?: SearchBoxSortFunction;
4
6
  items: ISearchBoxItem[];
5
7
  searchString: string;
6
8
  }
7
- export declare const sortSearchBoxItems: ({ searchString, items }: SearchListOptions) => ISearchBoxItem[];
8
- export declare const searchList: ({ searchString, items }: SearchListOptions) => ISearchBoxItem[];
9
+ export declare const sortSearchBoxItems: ({ customSortFunction, searchString, items, }: SearchListOptions) => ISearchBoxItem[];
10
+ export declare const searchList: ({ customSortFunction, searchString, items }: SearchListOptions) => ISearchBoxItem[];
9
11
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/core",
3
- "version": "5.5.37",
3
+ "version": "5.5.40",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -93,5 +93,5 @@
93
93
  "publishConfig": {
94
94
  "access": "public"
95
95
  },
96
- "gitHead": "d54ff7f9ff20ebb76f33a5539cbb610b107a0cc7"
96
+ "gitHead": "6dbae57c63a1acb4aad518450bc6bc3d911a1d3e"
97
97
  }