@chayns-components/core 5.5.37 → 5.5.41

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.
@@ -38,9 +38,13 @@ export const getCurrentGroupName = element => {
38
38
  return currentGroupName;
39
39
  };
40
40
  export const sortSearchBoxItems = ({
41
+ customSortFunction,
41
42
  searchString,
42
43
  items
43
44
  }) => {
45
+ if (customSortFunction) {
46
+ return [...items].sort(customSortFunction);
47
+ }
44
48
  const lowercaseSearchString = searchString.toLowerCase();
45
49
  return [...items].sort((a, b) => {
46
50
  const aStartsWithSearchString = a.text.toLowerCase().startsWith(lowercaseSearchString);
@@ -55,6 +59,7 @@ export const sortSearchBoxItems = ({
55
59
  });
56
60
  };
57
61
  export const searchList = ({
62
+ customSortFunction,
58
63
  searchString,
59
64
  items
60
65
  }) => {
@@ -76,6 +81,7 @@ export const searchList = ({
76
81
  }
77
82
  });
78
83
  return sortSearchBoxItems({
84
+ customSortFunction,
79
85
  items: matchingItems,
80
86
  searchString
81
87
  });
@@ -1 +1 @@
1
- {"version":3,"file":"searchBox.js","names":["surroundWithBTag","text","startIndex","length","before","substring","highlighted","after","getCurrentGroupName","element","hasChildrenFound","currentGroupName","top","parentTop","getBoundingClientRect","children","Array","from","forEach","child","y","childrenY","height","childrenHeight","id","sum","currentGroup","startsWith","nummer","split","pop","sortSearchBoxItems","searchString","items","lowercaseSearchString","toLowerCase","sort","a","b","aStartsWithSearchString","bStartsWithSearchString","localeCompare","searchList","matchingItems","item","lowercaseText","includes","push","indexOf","highlightedText"],"sources":["../../../src/utils/searchBox.ts"],"sourcesContent":["import type { ISearchBoxItem } from '../types/searchBox';\n\nconst surroundWithBTag = (text: string, startIndex: number, length: number) => {\n const before = text.substring(0, startIndex);\n const highlighted = text.substring(startIndex, startIndex + length);\n const after = text.substring(startIndex + length);\n\n return `${before}<b>${highlighted}</b>${after}`;\n};\n\nexport const getCurrentGroupName = (element: HTMLElement) => {\n let hasChildrenFound = false;\n let currentGroupName = '';\n\n const { top: parentTop } = element.getBoundingClientRect();\n const { children } = element;\n\n Array.from(children).forEach((child) => {\n if (hasChildrenFound) {\n return;\n }\n\n const { y: childrenY, height: childrenHeight } = child.getBoundingClientRect();\n const { id } = child;\n\n const sum = childrenY + childrenHeight - parentTop;\n\n if (sum >= 0) {\n hasChildrenFound = true;\n let currentGroup = id;\n\n if (id.startsWith('search-box-item__')) {\n const nummer = id.split('__')[1];\n currentGroup = nummer?.split('_').pop() ?? '';\n }\n\n currentGroupName = currentGroup;\n }\n });\n\n return currentGroupName;\n};\n\ninterface SearchListOptions {\n items: ISearchBoxItem[];\n searchString: string;\n}\n\nexport const sortSearchBoxItems = ({ searchString, items }: SearchListOptions) => {\n const lowercaseSearchString = searchString.toLowerCase();\n\n return [...items].sort((a, b) => {\n const aStartsWithSearchString = a.text.toLowerCase().startsWith(lowercaseSearchString);\n const bStartsWithSearchString = b.text.toLowerCase().startsWith(lowercaseSearchString);\n\n if (aStartsWithSearchString && !bStartsWithSearchString) {\n return -1;\n }\n if (!aStartsWithSearchString && bStartsWithSearchString) {\n return 1;\n }\n return a.text.localeCompare(b.text);\n });\n};\n\nexport const searchList = ({ searchString, items }: SearchListOptions) => {\n const matchingItems: ISearchBoxItem[] = [];\n\n const lowercaseSearchString = searchString.toLowerCase();\n\n items.forEach((item) => {\n const lowercaseText = item.text.toLowerCase();\n\n if (lowercaseText.includes(lowercaseSearchString)) {\n if (searchString === '') {\n matchingItems.push(item);\n } else {\n const startIndex = lowercaseText.indexOf(lowercaseSearchString);\n const highlightedText = surroundWithBTag(\n item.text,\n startIndex,\n searchString.length,\n );\n matchingItems.push({ ...item, text: highlightedText });\n }\n }\n });\n\n return sortSearchBoxItems({ items: matchingItems, searchString });\n};\n"],"mappings":"AAEA,MAAMA,gBAAgB,GAAGA,CAACC,IAAY,EAAEC,UAAkB,EAAEC,MAAc,KAAK;EAC3E,MAAMC,MAAM,GAAGH,IAAI,CAACI,SAAS,CAAC,CAAC,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BAAqB,CAAC;QAC/D,MAAMe,eAAe,GAAGjD,gBAAgB,CACpC4C,IAAI,CAAC3C,IAAI,EACTC,UAAU,EACV8B,YAAY,CAAC7B,MACjB,CAAC;QACDwC,aAAa,CAACI,IAAI,CAAC;UAAE,GAAGH,IAAI;UAAE3C,IAAI,EAAEgD;QAAgB,CAAC,CAAC;MAC1D;IACJ;EACJ,CAAC,CAAC;EAEF,OAAOlB,kBAAkB,CAAC;IAAEE,KAAK,EAAEU,aAAa;IAAEX;EAAa,CAAC,CAAC;AACrE,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"searchBox.js","names":["surroundWithBTag","text","startIndex","length","before","substring","highlighted","after","getCurrentGroupName","element","hasChildrenFound","currentGroupName","top","parentTop","getBoundingClientRect","children","Array","from","forEach","child","y","childrenY","height","childrenHeight","id","sum","currentGroup","startsWith","nummer","split","pop","sortSearchBoxItems","customSortFunction","searchString","items","sort","lowercaseSearchString","toLowerCase","a","b","aStartsWithSearchString","bStartsWithSearchString","localeCompare","searchList","matchingItems","item","lowercaseText","includes","push","indexOf","highlightedText"],"sources":["../../../src/utils/searchBox.ts"],"sourcesContent":["import type { ISearchBoxItem } from '../types/searchBox';\n\nconst surroundWithBTag = (text: string, startIndex: number, length: number) => {\n const before = text.substring(0, startIndex);\n const highlighted = text.substring(startIndex, startIndex + length);\n const after = text.substring(startIndex + length);\n\n return `${before}<b>${highlighted}</b>${after}`;\n};\n\nexport const getCurrentGroupName = (element: HTMLElement) => {\n let hasChildrenFound = false;\n let currentGroupName = '';\n\n const { top: parentTop } = element.getBoundingClientRect();\n const { children } = element;\n\n Array.from(children).forEach((child) => {\n if (hasChildrenFound) {\n return;\n }\n\n const { y: childrenY, height: childrenHeight } = child.getBoundingClientRect();\n const { id } = child;\n\n const sum = childrenY + childrenHeight - parentTop;\n\n if (sum >= 0) {\n hasChildrenFound = true;\n let currentGroup = id;\n\n if (id.startsWith('search-box-item__')) {\n const nummer = id.split('__')[1];\n currentGroup = nummer?.split('_').pop() ?? '';\n }\n\n currentGroupName = currentGroup;\n }\n });\n\n return currentGroupName;\n};\n\nexport type SearchBoxSortFunction = (a: ISearchBoxItem, b: ISearchBoxItem) => number;\n\ninterface SearchListOptions {\n customSortFunction?: SearchBoxSortFunction;\n items: ISearchBoxItem[];\n searchString: string;\n}\n\nexport const sortSearchBoxItems = ({\n customSortFunction,\n searchString,\n items,\n}: SearchListOptions) => {\n if (customSortFunction) {\n return [...items].sort(customSortFunction);\n }\n\n const lowercaseSearchString = searchString.toLowerCase();\n\n return [...items].sort((a, b) => {\n const aStartsWithSearchString = a.text.toLowerCase().startsWith(lowercaseSearchString);\n const bStartsWithSearchString = b.text.toLowerCase().startsWith(lowercaseSearchString);\n\n if (aStartsWithSearchString && !bStartsWithSearchString) {\n return -1;\n }\n if (!aStartsWithSearchString && bStartsWithSearchString) {\n return 1;\n }\n return a.text.localeCompare(b.text);\n });\n};\n\nexport const searchList = ({ customSortFunction, searchString, items }: SearchListOptions) => {\n const matchingItems: ISearchBoxItem[] = [];\n\n const lowercaseSearchString = searchString.toLowerCase();\n\n items.forEach((item) => {\n const lowercaseText = item.text.toLowerCase();\n\n if (lowercaseText.includes(lowercaseSearchString)) {\n if (searchString === '') {\n matchingItems.push(item);\n } else {\n const startIndex = lowercaseText.indexOf(lowercaseSearchString);\n const highlightedText = surroundWithBTag(\n item.text,\n startIndex,\n searchString.length,\n );\n matchingItems.push({ ...item, text: highlightedText });\n }\n }\n });\n\n return sortSearchBoxItems({ customSortFunction, items: matchingItems, searchString });\n};\n"],"mappings":"AAEA,MAAMA,gBAAgB,GAAGA,CAACC,IAAY,EAAEC,UAAkB,EAAEC,MAAc,KAAK;EAC3E,MAAMC,MAAM,GAAGH,IAAI,CAACI,SAAS,CAAC,CAAC,EAAEH,UAAU,CAAC;EAC5C,MAAMI,WAAW,GAAGL,IAAI,CAACI,SAAS,CAACH,UAAU,EAAEA,UAAU,GAAGC,MAAM,CAAC;EACnE,MAAMI,KAAK,GAAGN,I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B,CAAC;QAC/D,MAAMc,eAAe,GAAGlD,gBAAgB,CACpC6C,IAAI,CAAC5C,IAAI,EACTC,UAAU,EACV+B,YAAY,CAAC9B,MACjB,CAAC;QACDyC,aAAa,CAACI,IAAI,CAAC;UAAE,GAAGH,IAAI;UAAE5C,IAAI,EAAEiD;QAAgB,CAAC,CAAC;MAC1D;IACJ;EACJ,CAAC,CAAC;EAEF,OAAOnB,kBAAkB,CAAC;IAAEC,kBAAkB;IAAEE,KAAK,EAAEU,aAAa;IAAEX;EAAa,CAAC,CAAC;AACzF,CAAC","ignoreList":[]}
@@ -0,0 +1,52 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { filterSearchBoxItems } from '../components/search-box/SearchBox';
3
+ import { searchList } from './searchBox';
4
+ const items = [{
5
+ id: '2',
6
+ text: 'Zweite'
7
+ }, {
8
+ id: '1',
9
+ text: 'Erste'
10
+ }];
11
+ describe('searchList', () => {
12
+ it('uses the custom sort function instead of the default sort', () => {
13
+ const result = searchList({
14
+ customSortFunction: (a, b) => b.id.localeCompare(a.id),
15
+ items,
16
+ searchString: ''
17
+ });
18
+ expect(result.map(({
19
+ id
20
+ }) => id)).toEqual(['2', '1']);
21
+ });
22
+ it('still filters before applying the custom sort function', () => {
23
+ const result = searchList({
24
+ customSortFunction: (a, b) => a.id.localeCompare(b.id),
25
+ items,
26
+ searchString: 'e'
27
+ });
28
+ expect(result.map(({
29
+ id
30
+ }) => id)).toEqual(['1', '2']);
31
+ });
32
+ it('uses only the custom filter when shouldUseCustomFilterOnly is enabled', () => {
33
+ const values = [];
34
+ const result = filterSearchBoxItems({
35
+ customFilter: ({
36
+ id
37
+ }, value) => {
38
+ values.push(value);
39
+ return id === '2';
40
+ },
41
+ customSortFunction: (a, b) => a.id.localeCompare(b.id),
42
+ items,
43
+ searchString: 'does-not-match',
44
+ shouldUseCustomFilterOnly: true
45
+ });
46
+ expect(result.map(({
47
+ id
48
+ }) => id)).toEqual(['2']);
49
+ expect(values).toEqual(['does-not-match', 'does-not-match']);
50
+ });
51
+ });
52
+ //# sourceMappingURL=searchBox.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchBox.test.js","names":["describe","expect","it","filterSearchBoxItems","searchList","items","id","text","result","customSortFunction","a","b","localeCompare","searchString","map","toEqual","values","customFilter","value","push","shouldUseCustomFilterOnly"],"sources":["../../../src/utils/searchBox.test.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest';\nimport type { ISearchBoxItem } from '../types/searchBox';\nimport { filterSearchBoxItems } from '../components/search-box/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']);\n });\n\n it('uses only the custom filter when shouldUseCustomFilterOnly is enabled', () => {\n const values: string[] = [];\n const result = filterSearchBoxItems({\n customFilter: ({ id }, value) => {\n values.push(value);\n return id === '2';\n },\n customSortFunction: (a, b) => a.id.localeCompare(b.id),\n items,\n searchString: 'does-not-match',\n shouldUseCustomFilterOnly: true,\n });\n\n expect(result.map(({ id }) => id)).toEqual(['2']);\n expect(values).toEqual(['does-not-match', 'does-not-match']);\n });\n});\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAE7C,SAASC,oBAAoB,QAAQ,oCAAoC;AACzE,SAASC,UAAU,QAAQ,aAAa;AAExC,MAAMC,KAAuB,GAAG,CAC5B;EAAEC,EAAE,EAAE,GAAG;EAAEC,IAAI,EAAE;AAAS,CAAC,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ACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACJ,EAAE,CAACM,aAAa,CAACD,CAAC,CAACL,EAAE,CAAC;MACtDD,KAAK;MACLQ,YAAY,EAAE,gBAAgB;MAC9BO,yBAAyB,EAAE;IAC/B,CAAC,CAAC;IAEFnB,MAAM,CAACO,MAAM,CAACM,GAAG,CAAC,CAAC;MAAER;IAAG,CAAC,KAAKA,EAAE,CAAC,CAAC,CAACS,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;IACjDd,MAAM,CAACe,MAAM,CAAC,CAACD,OAAO,CAAC,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;EAChE,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -1,5 +1,6 @@
1
1
  import { ChangeEventHandler, FC, FocusEventHandler, KeyboardEventHandler } 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';
@@ -13,6 +14,13 @@ export interface TagInputSettings {
13
14
  shouldAllowMultiple?: TagInputProps['shouldAllowMultiple'];
14
15
  tags?: TagInputProps['tags'];
15
16
  }
17
+ export declare const filterSearchBoxItems: ({ customFilter, customSortFunction, items, searchString, shouldUseCustomFilterOnly, }: {
18
+ customFilter?: (item: ISearchBoxItem, value: string) => boolean;
19
+ customSortFunction?: SearchBoxSortFunction;
20
+ items: ISearchBoxItem[];
21
+ searchString: string;
22
+ shouldUseCustomFilterOnly?: boolean;
23
+ }) => ISearchBoxItem[];
16
24
  export type SearchBoxProps = {
17
25
  /**
18
26
  * The element where the content of the `ComboBox` should be rendered via React Portal.
@@ -20,8 +28,14 @@ export type SearchBoxProps = {
20
28
  container?: Element;
21
29
  /**
22
30
  * An optional callback function to filter the elements to be displayed
31
+ * @param item The item to filter.
32
+ * @param value The current input value.
33
+ */
34
+ customFilter?: (item: ISearchBoxItem, value: string) => boolean;
35
+ /**
36
+ * An optional callback function to sort the filtered elements to be displayed
23
37
  */
24
- customFilter?: (item: ISearchBoxItem) => boolean;
38
+ customSortFunction?: SearchBoxSortFunction;
25
39
  /**
26
40
  * If true, the custom filter replaces the built-in text search instead of narrowing its results.
27
41
  */
@@ -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.41",
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": "fc3d589835b668db40cc14ed59307d4cca80e9da"
97
97
  }