@agilant/toga-blox 1.0.54 → 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.
@@ -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?: ColumnInstance<T>;
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, searchItems, setSearchItems, 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, 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, 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" : "searchItems", }) => {
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
- // For advanced mode, expect an object with state.searchCriteria
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, column, setSearchCriteria, setSearchItems]);
32
+ }, [localStorageKey, setSearchCriteria]);
43
33
  const handleInputChange = (event) => {
44
34
  setLocalSearchText(event.target.value);
45
35
  };
46
- const updateLocalStorage = (data) => {
47
- localStorage.setItem(localStorageKey, JSON.stringify(data));
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
- // Advanced mode: use searchCriteria with column info
50
- const handleSubmitAdvanced = () => {
43
+ const handleSubmit = () => {
51
44
  const trimmed = localSearchText.trim();
52
- if (!trimmed || !column || !setSearchCriteria || !searchCriteria)
45
+ if (!trimmed)
53
46
  return;
54
47
  let newCriteria;
55
- const exists = searchCriteria.some((c) => c.searchColumn.id === column.id);
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" : "searchItems", }) => {
64
56
  { searchColumn: column, submittedSearchText: trimmed },
65
57
  ];
66
58
  }
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);
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" : "searchItems", }) => {
99
71
  handleSubmit();
100
72
  }
101
73
  };
102
- // Clear functions for each mode
103
- const handleClearAdvanced = () => {
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(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);
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 ${(column ? searchCriteria?.length : searchItems?.length)
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: 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] }) }));
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilant/toga-blox",
3
3
  "private": false,
4
- "version": "1.0.54",
4
+ "version": "1.0.56",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",