@eztrak/shared 0.6.9 → 0.7.0

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/index.js CHANGED
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  Modal: () => Modal,
37
37
  ResetColumnsButton: () => ResetColumnsButton,
38
38
  ResetFiltersButton: () => ResetFiltersButton,
39
+ SearchInput: () => SearchInput,
39
40
  TableLayoutToolbarControls: () => TableLayoutToolbarControls,
40
41
  capitalizeText: () => capitalizeText,
41
42
  checkIfExistsInArray: () => checkIfExistsInArray,
@@ -999,17 +1000,132 @@ function ResetFiltersButton({
999
1000
  );
1000
1001
  }
1001
1002
 
1003
+ // src/components/search-filters/SearchInput.tsx
1004
+ var import_react4 = require("react");
1005
+ var import_fi = require("react-icons/fi");
1006
+ var import_react_router_dom3 = require("react-router-dom");
1007
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1008
+ function SearchInput({
1009
+ placeholder = "Search...",
1010
+ searchBtn = "",
1011
+ searchClassName = "",
1012
+ searchWrapperClass = "",
1013
+ searchIconClassName = "",
1014
+ defaultParam = "query",
1015
+ showIcon = true,
1016
+ name = "search",
1017
+ type = "search",
1018
+ liveSearch = false,
1019
+ debounceDelay = 500,
1020
+ customIcon = null,
1021
+ defaultValue,
1022
+ ...props
1023
+ }) {
1024
+ const [searchParams, setSearchParams] = (0, import_react_router_dom3.useSearchParams)();
1025
+ const queryParam = searchParams.get(defaultParam) || defaultValue || "";
1026
+ const [inputValue, setInputValue] = (0, import_react4.useState)(queryParam);
1027
+ const debounceTimerRef = (0, import_react4.useRef)(null);
1028
+ const updateSearchParams = (searchQuery) => {
1029
+ if (searchQuery?.trim()) {
1030
+ setSearchParams((prev) => {
1031
+ prev.set(defaultParam, searchQuery.trim());
1032
+ return prev;
1033
+ });
1034
+ } else {
1035
+ setSearchParams((prev) => {
1036
+ prev.delete(defaultParam);
1037
+ return prev;
1038
+ });
1039
+ }
1040
+ };
1041
+ const handleSearch = (e) => {
1042
+ e.preventDefault();
1043
+ const formData = new FormData(e.currentTarget);
1044
+ const searchQuery = formData.get(name);
1045
+ updateSearchParams(String(searchQuery ?? ""));
1046
+ };
1047
+ const handleInputChange = (e) => {
1048
+ const value = e.target.value;
1049
+ setInputValue(value);
1050
+ if (liveSearch) {
1051
+ if (debounceTimerRef.current) {
1052
+ clearTimeout(debounceTimerRef.current);
1053
+ }
1054
+ debounceTimerRef.current = setTimeout(() => {
1055
+ updateSearchParams(value);
1056
+ }, debounceDelay);
1057
+ }
1058
+ if (value === "") {
1059
+ if (debounceTimerRef.current) {
1060
+ clearTimeout(debounceTimerRef.current);
1061
+ }
1062
+ setInputValue("");
1063
+ updateSearchParams("");
1064
+ }
1065
+ };
1066
+ (0, import_react4.useEffect)(() => {
1067
+ setInputValue(queryParam);
1068
+ }, [queryParam]);
1069
+ (0, import_react4.useEffect)(() => {
1070
+ return () => {
1071
+ if (debounceTimerRef.current) {
1072
+ clearTimeout(debounceTimerRef.current);
1073
+ }
1074
+ };
1075
+ }, []);
1076
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1077
+ "form",
1078
+ {
1079
+ onSubmit: handleSearch,
1080
+ className: cn(
1081
+ "flex items-center justify-between bg-white rounded-md px-2 h-11",
1082
+ searchWrapperClass
1083
+ ),
1084
+ children: [
1085
+ showIcon && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1086
+ "button",
1087
+ {
1088
+ type: "submit",
1089
+ className: cn(
1090
+ "bg-white text-secondary rounded-full flex items-center justify-center w-10 h-10",
1091
+ searchBtn
1092
+ ),
1093
+ children: customIcon ? customIcon : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1094
+ import_fi.FiSearch,
1095
+ {
1096
+ className: cn("h-5 w-5 text-gray-400", searchIconClassName)
1097
+ }
1098
+ )
1099
+ }
1100
+ ),
1101
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1102
+ "input",
1103
+ {
1104
+ value: inputValue,
1105
+ onChange: handleInputChange,
1106
+ name,
1107
+ type,
1108
+ className: cn("outline-none text-sm w-96", searchClassName),
1109
+ placeholder,
1110
+ ...props
1111
+ }
1112
+ )
1113
+ ]
1114
+ }
1115
+ );
1116
+ }
1117
+
1002
1118
  // src/components/modal/Modal.tsx
1003
1119
  var import_framer_motion = require("framer-motion");
1004
- var import_react4 = require("react");
1120
+ var import_react5 = require("react");
1005
1121
  var import_react_dom = require("react-dom");
1006
1122
  var import_fa = require("react-icons/fa");
1007
1123
  var import_io5 = require("react-icons/io5");
1008
1124
 
1009
1125
  // src/components/Loader/Loader.tsx
1010
- var import_jsx_runtime4 = require("react/jsx-runtime");
1126
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1011
1127
  var Loader = ({ className, color = "#F54C00", size = "50px", speed = "1s" }) => {
1012
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `loader`, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1128
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `loader`, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1013
1129
  "div",
1014
1130
  {
1015
1131
  className: `spinner ${className}`,
@@ -1026,7 +1142,7 @@ var Loader = ({ className, color = "#F54C00", size = "50px", speed = "1s" }) =>
1026
1142
  };
1027
1143
 
1028
1144
  // src/components/modal/Modal.tsx
1029
- var import_jsx_runtime5 = require("react/jsx-runtime");
1145
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1030
1146
  function Modal({
1031
1147
  isOpen,
1032
1148
  onClose,
@@ -1046,13 +1162,13 @@ function Modal({
1046
1162
  customLoader = null,
1047
1163
  footerClassName
1048
1164
  }) {
1049
- const modalRef = (0, import_react4.useRef)(null);
1165
+ const modalRef = (0, import_react5.useRef)(null);
1050
1166
  const handleBackdropClick = (e) => {
1051
1167
  if (e.target === e.currentTarget && closeOnBackdropClick) {
1052
1168
  onClose();
1053
1169
  }
1054
1170
  };
1055
- (0, import_react4.useEffect)(() => {
1171
+ (0, import_react5.useEffect)(() => {
1056
1172
  const handleEscape = (e) => {
1057
1173
  if (e.key === "Escape" && isOpen && closeOnEscape) {
1058
1174
  onClose();
@@ -1067,7 +1183,7 @@ function Modal({
1067
1183
  document.body.style.overflow = "unset";
1068
1184
  };
1069
1185
  }, [isOpen, onClose, closeOnEscape]);
1070
- const modalContent = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_framer_motion.AnimatePresence, { children: isOpen && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1186
+ const modalContent = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_framer_motion.AnimatePresence, { children: isOpen && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1071
1187
  "div",
1072
1188
  {
1073
1189
  className: "fixed inset-0 bg-gray-500 bg-opacity-50 flex justify-center items-center z-1000 p-4",
@@ -1086,7 +1202,7 @@ function Modal({
1086
1202
  zIndex
1087
1203
  },
1088
1204
  children: [
1089
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1205
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1090
1206
  import_framer_motion.motion.div,
1091
1207
  {
1092
1208
  ref: modalRef,
@@ -1107,7 +1223,7 @@ function Modal({
1107
1223
  // Ensure modal doesn't exceed viewport height
1108
1224
  },
1109
1225
  children: [
1110
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1226
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1111
1227
  "div",
1112
1228
  {
1113
1229
  style: {
@@ -1115,43 +1231,43 @@ function Modal({
1115
1231
  },
1116
1232
  className: "sticky top-0 z-10 flex justify-between items-center bg-white text-2xl p-8 pb-4 rounded-t-3xl",
1117
1233
  children: [
1118
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { className: "font-semibold", children: title }),
1119
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center space-x-4", children: [
1120
- onPrint && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1234
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h2", { className: "font-semibold", children: title }),
1235
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center space-x-4", children: [
1236
+ onPrint && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1121
1237
  "button",
1122
1238
  {
1123
1239
  onClick: onPrint,
1124
1240
  className: "flex items-center gap-1 hover:text-gray-300 text-sm border p-1 rounded",
1125
1241
  children: [
1126
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_fa.FaPrint, { name: "FaPrint" }),
1127
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Print" })
1242
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_fa.FaPrint, { name: "FaPrint" }),
1243
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Print" })
1128
1244
  ]
1129
1245
  }
1130
1246
  ),
1131
- onExport && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1247
+ onExport && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1132
1248
  "button",
1133
1249
  {
1134
1250
  onClick: onExport,
1135
1251
  className: "flex items-center gap-1 hover:text-gray-300 text-sm border p-1 rounded",
1136
1252
  children: [
1137
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_fa.FaFileExport, {}),
1138
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Export" })
1253
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_fa.FaFileExport, {}),
1254
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Export" })
1139
1255
  ]
1140
1256
  }
1141
1257
  ),
1142
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1258
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1143
1259
  "button",
1144
1260
  {
1145
1261
  onClick: onClose,
1146
1262
  className: "px-2 hover:opacity-70 transition-opacity",
1147
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_io5.IoCloseCircleOutline, { color: "#8898AA", size: 25 })
1263
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_io5.IoCloseCircleOutline, { color: "#8898AA", size: 25 })
1148
1264
  }
1149
1265
  )
1150
1266
  ] })
1151
1267
  ]
1152
1268
  }
1153
1269
  ),
1154
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1270
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1155
1271
  "div",
1156
1272
  {
1157
1273
  className: cn(
@@ -1161,7 +1277,7 @@ function Modal({
1161
1277
  children
1162
1278
  }
1163
1279
  ),
1164
- footer && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1280
+ footer && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1165
1281
  "div",
1166
1282
  {
1167
1283
  className: cn("sticky bottom-0 flex justify-end p-4 space-x-4 border-t bg-white ", footerClassName),
@@ -1175,7 +1291,7 @@ function Modal({
1175
1291
  ]
1176
1292
  }
1177
1293
  ),
1178
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1294
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1179
1295
  "div",
1180
1296
  {
1181
1297
  className: "fixed inset-0 flex items-center justify-center bg-gray-200/60",
@@ -1184,7 +1300,7 @@ function Modal({
1184
1300
  "aria-live": "polite",
1185
1301
  role: "status",
1186
1302
  onClick: (e) => e.stopPropagation(),
1187
- children: customLoader ? customLoader : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Loader, { size: "48px" })
1303
+ children: customLoader ? customLoader : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Loader, { size: "48px" })
1188
1304
  }
1189
1305
  )
1190
1306
  ]
@@ -1206,6 +1322,7 @@ function Modal({
1206
1322
  Modal,
1207
1323
  ResetColumnsButton,
1208
1324
  ResetFiltersButton,
1325
+ SearchInput,
1209
1326
  TableLayoutToolbarControls,
1210
1327
  capitalizeText,
1211
1328
  checkIfExistsInArray,