@agilant/toga-blox 1.0.55 → 1.0.56
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 +1 -2
- package/dist/components/SearchInput/SearchTextInput.d.ts +2 -2
- package/dist/components/SearchInput/SearchTextInput.js +30 -79
- 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,
|
|
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;
|
|
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, }) => {
|
|
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 }));
|
|
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,7 +29,6 @@ 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;
|
|
33
32
|
};
|
|
34
33
|
export interface OptionType {
|
|
35
34
|
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,
|
|
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;
|
|
24
24
|
export default SearchTextInput;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// SearchTextInput.tsx
|
|
3
2
|
import { useEffect, useRef, useState } from "react";
|
|
4
3
|
import { AnimatePresence, motion } from "framer-motion";
|
|
5
4
|
import { Input } from "../Input";
|
|
@@ -11,49 +10,42 @@ const SearchTextInput = ({ pillColor = "bg-sky-500", textHighlight = "text-sky-5
|
|
|
11
10
|
iconClasses: textHighlight,
|
|
12
11
|
name: "chevronDown",
|
|
13
12
|
weight: "solid",
|
|
14
|
-
}, dropdownOptions = [], selectedDropdownOption = "", onDropdownOptionSelect,
|
|
15
|
-
// Use a default key for simple mode if no column is provided.
|
|
16
|
-
localStorageKey = column ? "zu-table-store" : "searchCriteria", }) => {
|
|
13
|
+
}, dropdownOptions = [], selectedDropdownOption = "", onDropdownOptionSelect, searchCriteria = [], setSearchCriteria, column, handleFilter, localStorageKey = "zu-table-store", }) => {
|
|
17
14
|
const containerRef = useRef(null);
|
|
18
15
|
const [localSearchText, setLocalSearchText] = useState("");
|
|
19
16
|
const inputRef = useRef(null);
|
|
20
|
-
// On mount, focus input and load from local storage
|
|
17
|
+
// On mount, focus input and optionally load criteria from local storage.
|
|
21
18
|
useEffect(() => {
|
|
22
19
|
inputRef.current?.focus();
|
|
23
20
|
const stored = localStorage.getItem(localStorageKey);
|
|
24
|
-
if (stored) {
|
|
21
|
+
if (stored && setSearchCriteria) {
|
|
25
22
|
try {
|
|
26
23
|
const parsed = JSON.parse(stored);
|
|
27
|
-
|
|
28
|
-
if (column &&
|
|
29
|
-
parsed?.state?.searchCriteria &&
|
|
30
|
-
setSearchCriteria) {
|
|
24
|
+
if (parsed?.state?.searchCriteria) {
|
|
31
25
|
setSearchCriteria(parsed.state.searchCriteria);
|
|
32
26
|
}
|
|
33
|
-
// Otherwise, for simple mode, expect a plain array
|
|
34
|
-
else if (!column && setSearchItems) {
|
|
35
|
-
setSearchItems(parsed);
|
|
36
|
-
}
|
|
37
27
|
}
|
|
38
28
|
catch (e) {
|
|
39
|
-
console.error("Error parsing local storage:", e);
|
|
29
|
+
console.error("Error parsing local storage data:", e);
|
|
40
30
|
}
|
|
41
31
|
}
|
|
42
|
-
}, [localStorageKey,
|
|
32
|
+
}, [localStorageKey, setSearchCriteria]);
|
|
43
33
|
const handleInputChange = (event) => {
|
|
44
34
|
setLocalSearchText(event.target.value);
|
|
45
35
|
};
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
// Update local storage in the format used in your working app.
|
|
37
|
+
const updateLocalStorage = (criteria) => {
|
|
38
|
+
localStorage.setItem(localStorageKey, JSON.stringify({
|
|
39
|
+
state: { searchCriteria: criteria },
|
|
40
|
+
version: 0,
|
|
41
|
+
}));
|
|
48
42
|
};
|
|
49
|
-
|
|
50
|
-
const handleSubmitAdvanced = () => {
|
|
43
|
+
const handleSubmit = () => {
|
|
51
44
|
const trimmed = localSearchText.trim();
|
|
52
|
-
if (!trimmed
|
|
45
|
+
if (!trimmed)
|
|
53
46
|
return;
|
|
54
47
|
let newCriteria;
|
|
55
|
-
|
|
56
|
-
if (exists) {
|
|
48
|
+
if (searchCriteria.some((c) => c.searchColumn.id === column.id)) {
|
|
57
49
|
newCriteria = searchCriteria.map((c) => c.searchColumn.id === column.id
|
|
58
50
|
? { searchColumn: column, submittedSearchText: trimmed }
|
|
59
51
|
: c);
|
|
@@ -64,33 +56,13 @@ localStorageKey = column ? "zu-table-store" : "searchCriteria", }) => {
|
|
|
64
56
|
{ searchColumn: column, submittedSearchText: trimmed },
|
|
65
57
|
];
|
|
66
58
|
}
|
|
67
|
-
setSearchCriteria
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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);
|
|
59
|
+
if (setSearchCriteria) {
|
|
60
|
+
setSearchCriteria(newCriteria);
|
|
61
|
+
}
|
|
62
|
+
updateLocalStorage(newCriteria);
|
|
84
63
|
setLocalSearchText("");
|
|
85
|
-
if (handleFilter)
|
|
64
|
+
if (handleFilter) {
|
|
86
65
|
handleFilter();
|
|
87
|
-
};
|
|
88
|
-
const handleSubmit = () => {
|
|
89
|
-
if (column) {
|
|
90
|
-
handleSubmitAdvanced();
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
handleSubmitSimple();
|
|
94
66
|
}
|
|
95
67
|
};
|
|
96
68
|
const handleKeyDown = (e) => {
|
|
@@ -99,41 +71,20 @@ localStorageKey = column ? "zu-table-store" : "searchCriteria", }) => {
|
|
|
99
71
|
handleSubmit();
|
|
100
72
|
}
|
|
101
73
|
};
|
|
102
|
-
// Clear
|
|
103
|
-
const
|
|
104
|
-
if (!column || !setSearchCriteria || !searchCriteria)
|
|
105
|
-
return;
|
|
74
|
+
// Clear the criterion for this column.
|
|
75
|
+
const handleClearCriterion = () => {
|
|
106
76
|
const newCriteria = searchCriteria.filter((c) => c.searchColumn.id !== column.id);
|
|
107
|
-
setSearchCriteria
|
|
108
|
-
|
|
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);
|
|
120
|
-
setLocalSearchText("");
|
|
121
|
-
};
|
|
122
|
-
const handleClear = () => {
|
|
123
|
-
if (column) {
|
|
124
|
-
handleClearAdvanced();
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
handleClearSimple();
|
|
77
|
+
if (setSearchCriteria) {
|
|
78
|
+
setSearchCriteria(newCriteria);
|
|
128
79
|
}
|
|
80
|
+
updateLocalStorage(newCriteria);
|
|
81
|
+
setLocalSearchText("");
|
|
129
82
|
};
|
|
130
83
|
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`;
|
|
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 ${(
|
|
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 ${searchCriteria.some((c) => c.searchColumn.id === column.id)
|
|
132
85
|
? "border-b-2"
|
|
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:
|
|
134
|
-
|
|
135
|
-
|
|
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] }) }));
|
|
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: handleClearCriterion, "data-testid": "clear-icon", children: getFontAwesomeIcon("xmark", "regular") }), _jsx("div", { className: `${textHighlight} text-sm hover:text-primary`, children: getFontAwesomeIcon("search", "solid") })] })) }) }), onIconClick: handleClearCriterion })] }), searchCriteria.some((c) => c.searchColumn.id === column.id) && (_jsx("div", { className: "flex flex-wrap bg-white py-2 px-2 rounded-md", children: searchCriteria
|
|
87
|
+
.filter((c) => c.searchColumn.id === column.id)
|
|
88
|
+
.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: handleClearCriterion, text: _jsx(Text, { color: "text-white", fontFamily: "font-serif", size: "text-sm", tag: "span", text: criterion.submittedSearchText }), badgeContainerClasses: pillClassnames, type: "span" }, index))) }))] }) }));
|
|
138
89
|
};
|
|
139
90
|
export default SearchTextInput;
|