dry-ux 1.74.0 → 1.75.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.
@@ -59,7 +59,7 @@ export declare const toHashCode: (input: string) => number;
59
59
  * @param key The key of the parameter.
60
60
  * @param value The value of the parameter.
61
61
  */
62
- export declare const insertUrlParam: (key: string, value: any) => void;
62
+ export declare const insertUrlParam: (key: any, value: any) => void;
63
63
  /**
64
64
  * Inserts multiple URL parameters.
65
65
  * @param params An object containing key-value pairs of parameters.
@@ -113,7 +113,20 @@ export declare const usePubSub: <T>() => {
113
113
  usePub: () => <TName extends keyof T, TPayload extends T[TName]>(event: TName, data?: TPayload) => void;
114
114
  useSub: <TName extends keyof T, TPayload_1 extends T[TName]>(event: TName, callback: (data: TPayload_1) => void) => () => void;
115
115
  };
116
+ /**
117
+ * Hook to get dimensions of an element or the viewport.
118
+ * @param ref
119
+ */
116
120
  export declare const useDimensions: (ref?: React.MutableRefObject<HTMLElement>) => {
117
121
  width: number;
118
122
  height: number;
119
123
  };
124
+ /**
125
+ * Hook to get and set URL search parameters.
126
+ * @template T The type of the URL parameters.
127
+ * @returns An object containing the current URL parameters and a function to set a parameter.
128
+ */
129
+ export declare const useSearchParams: <T>() => {
130
+ params: T;
131
+ setParam: <TKey extends keyof T, TValue extends T[TKey]>(key: TKey, value: TValue) => void;
132
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useDimensions = exports.usePubSub = exports.useIsVisible = exports.tryParseJson = exports.Deferred = exports.getUrlParams = exports.insertUrlParams = exports.insertUrlParam = exports.toHashCode = exports.StorageUtils = exports.fnWithAuthCheck = exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
3
+ exports.useSearchParams = exports.useDimensions = exports.usePubSub = exports.useIsVisible = exports.tryParseJson = exports.Deferred = exports.getUrlParams = exports.insertUrlParams = exports.insertUrlParam = exports.toHashCode = exports.StorageUtils = exports.fnWithAuthCheck = exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
4
4
  const React = require("react");
5
5
  /**
6
6
  * Returns a function that will call the given handler and prevent the default event behavior.
@@ -282,6 +282,10 @@ const usePubSub = () => {
282
282
  return { usePub, useSub };
283
283
  };
284
284
  exports.usePubSub = usePubSub;
285
+ /**
286
+ * Hook to get dimensions of an element or the viewport.
287
+ * @param ref
288
+ */
285
289
  const useDimensions = (ref) => {
286
290
  const [size, setSize] = React.useState({ width: 0, height: 0 });
287
291
  const element = (ref === null || ref === void 0 ? void 0 : ref.current) || document.documentElement;
@@ -296,3 +300,23 @@ const useDimensions = (ref) => {
296
300
  return size;
297
301
  };
298
302
  exports.useDimensions = useDimensions;
303
+ /**
304
+ * Hook to get and set URL search parameters.
305
+ * @template T The type of the URL parameters.
306
+ * @returns An object containing the current URL parameters and a function to set a parameter.
307
+ */
308
+ const useSearchParams = () => {
309
+ const [params, setParams] = React.useState((0, exports.getUrlParams)());
310
+ /**
311
+ * Sets a URL parameter and updates the state.
312
+ */
313
+ const setParam = React.useCallback((key, value) => {
314
+ (0, exports.insertUrlParam)(key, value);
315
+ setParams((0, exports.getUrlParams)());
316
+ }, []);
317
+ return {
318
+ params,
319
+ setParam,
320
+ };
321
+ };
322
+ exports.useSearchParams = useSearchParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dry-ux",
3
- "version": "1.74.0",
3
+ "version": "1.75.0",
4
4
  "description": "",
5
5
  "main": "dist/index",
6
6
  "scripts": {