@momo-kits/auto-complete 0.77.5 → 0.77.6

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.
Files changed (3) hide show
  1. package/index.tsx +3 -2
  2. package/package.json +1 -1
  3. package/types.ts +47 -3
package/index.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, {FC, useEffect, useState} from 'react';
2
2
  import {FlatList, TouchableOpacity} from 'react-native';
3
3
  import {Divider, Shadow, Text} from '@momo-kits/foundation';
4
- import {AutoCompleteProps, ListItemProps, SuggestItem} from './types';
4
+ import {AutoCompleteProps, SuggestItem} from './types';
5
5
  import styles from './styles';
6
6
 
7
7
  const AutoComplete: FC<AutoCompleteProps> = ({
@@ -9,6 +9,7 @@ const AutoComplete: FC<AutoCompleteProps> = ({
9
9
  query = '',
10
10
  onPressItem,
11
11
  maxItemShow = 5,
12
+ searchKey = 'title',
12
13
  }) => {
13
14
  const [haveSelected, setHaveSelected] = useState(false);
14
15
 
@@ -36,7 +37,7 @@ const AutoComplete: FC<AutoCompleteProps> = ({
36
37
  if (typeof item === 'string') {
37
38
  return regex.test(removeDiacritics(item.toLowerCase()));
38
39
  } else {
39
- return regex.test(removeDiacritics(item.title.toLowerCase()));
40
+ return regex.test(removeDiacritics(item?.[searchKey].toLowerCase()));
40
41
  }
41
42
  })
42
43
  .slice(0, maxItemShow);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/auto-complete",
3
- "version": "0.77.5",
3
+ "version": "0.77.6",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "peerDependencies": {
package/types.ts CHANGED
@@ -1,16 +1,60 @@
1
1
  import {ReactElement} from 'react';
2
2
 
3
+ /**
4
+ * Represents a suggested item in the autocomplete list. Each item has a title for display
5
+ * and a value that represents the underlying data.
6
+ */
3
7
  export type SuggestItem = {
4
- title: string;
5
- value?: string;
8
+ title: string; // The display text for a suggestion item.
9
+ value: string; // The underlying value or identifier for this item.
6
10
  };
7
11
 
12
+ /**
13
+ * Props for configuring the AutoComplete component.
14
+ */
8
15
  export type AutoCompleteProps = {
16
+ /**
17
+ * An array of strings or `SuggestItem` objects that will be used to create the
18
+ * autocomplete dropdown list.
19
+ */
9
20
  data: Array<string | SuggestItem>;
21
+
22
+ /**
23
+ * The current text in the autocomplete input field. This is used to determine
24
+ * which suggestions to display.
25
+ */
10
26
  query: string;
27
+
28
+ /**
29
+ * Optional. The maximum number of items to display in the dropdown list. If not
30
+ * provided, all matching items will be shown.
31
+ */
11
32
  maxItemShow?: number;
33
+
34
+ /**
35
+ * Optional. A function to render the UI of each item in the dropdown list.
36
+ * This is useful for adding custom styling or formatting to the displayed items.
37
+ */
12
38
  renderItem?: (data: string) => ReactElement;
39
+
40
+ /**
41
+ * A function that is called when a user selects an item from the autocomplete list.
42
+ * It receives two arguments: the display text of the selected item and its corresponding value.
43
+ */
13
44
  onPressItem?: (item: string, value: null | string | undefined) => void;
45
+
46
+ /**
47
+ * Indicates whether the 'title' or 'value' of a `SuggestItem` should be used for
48
+ * searching. This affects which items are filtered into the dropdown list as the
49
+ * user types in the input field.
50
+ */
51
+ searchKey: 'title' | 'value';
14
52
  };
15
53
 
16
- export type ListItemProps = {item: string; index: number};
54
+ /**
55
+ * Props for representing individual items in the autocomplete suggestions list.
56
+ */
57
+ export type ListItemProps = {
58
+ item: string; // The content or data of the list item, to be rendered in the list.
59
+ index: number; // Represents the position of this item within the list.
60
+ };