@eztrak/shared 0.13.8 → 0.14.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.
@@ -129,6 +129,11 @@ interface SearchInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "
129
129
  debounceDelay?: number;
130
130
  customIcon?: ReactNode | null;
131
131
  defaultValue?: string;
132
+ /**
133
+ * Pagination param reset to page 1 when the query changes. Defaults to "page";
134
+ * match `CustomPagination`'s `paramNames.page` if the screen overrides it.
135
+ */
136
+ pageParam?: string;
132
137
  }
133
138
  interface DropdownFilterProps<Option extends Record<string, unknown>> extends Omit<Props<Option, false>, "value" | "onChange" | "options" | "styles" | "name"> {
134
139
  /** URL search param key synced with the selected option. */
@@ -142,13 +147,18 @@ interface DropdownFilterProps<Option extends Record<string, unknown>> extends Om
142
147
  borderRadius?: string;
143
148
  /** When true, persists the selected value in localStorage under `name`. */
144
149
  saveToLocalStorage?: boolean;
150
+ /**
151
+ * Pagination param reset to page 1 when the selection changes. Defaults to
152
+ * "page"; match `CustomPagination`'s `paramNames.page` if the screen overrides it.
153
+ */
154
+ pageParam?: string;
145
155
  }
146
156
 
147
- declare function DropdownFilter<Option extends Record<string, unknown>>({ name, valueKey, options, placeholder, borderRadius, className, isClearable, isSearchable, isDisabled, isLoading, saveToLocalStorage, ...otherProps }: DropdownFilterProps<Option>): react.JSX.Element;
157
+ declare function DropdownFilter<Option extends Record<string, unknown>>({ name, valueKey, options, placeholder, borderRadius, className, isClearable, isSearchable, isDisabled, isLoading, saveToLocalStorage, pageParam, ...otherProps }: DropdownFilterProps<Option>): react.JSX.Element;
148
158
 
149
159
  declare function ResetFiltersButton({ label, showLabel, icon, variant, className, onReset, disabled, }: ResetFiltersButtonProps): react.JSX.Element;
150
160
 
151
- declare function SearchInput({ placeholder, searchBtn, searchClassName, searchWrapperClass, searchIconClassName, defaultParam, showIcon, name, type, liveSearch, debounceDelay, customIcon, defaultValue, ...props }: SearchInputProps): react.JSX.Element;
161
+ declare function SearchInput({ placeholder, searchBtn, searchClassName, searchWrapperClass, searchIconClassName, defaultParam, showIcon, name, type, liveSearch, debounceDelay, customIcon, defaultValue, pageParam, ...props }: SearchInputProps): react.JSX.Element;
152
162
 
153
163
  declare const dropdownStyles: <Option>(_borderRadius: string) => StylesConfig<Option, false>;
154
164
 
@@ -129,6 +129,11 @@ interface SearchInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "
129
129
  debounceDelay?: number;
130
130
  customIcon?: ReactNode | null;
131
131
  defaultValue?: string;
132
+ /**
133
+ * Pagination param reset to page 1 when the query changes. Defaults to "page";
134
+ * match `CustomPagination`'s `paramNames.page` if the screen overrides it.
135
+ */
136
+ pageParam?: string;
132
137
  }
133
138
  interface DropdownFilterProps<Option extends Record<string, unknown>> extends Omit<Props<Option, false>, "value" | "onChange" | "options" | "styles" | "name"> {
134
139
  /** URL search param key synced with the selected option. */
@@ -142,13 +147,18 @@ interface DropdownFilterProps<Option extends Record<string, unknown>> extends Om
142
147
  borderRadius?: string;
143
148
  /** When true, persists the selected value in localStorage under `name`. */
144
149
  saveToLocalStorage?: boolean;
150
+ /**
151
+ * Pagination param reset to page 1 when the selection changes. Defaults to
152
+ * "page"; match `CustomPagination`'s `paramNames.page` if the screen overrides it.
153
+ */
154
+ pageParam?: string;
145
155
  }
146
156
 
147
- declare function DropdownFilter<Option extends Record<string, unknown>>({ name, valueKey, options, placeholder, borderRadius, className, isClearable, isSearchable, isDisabled, isLoading, saveToLocalStorage, ...otherProps }: DropdownFilterProps<Option>): react.JSX.Element;
157
+ declare function DropdownFilter<Option extends Record<string, unknown>>({ name, valueKey, options, placeholder, borderRadius, className, isClearable, isSearchable, isDisabled, isLoading, saveToLocalStorage, pageParam, ...otherProps }: DropdownFilterProps<Option>): react.JSX.Element;
148
158
 
149
159
  declare function ResetFiltersButton({ label, showLabel, icon, variant, className, onReset, disabled, }: ResetFiltersButtonProps): react.JSX.Element;
150
160
 
151
- declare function SearchInput({ placeholder, searchBtn, searchClassName, searchWrapperClass, searchIconClassName, defaultParam, showIcon, name, type, liveSearch, debounceDelay, customIcon, defaultValue, ...props }: SearchInputProps): react.JSX.Element;
161
+ declare function SearchInput({ placeholder, searchBtn, searchClassName, searchWrapperClass, searchIconClassName, defaultParam, showIcon, name, type, liveSearch, debounceDelay, customIcon, defaultValue, pageParam, ...props }: SearchInputProps): react.JSX.Element;
152
162
 
153
163
  declare const dropdownStyles: <Option>(_borderRadius: string) => StylesConfig<Option, false>;
154
164
 
@@ -782,6 +782,14 @@ var dropdownStyles = (_borderRadius) => ({
782
782
  })
783
783
  });
784
784
 
785
+ // src/utils/resetPageParam.ts
786
+ function resetPageParam(params, pageKey = "page", defaultPage = "1") {
787
+ if (params.has(pageKey)) {
788
+ params.set(pageKey, defaultPage);
789
+ }
790
+ return params;
791
+ }
792
+
785
793
  // src/utils/localStorage.ts
786
794
  function getStorage() {
787
795
  if (typeof window === "undefined") return null;
@@ -827,6 +835,7 @@ function DropdownFilter({
827
835
  isDisabled = false,
828
836
  isLoading = false,
829
837
  saveToLocalStorage = false,
838
+ pageParam = "page",
830
839
  ...otherProps
831
840
  }) {
832
841
  const [searchParams, setSearchParams] = (0, import_react_router_dom2.useSearchParams)();
@@ -839,10 +848,10 @@ function DropdownFilter({
839
848
  if (stored != null && stored !== "") {
840
849
  setSearchParams((prev) => {
841
850
  prev.set(name, String(stored));
842
- return prev;
851
+ return resetPageParam(prev, pageParam);
843
852
  });
844
853
  }
845
- }, [saveToLocalStorage, name, searchParams, setSearchParams]);
854
+ }, [saveToLocalStorage, name, pageParam, searchParams, setSearchParams]);
846
855
  const currentValue = searchParams.get(name);
847
856
  const selectedOption = currentValue ? options?.find(
848
857
  (option) => option[valueKey]?.toString() === currentValue
@@ -850,12 +859,15 @@ function DropdownFilter({
850
859
  const handleChange = (selected) => {
851
860
  const selectedValue = selected && selected[valueKey] !== "" ? String(selected[valueKey]) : null;
852
861
  setSearchParams((prev) => {
862
+ if ((prev.get(name) ?? "") === (selectedValue ?? "")) {
863
+ return prev;
864
+ }
853
865
  if (!selectedValue) {
854
866
  prev.delete(name);
855
867
  } else {
856
868
  prev.set(name, selectedValue);
857
869
  }
858
- return prev;
870
+ return resetPageParam(prev, pageParam);
859
871
  });
860
872
  if (saveToLocalStorage) {
861
873
  if (selectedValue) {
@@ -972,6 +984,7 @@ function SearchInput({
972
984
  debounceDelay = 500,
973
985
  customIcon = null,
974
986
  defaultValue,
987
+ pageParam = "page",
975
988
  ...props
976
989
  }) {
977
990
  const [searchParams, setSearchParams] = (0, import_react_router_dom4.useSearchParams)();
@@ -979,17 +992,18 @@ function SearchInput({
979
992
  const [inputValue, setInputValue] = (0, import_react3.useState)(queryParam);
980
993
  const debounceTimerRef = (0, import_react3.useRef)(null);
981
994
  const updateSearchParams = (searchQuery) => {
982
- if (searchQuery?.trim()) {
983
- setSearchParams((prev) => {
984
- prev.set(defaultParam, searchQuery.trim());
995
+ const nextValue = searchQuery?.trim() ?? "";
996
+ setSearchParams((prev) => {
997
+ if ((prev.get(defaultParam) ?? "") === nextValue) {
985
998
  return prev;
986
- });
987
- } else {
988
- setSearchParams((prev) => {
999
+ }
1000
+ if (nextValue) {
1001
+ prev.set(defaultParam, nextValue);
1002
+ } else {
989
1003
  prev.delete(defaultParam);
990
- return prev;
991
- });
992
- }
1004
+ }
1005
+ return resetPageParam(prev, pageParam);
1006
+ });
993
1007
  };
994
1008
  const handleSearch = (e) => {
995
1009
  e.preventDefault();