dry-ux 1.66.0 → 1.67.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.
|
@@ -113,3 +113,7 @@ 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
|
+
export declare const useResize: (myRef: React.MutableRefObject<HTMLElement>) => {
|
|
117
|
+
width: number;
|
|
118
|
+
height: number;
|
|
119
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.useResize = 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,3 +282,22 @@ const usePubSub = () => {
|
|
|
282
282
|
return { usePub, useSub };
|
|
283
283
|
};
|
|
284
284
|
exports.usePubSub = usePubSub;
|
|
285
|
+
const useResize = (myRef) => {
|
|
286
|
+
const [size, setSize] = React.useState({ width: 0, height: 0 });
|
|
287
|
+
const handleResize = React.useCallback(() => {
|
|
288
|
+
if (myRef.current) {
|
|
289
|
+
setSize({ width: myRef.current.offsetWidth, height: myRef.current.offsetHeight });
|
|
290
|
+
}
|
|
291
|
+
}, [myRef]);
|
|
292
|
+
React.useEffect(() => {
|
|
293
|
+
window.addEventListener("load", handleResize);
|
|
294
|
+
window.addEventListener("resize", handleResize);
|
|
295
|
+
handleResize();
|
|
296
|
+
return () => {
|
|
297
|
+
window.removeEventListener("load", handleResize);
|
|
298
|
+
window.removeEventListener("resize", handleResize);
|
|
299
|
+
};
|
|
300
|
+
}, [myRef, handleResize]);
|
|
301
|
+
return size;
|
|
302
|
+
};
|
|
303
|
+
exports.useResize = useResize;
|