@agilant/toga-blox 1.0.52 → 1.0.54

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, 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, searchCriteria = [], setSearchCriteria, column, handleFilter, localStorageKey = "zu-table-store", }) => {
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", }) => {
14
17
  const containerRef = useRef(null);
15
18
  const [localSearchText, setLocalSearchText] = useState("");
16
19
  const inputRef = useRef(null);
17
- // On mount, focus input and optionally load criteria from local storage.
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 && setSearchCriteria) {
24
+ if (stored) {
22
25
  try {
23
26
  const parsed = JSON.parse(stored);
24
- if (parsed?.state?.searchCriteria) {
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 data:", e);
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
- // 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
- }));
46
+ const updateLocalStorage = (data) => {
47
+ localStorage.setItem(localStorageKey, JSON.stringify(data));
42
48
  };
43
- const handleSubmit = () => {
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
- if (searchCriteria.some((c) => c.searchColumn.id === column.id)) {
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
- if (setSearchCriteria) {
60
- setSearchCriteria(newCriteria);
61
- }
62
- updateLocalStorage(newCriteria);
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 the criterion for this column.
75
- const handleClearCriterion = () => {
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
- if (setSearchCriteria) {
78
- setSearchCriteria(newCriteria);
79
- }
80
- updateLocalStorage(newCriteria);
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 ${searchCriteria.some((c) => c.searchColumn.id === column.id)
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: 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))) }))] }) }));
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilant/toga-blox",
3
3
  "private": false,
4
- "version": "1.0.52",
4
+ "version": "1.0.54",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",