react-core-ts 1.0.42 → 1.0.43

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 (44) hide show
  1. package/README.md +50 -0
  2. package/dist/AutoComplete.d.ts +2 -2
  3. package/dist/AutoComplete.js +44 -37
  4. package/dist/AutoComplete.js.map +1 -1
  5. package/dist/AutoCompleteWithSelectedList.d.ts +4 -0
  6. package/dist/AutoCompleteWithSelectedList.js +446 -0
  7. package/dist/AutoCompleteWithSelectedList.js.map +1 -0
  8. package/dist/ExpandableAutoComplete.js +12 -5
  9. package/dist/ExpandableAutoComplete.js.map +1 -1
  10. package/dist/commontypes.d.ts +11 -4
  11. package/dist/components/DropdownList.js +2 -2
  12. package/dist/components/DropdownList.js.map +1 -1
  13. package/dist/components/InputActions.d.ts +1 -0
  14. package/dist/components/InputActions.js +2 -2
  15. package/dist/components/InputActions.js.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +3 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/styles/styles/components/autocomplete.css +602 -0
  20. package/dist/styles/styles/components/selectedautocomplete.css +121 -0
  21. package/dist/styles/styles/components/treedropdown.css +63 -0
  22. package/dist/styles/styles/global.css +7 -0
  23. package/dist/utilities/autosuggestions.d.ts +2 -2
  24. package/dist/utilities/autosuggestions.js +10 -7
  25. package/dist/utilities/autosuggestions.js.map +1 -1
  26. package/dist/utilities/filterSuggestions.d.ts +1 -1
  27. package/dist/utilities/filterSuggestions.js +10 -5
  28. package/dist/utilities/filterSuggestions.js.map +1 -1
  29. package/docs/App.tsx +96 -4
  30. package/docs/index.html +1 -1
  31. package/package.json +1 -1
  32. package/src/AutoComplete.tsx +66 -51
  33. package/src/AutoCompleteWithSelectedList.tsx +677 -0
  34. package/src/ExpandableAutoComplete.tsx +13 -5
  35. package/src/commontypes.ts +14 -6
  36. package/src/components/DropdownList.tsx +3 -3
  37. package/src/components/InputActions.tsx +3 -1
  38. package/src/index.html +1 -1
  39. package/src/index.tsx +1 -0
  40. package/src/styles/components/autocomplete.css +18 -1
  41. package/src/styles/components/selectedautocomplete.css +121 -0
  42. package/src/styles/global.css +2 -1
  43. package/src/utilities/autosuggestions.ts +18 -12
  44. package/src/utilities/filterSuggestions.ts +10 -7
@@ -1,6 +1,10 @@
1
- type ValueProps = {
1
+ export type ValueProps = {
2
2
  [key: string]: string;
3
3
  };
4
+ export type TabPops = {
5
+ id: number | string;
6
+ label: string;
7
+ };
4
8
  export interface AutoSuggestionInputProps {
5
9
  id?: string;
6
10
  label?: string;
@@ -10,12 +14,12 @@ export interface AutoSuggestionInputProps {
10
14
  onChange: (value?: ValueProps | ValueProps[]) => void;
11
15
  data?: any[];
12
16
  type?:
13
- | 'custom_select'
14
- | 'auto_complete'
15
- | 'custom_search_select'
16
- | 'auto_suggestion';
17
+ | "custom_select"
18
+ | "auto_complete"
19
+ | "custom_search_select"
20
+ | "auto_suggestion";
17
21
  placeholder?: string;
18
- getData?: (key?: string, nextBlock?: number) => any;
22
+ getData?: (key?: string, nextBlock?: number, tabValue?: number | string) => any;
19
23
  errors?: any;
20
24
  name: string;
21
25
  readOnly?: boolean;
@@ -33,6 +37,7 @@ export interface AutoSuggestionInputProps {
33
37
  handleAction?: () => void;
34
38
  actionLabel?: string;
35
39
  notDataMessage?: string;
40
+ initialDataMessage?:string;
36
41
  selectedItems?: any[];
37
42
  onFocus?: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
38
43
  dopDownRef?: HTMLInputElement;
@@ -42,4 +47,7 @@ export interface AutoSuggestionInputProps {
42
47
  isTreeDropdown?: boolean;
43
48
  flatArray?: boolean;
44
49
  parentField?: string;
50
+ countOnly?: boolean; // only show selected items count
51
+ typeOnlyFetch?: boolean; // async only call when typed any value
52
+ tab?: TabPops[];
45
53
  }
@@ -25,7 +25,7 @@ const DropdownList: React.FC<ValueProps> = ({
25
25
  return (
26
26
  <div
27
27
  key={idx.toString()}
28
- className={`qbs-autocomplete-listitem-container ${
28
+ className={`qbs-autocomplete-listitem-container ${
29
29
  (isMultiple || singleSelect) && 'qbs-autocomplete-checkbox-container'
30
30
  } ${isSelected(suggestion, selected) ? 'is-selected' : ''}`}
31
31
  >
@@ -53,7 +53,7 @@ const DropdownList: React.FC<ValueProps> = ({
53
53
  </label>
54
54
  </div>
55
55
  )}
56
- <li
56
+ <div
57
57
  key={idx}
58
58
  className={`qbs-autocomplete-suggestions-item ${
59
59
  isSelected(suggestion, selected) ? 'is-selected' : ''
@@ -62,7 +62,7 @@ const DropdownList: React.FC<ValueProps> = ({
62
62
  data-testid={suggestion[desc]}
63
63
  >
64
64
  {suggestion[desc]}
65
- </li>
65
+ </div>
66
66
  </div>
67
67
  );
68
68
  };
@@ -5,6 +5,7 @@ type ValueProps = {
5
5
  inputValue: string;
6
6
  searchValue: string;
7
7
  dropOpen: boolean;
8
+ countOnly?: boolean;
8
9
  handleDropOpen: (e: any) => void;
9
10
  handleDropClose: (e: any) => void;
10
11
  disabled: boolean;
@@ -22,10 +23,11 @@ const InputActions: React.FC<ValueProps> = ({
22
23
  readOnly,
23
24
  expandable,
24
25
  handleClear,
26
+ countOnly
25
27
  }) => {
26
28
  return (
27
29
  <div className="qbs-autocomplete-close-icon">
28
- {(inputValue || searchValue) && !disabled && !readOnly && !expandable && (
30
+ {(inputValue || searchValue) && !disabled && !readOnly && !expandable && !countOnly && (
29
31
  <button
30
32
  onClick={handleClear}
31
33
  className="icon-button"
package/src/index.html CHANGED
@@ -1 +1 @@
1
- <div>sdfdsf</div>
1
+ <div>AutoComplete Components</div>
package/src/index.tsx CHANGED
@@ -7,6 +7,7 @@ export {
7
7
  export { default as AutoCompleteWithTreeStructure } from "./AutoCompleteWithTreeStructure";
8
8
  export type { AutoSuggestionInputProps } from "./commontypes";
9
9
  export { default as ExpandableAutoComplete } from "./ExpandableAutoComplete";
10
+ export { default as AutoCompleteWithSelectedList } from "./AutoCompleteWithSelectedList";
10
11
  export { deepEqual } from "./utilities/deepEqual";
11
12
  export { default as ExpandableToolTip } from "./utilities/expandableTootltip";
12
13
  export { default as ToolTip } from "./utilities/tooltip";
@@ -192,6 +192,18 @@ body * {
192
192
  gap: 5px;
193
193
  }
194
194
 
195
+ .qbs-dropdown-selected-container {
196
+ border: 0px;
197
+ border-top: 1px solid #d6d8dc;
198
+ min-height: 35px;
199
+ margin-top: 2px;
200
+ padding-top: 10px;
201
+ }
202
+
203
+ .qbs-dropdown-selected-container .qbs-clear-link {
204
+ color: #e76458;
205
+ }
206
+
195
207
  .qbs-textfield-default.expandable {
196
208
  height: auto;
197
209
  border: none;
@@ -348,6 +360,11 @@ ul {
348
360
  left: 0;
349
361
  }
350
362
 
363
+ .selected-items-container .badge {
364
+ background-color: #c63a3a;
365
+ color: #fff;
366
+ }
367
+
351
368
  .selected-item-more {
352
369
  display: flex;
353
370
  align-items: center;
@@ -422,7 +439,7 @@ span.dropdown-search-icon {
422
439
 
423
440
  .qbs-autocomplete-checkbox-container .qbs-autocomplete-suggestions-item {
424
441
  padding: 0;
425
- pointer-events: none;
442
+ /* pointer-events: none; */
426
443
  }
427
444
 
428
445
  .qbs-autocomplete-checkbox-container:hover {
@@ -0,0 +1,121 @@
1
+ .qbs-flex {
2
+ display: flex;
3
+ }
4
+ .qbs-flex-wrap {
5
+ flex-wrap: wrap;
6
+ }
7
+ .qbs-w-full {
8
+ width: 100%;
9
+ }
10
+ .qbs-mb-2 {
11
+ margin-bottom: 0.5rem;
12
+ }
13
+ .-qbs-mt-2 {
14
+ margin-top: -0.5rem;
15
+ }
16
+ .qbs-flex-1 {
17
+ flex: 1 1 0%;
18
+ }
19
+ .qbs-inline-block {
20
+ display: inline-block;
21
+ }
22
+ .qbs-text-sm {
23
+ font-size: 0.875rem;
24
+ }
25
+ .qbs-cursor-pointer {
26
+ cursor: pointer;
27
+ }
28
+ .qbs-text-center {
29
+ text-align: center;
30
+ }
31
+ .qbs-p-1 {
32
+ padding: 0.25rem;
33
+ }
34
+ .qbs-border-b-2 {
35
+ border-bottom-width: 2px;
36
+ }
37
+ .qbs-tab-item {
38
+ color: #4b5563;
39
+ border-color: #d1d5db;
40
+ }
41
+ .qbs-tab-item:hover {
42
+ color: #2563eb;
43
+ }
44
+ .qbs-tab-active-item {
45
+ color: #2563eb;
46
+ border-color: #2563eb;
47
+ }
48
+ .qbs-relative {
49
+ position: relative;
50
+ }
51
+ .qbs-gap-1 {
52
+ gap: 0.25rem;
53
+ }
54
+ .qbs-rounded-full {
55
+ border-radius: 9999px;
56
+ }
57
+ .qbs-text-xs {
58
+ font-size: 0.75rem;
59
+ }
60
+ .qbs-inline-flex {
61
+ display: inline-flex;
62
+ }
63
+ .qbs-items-center {
64
+ align-items: center;
65
+ }
66
+ .qbs-justify-center {
67
+ justify-content: center;
68
+ }
69
+ .qbs-px-2 {
70
+ padding-left: 0.5rem;
71
+ padding-right: 0.5rem;
72
+ }
73
+ .qbs-py-1 {
74
+ padding-top: 0.25rem;
75
+ padding-bottom: 0.25rem;
76
+ }
77
+ .qbs-leading-none {
78
+ line-height: 1;
79
+ }
80
+ .qbs-min-w-6 {
81
+ min-width: 1.5rem;
82
+ }
83
+ .qbs-min-h-6 {
84
+ min-height: 1.5rem;
85
+ }
86
+ .qbs-align-middle {
87
+ vertical-align: middle;
88
+ }
89
+ .qbs-min-emp-h {
90
+ min-height: 183px;
91
+ }
92
+ .qbs-py-80 {
93
+ padding-top: 80px;
94
+ padding-bottom: 80px;
95
+ }
96
+ .qbs-flex-grow {
97
+ flex-grow: 1;
98
+ }
99
+ .qbs-text-right {
100
+ text-align: right;
101
+ }
102
+ .qbs-readmore-collapse {
103
+ cursor: pointer;
104
+ width: 100%;
105
+ text-align: center;
106
+ display: flex;
107
+ justify-content: center;
108
+ margin-top: 5px;
109
+ }
110
+ .qbs-readmore-collapse div {
111
+ border-radius: 9999px;
112
+ min-width: 1.5rem;
113
+ min-height: 1.5rem;
114
+ padding: 5px;
115
+ }
116
+ .qbs-more-collapse:hover {
117
+ background-color: #d1d5db;
118
+ }
119
+ .qbs-hidden {
120
+ display: none;
121
+ }
@@ -3,4 +3,5 @@
3
3
  @tailwind utilities;
4
4
 
5
5
  @import './components/autocomplete.css';
6
- @import './components/treedropdown.css';
6
+ @import './components/treedropdown.css';
7
+ @import './components/selectedautocomplete.css';
@@ -1,20 +1,21 @@
1
- import { useEffect, useState } from 'react';
1
+ import { useEffect, useState } from "react";
2
2
 
3
3
  type ValueProps = {
4
4
  [key: string]: string;
5
5
  };
6
6
 
7
7
  type UseSuggestionsType = (
8
- getData: (key?: string, next?: number) => Promise<ValueProps[]>,
8
+ getData: (key?: string, next?: number, tabValue?: number | string) => Promise<ValueProps[]>,
9
9
  initialData?: ValueProps[],
10
10
  dropOpen?: boolean,
11
11
  asyncFetch?: boolean,
12
12
  paginationEnabled?: boolean,
13
- initialLoad?: boolean,
13
+ typeOnlyFetch?: boolean,
14
14
  inputValue?: string,
15
15
  isMultiple?: boolean,
16
16
  setNextPage?: (value: number) => void,
17
- selectedItems?: any[]
17
+ selectedItems?: any[],
18
+ initialLoad?: boolean,
18
19
  ) => {
19
20
  suggestions: ValueProps[];
20
21
  isLoading: boolean;
@@ -22,7 +23,8 @@ type UseSuggestionsType = (
22
23
  handlePickSuggestions: (
23
24
  value?: string,
24
25
  next?: number,
25
- append?: boolean
26
+ append?: boolean,
27
+ tabValue?: string | number
26
28
  ) => Promise<void>;
27
29
  };
28
30
 
@@ -33,10 +35,11 @@ export const useSuggestions: UseSuggestionsType = (
33
35
  asyncFetch = false,
34
36
  paginationEnabled = false,
35
37
  initialLoad = false,
36
- inputValue = '',
38
+ inputValue = "",
37
39
  isMultiple,
38
40
  setNextPage,
39
- selectedItems = []
41
+ selectedItems = [],
42
+ typeOnlyFetch = false
40
43
  ) => {
41
44
  const [suggestions, setSuggestions] = useState<ValueProps[]>(initialData);
42
45
  const [isLoading, setIsLoading] = useState<boolean>(false);
@@ -44,12 +47,15 @@ export const useSuggestions: UseSuggestionsType = (
44
47
  const handlePickSuggestions = async (
45
48
  value?: string,
46
49
  nextPage?: number,
47
- appendData?: boolean
50
+ appendData?: boolean,
51
+ tabValue?: string | number
48
52
  ) => {
49
53
  setIsLoading(true);
50
54
  try {
51
55
  const data = await (asyncFetch || initialLoad
52
- ? getData(value, nextPage)
56
+ ? typeOnlyFetch && value === ""
57
+ ? Promise.resolve([])
58
+ : getData(value, nextPage, tabValue)
53
59
  : Promise.resolve(initialData));
54
60
  if (!data || data?.length === 0) {
55
61
  setNextPage(undefined);
@@ -57,7 +63,7 @@ export const useSuggestions: UseSuggestionsType = (
57
63
  const newSuggestions = appendData ? [...suggestions, ...data] : data;
58
64
  setSuggestions(newSuggestions);
59
65
  } catch (error) {
60
- console.error('Error fetching data:', error);
66
+ console.error("Error fetching data:", error);
61
67
  } finally {
62
68
  setIsLoading(false);
63
69
  }
@@ -67,14 +73,14 @@ export const useSuggestions: UseSuggestionsType = (
67
73
  if (dropOpen) {
68
74
  if (!isMultiple && (!inputValue || suggestions.length === 0)) {
69
75
  setNextPage(1);
70
- handlePickSuggestions('', paginationEnabled ? 1 : undefined);
76
+ handlePickSuggestions("", paginationEnabled ? 1 : undefined);
71
77
  } else if (
72
78
  isMultiple &&
73
79
  (suggestions.length === 0 ||
74
80
  !selectedItems ||
75
81
  selectedItems?.length === 0)
76
82
  ) {
77
- handlePickSuggestions('', paginationEnabled ? 1 : undefined);
83
+ handlePickSuggestions("", paginationEnabled ? 1 : undefined);
78
84
  }
79
85
  }
80
86
  }, [dropOpen]);
@@ -7,14 +7,15 @@ export const filterSuggestions = (
7
7
  query: string,
8
8
  type: string,
9
9
  desc: string,
10
- inputValue?: string,
11
- async?: boolean,
12
- isTreeDropdown?: boolean
10
+ inputValue?: any[] | string,
11
+ async?: boolean, // API filter
12
+ isTreeDropdown?: boolean, // Tree dropdowns
13
+ withoutSort?: boolean // Don't show selected items on top of the suggections
13
14
  ): Item[] => {
14
15
  if (
15
- (type === 'custom_search_select' ||
16
- type === 'auto_complete' ||
17
- type === 'auto_suggestion') &&
16
+ (type === "custom_search_select" ||
17
+ type === "auto_complete" ||
18
+ type === "auto_suggestion") &&
18
19
  !async &&
19
20
  query &&
20
21
  !isTreeDropdown
@@ -23,7 +24,9 @@ export const filterSuggestions = (
23
24
  item[desc].toLowerCase().includes(query.toLowerCase())
24
25
  );
25
26
  }
26
- return isTreeDropdown ? data : sortedArrayData(data, inputValue, desc);
27
+ return isTreeDropdown || withoutSort
28
+ ? data
29
+ : sortedArrayData(data, inputValue, desc);
27
30
  };
28
31
 
29
32
  const sortedArrayData = (