@eztrak/shared 0.6.8 → 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,
@@ -1043,15 +1159,16 @@ function Modal({
1043
1159
  closeOnEscape = true,
1044
1160
  zIndex = 1e3,
1045
1161
  isLoading = false,
1046
- customLoader = null
1162
+ customLoader = null,
1163
+ footerClassName
1047
1164
  }) {
1048
- const modalRef = (0, import_react4.useRef)(null);
1165
+ const modalRef = (0, import_react5.useRef)(null);
1049
1166
  const handleBackdropClick = (e) => {
1050
1167
  if (e.target === e.currentTarget && closeOnBackdropClick) {
1051
1168
  onClose();
1052
1169
  }
1053
1170
  };
1054
- (0, import_react4.useEffect)(() => {
1171
+ (0, import_react5.useEffect)(() => {
1055
1172
  const handleEscape = (e) => {
1056
1173
  if (e.key === "Escape" && isOpen && closeOnEscape) {
1057
1174
  onClose();
@@ -1066,7 +1183,7 @@ function Modal({
1066
1183
  document.body.style.overflow = "unset";
1067
1184
  };
1068
1185
  }, [isOpen, onClose, closeOnEscape]);
1069
- 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)(
1070
1187
  "div",
1071
1188
  {
1072
1189
  className: "fixed inset-0 bg-gray-500 bg-opacity-50 flex justify-center items-center z-1000 p-4",
@@ -1085,7 +1202,7 @@ function Modal({
1085
1202
  zIndex
1086
1203
  },
1087
1204
  children: [
1088
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1205
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1089
1206
  import_framer_motion.motion.div,
1090
1207
  {
1091
1208
  ref: modalRef,
@@ -1106,7 +1223,7 @@ function Modal({
1106
1223
  // Ensure modal doesn't exceed viewport height
1107
1224
  },
1108
1225
  children: [
1109
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1226
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1110
1227
  "div",
1111
1228
  {
1112
1229
  style: {
@@ -1114,43 +1231,43 @@ function Modal({
1114
1231
  },
1115
1232
  className: "sticky top-0 z-10 flex justify-between items-center bg-white text-2xl p-8 pb-4 rounded-t-3xl",
1116
1233
  children: [
1117
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { className: "font-semibold", children: title }),
1118
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center space-x-4", children: [
1119
- 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)(
1120
1237
  "button",
1121
1238
  {
1122
1239
  onClick: onPrint,
1123
1240
  className: "flex items-center gap-1 hover:text-gray-300 text-sm border p-1 rounded",
1124
1241
  children: [
1125
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_fa.FaPrint, { name: "FaPrint" }),
1126
- /* @__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" })
1127
1244
  ]
1128
1245
  }
1129
1246
  ),
1130
- onExport && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1247
+ onExport && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1131
1248
  "button",
1132
1249
  {
1133
1250
  onClick: onExport,
1134
1251
  className: "flex items-center gap-1 hover:text-gray-300 text-sm border p-1 rounded",
1135
1252
  children: [
1136
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_fa.FaFileExport, {}),
1137
- /* @__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" })
1138
1255
  ]
1139
1256
  }
1140
1257
  ),
1141
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1258
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1142
1259
  "button",
1143
1260
  {
1144
1261
  onClick: onClose,
1145
1262
  className: "px-2 hover:opacity-70 transition-opacity",
1146
- 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 })
1147
1264
  }
1148
1265
  )
1149
1266
  ] })
1150
1267
  ]
1151
1268
  }
1152
1269
  ),
1153
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1270
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1154
1271
  "div",
1155
1272
  {
1156
1273
  className: cn(
@@ -1160,25 +1277,13 @@ function Modal({
1160
1277
  children
1161
1278
  }
1162
1279
  ),
1163
- footer && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1280
+ footer && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1164
1281
  "div",
1165
1282
  {
1283
+ className: cn("sticky bottom-0 flex justify-end p-4 space-x-4 border-t bg-white ", footerClassName),
1166
1284
  style: {
1167
1285
  zIndex: 1e3,
1168
- position: "sticky",
1169
- bottom: 0,
1170
- left: 0,
1171
- right: 0,
1172
- width: "100%",
1173
- height: "100%",
1174
- backgroundColor: "white",
1175
- fontSize: "24px",
1176
- fontWeight: "semibold",
1177
- padding: "8px 16px",
1178
- borderRadius: "16px",
1179
- boxShadow: "0 0 10px 0 rgba(0, 0, 0, 0.1)",
1180
- margin: "0 16px",
1181
- justifyContent: "space-between"
1286
+ borderRadius: "24px"
1182
1287
  },
1183
1288
  children: footer
1184
1289
  }
@@ -1186,7 +1291,7 @@ function Modal({
1186
1291
  ]
1187
1292
  }
1188
1293
  ),
1189
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1294
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1190
1295
  "div",
1191
1296
  {
1192
1297
  className: "fixed inset-0 flex items-center justify-center bg-gray-200/60",
@@ -1195,7 +1300,7 @@ function Modal({
1195
1300
  "aria-live": "polite",
1196
1301
  role: "status",
1197
1302
  onClick: (e) => e.stopPropagation(),
1198
- 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" })
1199
1304
  }
1200
1305
  )
1201
1306
  ]
@@ -1217,6 +1322,7 @@ function Modal({
1217
1322
  Modal,
1218
1323
  ResetColumnsButton,
1219
1324
  ResetFiltersButton,
1325
+ SearchInput,
1220
1326
  TableLayoutToolbarControls,
1221
1327
  capitalizeText,
1222
1328
  checkIfExistsInArray,