@agilant/toga-blox 1.0.52 → 1.0.55
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.
- package/dist/components/SearchInput/SearchInput.d.ts +1 -1
- package/dist/components/SearchInput/SearchInput.js +2 -2
- package/dist/components/SearchInput/SearchInput.types.d.ts +2 -1
- package/dist/components/SearchInput/SearchTextInput.d.ts +2 -2
- package/dist/components/SearchInput/SearchTextInput.js +79 -30
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { SearchInputProps } from "./SearchInput.types";
|
|
2
|
-
declare const SearchInput: <T extends object>({ bgColor, textHighlight, inputType, dropdownIconProp, dropdownOptions, selectedDropdownOption, onDropdownOptionSelect, searchItems, setSearchItems, toggleStatus, setToggleStatus, minValue, setMinValue, maxValue, setMaxValue, onChange, selectedValue, selectedDate, onDateSelect, selectedStartDate, onStartDateSelect, selectedEndDate, onEndDateSelect, handleFilter, }: SearchInputProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare const SearchInput: <T extends object>({ bgColor, textHighlight, inputType, dropdownIconProp, dropdownOptions, selectedDropdownOption, onDropdownOptionSelect, searchItems, setSearchItems, toggleStatus, setToggleStatus, minValue, setMinValue, maxValue, setMaxValue, onChange, selectedValue, selectedDate, onDateSelect, selectedStartDate, onStartDateSelect, selectedEndDate, onEndDateSelect, handleFilter, localStorageKey, }: SearchInputProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default SearchInput;
|
|
@@ -9,7 +9,7 @@ const SearchInput = ({ bgColor = "bg-sky-500", textHighlight = "text-sky-500", i
|
|
|
9
9
|
name: "chevronDown",
|
|
10
10
|
weight: "bold",
|
|
11
11
|
iconClasses: "text-black",
|
|
12
|
-
}, dropdownOptions = [], selectedDropdownOption = "", onDropdownOptionSelect, searchItems = [], setSearchItems, toggleStatus = false, setToggleStatus, minValue, setMinValue, maxValue, setMaxValue, onChange, selectedValue, selectedDate, onDateSelect, selectedStartDate, onStartDateSelect, selectedEndDate, onEndDateSelect, handleFilter, }) => {
|
|
12
|
+
}, dropdownOptions = [], selectedDropdownOption = "", onDropdownOptionSelect, searchItems = [], setSearchItems, toggleStatus = false, setToggleStatus, minValue, setMinValue, maxValue, setMaxValue, onChange, selectedValue, selectedDate, onDateSelect, selectedStartDate, onStartDateSelect, selectedEndDate, onEndDateSelect, handleFilter, localStorageKey, }) => {
|
|
13
13
|
const containerRef = useRef(null);
|
|
14
14
|
const inputRef = useRef(null);
|
|
15
15
|
useEffect(() => {
|
|
@@ -18,7 +18,7 @@ const SearchInput = ({ bgColor = "bg-sky-500", textHighlight = "text-sky-500", i
|
|
|
18
18
|
return (_jsx("div", { ref: containerRef, className: "", children: (() => {
|
|
19
19
|
switch (inputType) {
|
|
20
20
|
case "text":
|
|
21
|
-
return (_jsx(SearchTextInput, { dropdownIconProp: dropdownIconProp, dropdownOptions: dropdownOptions, selectedDropdownOption: selectedDropdownOption, onDropdownOptionSelect: onDropdownOptionSelect, searchItems: searchItems, setSearchItems: setSearchItems, handleFilter: handleFilter, column: undefined }));
|
|
21
|
+
return (_jsx(SearchTextInput, { dropdownIconProp: dropdownIconProp, dropdownOptions: dropdownOptions, selectedDropdownOption: selectedDropdownOption, onDropdownOptionSelect: onDropdownOptionSelect, searchItems: searchItems, setSearchItems: setSearchItems, handleFilter: handleFilter, column: undefined, localStorageKey: localStorageKey }));
|
|
22
22
|
case "number":
|
|
23
23
|
return (_jsx(SearchNumberInput, { dropdownIconProp: dropdownIconProp, dropdownOptions: dropdownOptions, selectedDropdownOption: selectedDropdownOption, onDropdownOptionSelect: onDropdownOptionSelect, toggleStatus: toggleStatus, setToggleStatus: setToggleStatus, minValue: minValue, maxValue: maxValue, setMinValue: setMinValue, setMaxValue: setMaxValue, handleFilter: handleFilter }));
|
|
24
24
|
case "multiSelect":
|
|
@@ -7,7 +7,7 @@ export type SearchInputProps<T extends object> = {
|
|
|
7
7
|
handleFilter: () => void;
|
|
8
8
|
bgColor?: string;
|
|
9
9
|
textHighlight?: string;
|
|
10
|
-
inputType?:
|
|
10
|
+
inputType?: "text" | "number" | "date" | "boolean" | "multiSelect";
|
|
11
11
|
dropdownOptions?: string[] | OptionType[] | number[];
|
|
12
12
|
selectedDropdownOption?: string | OptionType | number;
|
|
13
13
|
onDropdownOptionSelect?: (option: string) => void;
|
|
@@ -29,6 +29,7 @@ export type SearchInputProps<T extends object> = {
|
|
|
29
29
|
onStartDateSelect?: (date: Date) => void;
|
|
30
30
|
selectedEndDate?: Date;
|
|
31
31
|
onEndDateSelect?: (date: Date) => void;
|
|
32
|
+
localStorageKey?: string;
|
|
32
33
|
};
|
|
33
34
|
export interface OptionType {
|
|
34
35
|
uuid: string;
|
|
@@ -16,9 +16,9 @@ type SearchTextInputProps<T extends object> = {
|
|
|
16
16
|
setSearchItems?: React.Dispatch<React.SetStateAction<string[]>>;
|
|
17
17
|
searchCriteria?: SearchCriterion<T>[];
|
|
18
18
|
setSearchCriteria?: React.Dispatch<React.SetStateAction<SearchCriterion<T>[]>>;
|
|
19
|
-
column
|
|
19
|
+
column?: ColumnInstance<T>;
|
|
20
20
|
handleFilter?: () => void;
|
|
21
21
|
localStorageKey?: string;
|
|
22
22
|
};
|
|
23
|
-
declare const SearchTextInput: <T extends object>({ pillColor, textHighlight, dropdownIconProp, dropdownOptions, selectedDropdownOption, onDropdownOptionSelect, searchCriteria, setSearchCriteria, column, handleFilter, localStorageKey, }: SearchTextInputProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
declare const SearchTextInput: <T extends object>({ pillColor, textHighlight, dropdownIconProp, dropdownOptions, selectedDropdownOption, onDropdownOptionSelect, searchItems, setSearchItems, searchCriteria, setSearchCriteria, column, handleFilter, localStorageKey, }: SearchTextInputProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
24
24
|
export default SearchTextInput;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// SearchTextInput.tsx
|
|
2
3
|
import { useEffect, useRef, useState } from "react";
|
|
3
4
|
import { AnimatePresence, motion } from "framer-motion";
|
|
4
5
|
import { Input } from "../Input";
|
|
@@ -10,42 +11,49 @@ const SearchTextInput = ({ pillColor = "bg-sky-500", textHighlight = "text-sky-5
|
|
|
10
11
|
iconClasses: textHighlight,
|
|
11
12
|
name: "chevronDown",
|
|
12
13
|
weight: "solid",
|
|
13
|
-
}, dropdownOptions = [], selectedDropdownOption = "", onDropdownOptionSelect,
|
|
14
|
+
}, dropdownOptions = [], selectedDropdownOption = "", onDropdownOptionSelect, searchItems, setSearchItems, searchCriteria, setSearchCriteria, column, handleFilter,
|
|
15
|
+
// Use a default key for simple mode if no column is provided.
|
|
16
|
+
localStorageKey = column ? "zu-table-store" : "searchCriteria", }) => {
|
|
14
17
|
const containerRef = useRef(null);
|
|
15
18
|
const [localSearchText, setLocalSearchText] = useState("");
|
|
16
19
|
const inputRef = useRef(null);
|
|
17
|
-
// On mount, focus input and
|
|
20
|
+
// On mount, focus input and load from local storage
|
|
18
21
|
useEffect(() => {
|
|
19
22
|
inputRef.current?.focus();
|
|
20
23
|
const stored = localStorage.getItem(localStorageKey);
|
|
21
|
-
if (stored
|
|
24
|
+
if (stored) {
|
|
22
25
|
try {
|
|
23
26
|
const parsed = JSON.parse(stored);
|
|
24
|
-
|
|
27
|
+
// For advanced mode, expect an object with state.searchCriteria
|
|
28
|
+
if (column &&
|
|
29
|
+
parsed?.state?.searchCriteria &&
|
|
30
|
+
setSearchCriteria) {
|
|
25
31
|
setSearchCriteria(parsed.state.searchCriteria);
|
|
26
32
|
}
|
|
33
|
+
// Otherwise, for simple mode, expect a plain array
|
|
34
|
+
else if (!column && setSearchItems) {
|
|
35
|
+
setSearchItems(parsed);
|
|
36
|
+
}
|
|
27
37
|
}
|
|
28
38
|
catch (e) {
|
|
29
|
-
console.error("Error parsing local storage
|
|
39
|
+
console.error("Error parsing local storage:", e);
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
|
-
}, [localStorageKey, setSearchCriteria]);
|
|
42
|
+
}, [localStorageKey, column, setSearchCriteria, setSearchItems]);
|
|
33
43
|
const handleInputChange = (event) => {
|
|
34
44
|
setLocalSearchText(event.target.value);
|
|
35
45
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
localStorage.setItem(localStorageKey, JSON.stringify({
|
|
39
|
-
state: { searchCriteria: criteria },
|
|
40
|
-
version: 0,
|
|
41
|
-
}));
|
|
46
|
+
const updateLocalStorage = (data) => {
|
|
47
|
+
localStorage.setItem(localStorageKey, JSON.stringify(data));
|
|
42
48
|
};
|
|
43
|
-
|
|
49
|
+
// Advanced mode: use searchCriteria with column info
|
|
50
|
+
const handleSubmitAdvanced = () => {
|
|
44
51
|
const trimmed = localSearchText.trim();
|
|
45
|
-
if (!trimmed)
|
|
52
|
+
if (!trimmed || !column || !setSearchCriteria || !searchCriteria)
|
|
46
53
|
return;
|
|
47
54
|
let newCriteria;
|
|
48
|
-
|
|
55
|
+
const exists = searchCriteria.some((c) => c.searchColumn.id === column.id);
|
|
56
|
+
if (exists) {
|
|
49
57
|
newCriteria = searchCriteria.map((c) => c.searchColumn.id === column.id
|
|
50
58
|
? { searchColumn: column, submittedSearchText: trimmed }
|
|
51
59
|
: c);
|
|
@@ -56,13 +64,33 @@ const SearchTextInput = ({ pillColor = "bg-sky-500", textHighlight = "text-sky-5
|
|
|
56
64
|
{ searchColumn: column, submittedSearchText: trimmed },
|
|
57
65
|
];
|
|
58
66
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
setSearchCriteria(newCriteria);
|
|
68
|
+
updateLocalStorage({
|
|
69
|
+
state: { searchCriteria: newCriteria },
|
|
70
|
+
version: 0,
|
|
71
|
+
});
|
|
72
|
+
setLocalSearchText("");
|
|
73
|
+
if (handleFilter)
|
|
74
|
+
handleFilter();
|
|
75
|
+
};
|
|
76
|
+
// Simple mode: use searchItems as plain string array
|
|
77
|
+
const handleSubmitSimple = () => {
|
|
78
|
+
const trimmed = localSearchText.trim();
|
|
79
|
+
if (!trimmed || !setSearchItems || !searchItems)
|
|
80
|
+
return;
|
|
81
|
+
const newItems = [...searchItems, trimmed];
|
|
82
|
+
setSearchItems(newItems);
|
|
83
|
+
updateLocalStorage(newItems);
|
|
63
84
|
setLocalSearchText("");
|
|
64
|
-
if (handleFilter)
|
|
85
|
+
if (handleFilter)
|
|
65
86
|
handleFilter();
|
|
87
|
+
};
|
|
88
|
+
const handleSubmit = () => {
|
|
89
|
+
if (column) {
|
|
90
|
+
handleSubmitAdvanced();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
handleSubmitSimple();
|
|
66
94
|
}
|
|
67
95
|
};
|
|
68
96
|
const handleKeyDown = (e) => {
|
|
@@ -71,20 +99,41 @@ const SearchTextInput = ({ pillColor = "bg-sky-500", textHighlight = "text-sky-5
|
|
|
71
99
|
handleSubmit();
|
|
72
100
|
}
|
|
73
101
|
};
|
|
74
|
-
// Clear
|
|
75
|
-
const
|
|
102
|
+
// Clear functions for each mode
|
|
103
|
+
const handleClearAdvanced = () => {
|
|
104
|
+
if (!column || !setSearchCriteria || !searchCriteria)
|
|
105
|
+
return;
|
|
76
106
|
const newCriteria = searchCriteria.filter((c) => c.searchColumn.id !== column.id);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
107
|
+
setSearchCriteria(newCriteria);
|
|
108
|
+
updateLocalStorage({
|
|
109
|
+
state: { searchCriteria: newCriteria },
|
|
110
|
+
version: 0,
|
|
111
|
+
});
|
|
112
|
+
setLocalSearchText("");
|
|
113
|
+
};
|
|
114
|
+
const handleClearSimple = () => {
|
|
115
|
+
if (!setSearchItems || !searchItems)
|
|
116
|
+
return;
|
|
117
|
+
const newItems = searchItems.filter((item) => item !== localSearchText);
|
|
118
|
+
setSearchItems(newItems);
|
|
119
|
+
updateLocalStorage(newItems);
|
|
81
120
|
setLocalSearchText("");
|
|
82
121
|
};
|
|
122
|
+
const handleClear = () => {
|
|
123
|
+
if (column) {
|
|
124
|
+
handleClearAdvanced();
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
handleClearSimple();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
83
130
|
const pillClassnames = `${pillColor} p-1 max-w-fit min-w-20 rounded-full flex justify-between items-center text-white text-xs px-4 border-none mr-4 mb-1`;
|
|
84
|
-
return (_jsx("div", { ref: containerRef, className: "w-[425px]", children: _jsxs("div", { className: "flex flex-col border-2 border-navy-200 rounded-md", children: [_jsxs("div", { className: `flex ${
|
|
131
|
+
return (_jsx("div", { ref: containerRef, className: "w-[425px]", children: _jsxs("div", { className: "flex flex-col border-2 border-navy-200 rounded-md", children: [_jsxs("div", { className: `flex ${(column ? searchCriteria?.length : searchItems?.length)
|
|
85
132
|
? "border-b-2"
|
|
86
|
-
: ""} h-full`, children: [_jsx(Dropdown, { options: dropdownOptions, selectedOption: selectedDropdownOption, onOptionSelect: onDropdownOptionSelect, optionClasses: "px-4 py-1 h-full flex items-center", menuClasses: "bg-white min-w-32", icon: dropdownIconProp, dropdownClasses: "border-0 border-r-2 w-auto" }), _jsx(Input, { ref: inputRef, focusRingColor: "focus:ring-transparent", hasAutoFocus: true, value: localSearchText, iconColor: "text-navy-400", onKeyDown: handleKeyDown, required: false, id: "", name: "", type: "text", onChange: handleInputChange, additionalClasses: "min-w-[250px] min-h-full text-gray flex", placeholder: "Search", hasIcons: true, firstIcon: localSearchText === "" ? (_jsx(AnimatePresence, { children: _jsx(motion.div, { initial: "initial", animate: "animate", exit: "exit", className: "text-navy-400", children: getFontAwesomeIcon("search", "regular") }) })) : undefined, iconPosition: "both", secondIcon: _jsx("div", { className: "border-transparent text-white min-w-9", children: _jsx(AnimatePresence, { children: localSearchText !== "" && (_jsxs(motion.div, { className: "flex justify-between items-center min-w-4 text-navy-400 hover:cursor-pointer hover:text-primary", initial: "initial", animate: "animate", exit: "exit", onClick: handleSubmit, children: [_jsx("div", { className: "bg-navy-50 pr-2 pl-1 text-gray-500", onClick:
|
|
87
|
-
|
|
88
|
-
|
|
133
|
+
: ""} h-full`, children: [_jsx(Dropdown, { options: dropdownOptions, selectedOption: selectedDropdownOption, onOptionSelect: onDropdownOptionSelect, optionClasses: "px-4 py-1 h-full flex items-center", menuClasses: "bg-white min-w-32", icon: dropdownIconProp, dropdownClasses: "border-0 border-r-2 w-auto" }), _jsx(Input, { ref: inputRef, focusRingColor: "focus:ring-transparent", hasAutoFocus: true, value: localSearchText, iconColor: "text-navy-400", onKeyDown: handleKeyDown, required: false, id: "", name: "", type: "text", onChange: handleInputChange, additionalClasses: "min-w-[250px] min-h-full text-gray flex", placeholder: "Search", hasIcons: true, firstIcon: localSearchText === "" ? (_jsx(AnimatePresence, { children: _jsx(motion.div, { initial: "initial", animate: "animate", exit: "exit", className: "text-navy-400", children: getFontAwesomeIcon("search", "regular") }) })) : undefined, iconPosition: "both", secondIcon: _jsx("div", { className: "border-transparent text-white min-w-9", children: _jsx(AnimatePresence, { children: localSearchText !== "" && (_jsxs(motion.div, { className: "flex justify-between items-center min-w-4 text-navy-400 hover:cursor-pointer hover:text-primary", initial: "initial", animate: "animate", exit: "exit", onClick: handleSubmit, children: [_jsx("div", { className: "bg-navy-50 pr-2 pl-1 text-gray-500", onClick: handleClear, "data-testid": "clear-icon", children: getFontAwesomeIcon("xmark", "regular") }), _jsx("div", { className: `${textHighlight} text-sm hover:text-primary`, children: getFontAwesomeIcon("search", "solid") })] })) }) }), onIconClick: handleClear })] }), (column ? searchCriteria?.length : searchItems?.length) ? (_jsx("div", { className: "flex flex-wrap bg-white py-2 px-2 rounded-md", children: column
|
|
134
|
+
? searchCriteria
|
|
135
|
+
?.filter((c) => c.searchColumn.id === column.id)
|
|
136
|
+
.map((criterion, index) => (_jsx(Badge, { backgroundColor: pillColor, borderRadius: "rounded-full", hasRightIcon: true, icon: _jsx("div", { className: "text-white text-xxs", "data-testid": "item-clear-icon", children: getFontAwesomeIcon("xmark", "solid") }), iconSize: "text-sm", mobileIconLabel: criterion.submittedSearchText, onClick: handleClear, text: _jsx(Text, { color: "text-white", fontFamily: "font-serif", size: "text-sm", tag: "span", text: criterion.submittedSearchText }), badgeContainerClasses: pillClassnames, type: "span" }, index)))
|
|
137
|
+
: searchItems?.map((item, index) => (_jsx(Badge, { backgroundColor: pillColor, borderRadius: "rounded-full", hasRightIcon: true, icon: _jsx("div", { className: "text-white text-xxs", "data-testid": "item-clear-icon", children: getFontAwesomeIcon("xmark", "solid") }), iconSize: "text-sm", mobileIconLabel: item, onClick: handleClear, text: _jsx(Text, { color: "text-white", fontFamily: "font-serif", size: "text-sm", tag: "span", text: item }), badgeContainerClasses: pillClassnames, type: "span" }, index))) })) : null] }) }));
|
|
89
138
|
};
|
|
90
139
|
export default SearchTextInput;
|