@telia/teddy 0.0.38 → 0.0.40
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/components/navigation-menu/global-navigation/global-navigation-desktop.cjs +3 -0
- package/dist/components/navigation-menu/global-navigation/global-navigation-desktop.js +3 -0
- package/dist/components/navigation-menu/global-navigation/global-navigation-my-pages.cjs +128 -16
- package/dist/components/navigation-menu/global-navigation/global-navigation-my-pages.js +129 -17
- package/dist/components/navigation-menu/global-navigation/global-navigation-root.d.ts +3 -1
- package/dist/components/navigation-menu/global-navigation/utils.cjs +54 -28
- package/dist/components/navigation-menu/global-navigation/utils.d.ts +52 -50
- package/dist/components/navigation-menu/global-navigation/utils.js +54 -28
- package/dist/style.css +67 -8
- package/dist/utils/useCallbackRef.cjs +31 -0
- package/dist/utils/useCallbackRef.d.ts +6 -0
- package/dist/utils/useCallbackRef.js +14 -0
- package/dist/utils/useLayoutEffect.cjs +23 -0
- package/dist/utils/useLayoutEffect.d.ts +36 -0
- package/dist/utils/useLayoutEffect.js +6 -0
- package/dist/utils/useSize.cjs +39 -0
- package/dist/utils/useSize.d.ts +31 -0
- package/dist/utils/useSize.js +39 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { useLayoutEffect } from "./useLayoutEffect.js";
|
|
3
|
+
function useSize(element) {
|
|
4
|
+
const [size, setSize] = React__default.useState(void 0);
|
|
5
|
+
useLayoutEffect(() => {
|
|
6
|
+
if (element) {
|
|
7
|
+
setSize({ width: element.offsetWidth, height: element.offsetHeight });
|
|
8
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
9
|
+
if (!Array.isArray(entries)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (!entries.length) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const entry = entries[0];
|
|
16
|
+
let width;
|
|
17
|
+
let height;
|
|
18
|
+
if ("borderBoxSize" in entry) {
|
|
19
|
+
const borderSizeEntry = entry["borderBoxSize"];
|
|
20
|
+
const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
|
|
21
|
+
width = borderSize["inlineSize"];
|
|
22
|
+
height = borderSize["blockSize"];
|
|
23
|
+
} else {
|
|
24
|
+
width = element.offsetWidth;
|
|
25
|
+
height = element.offsetHeight;
|
|
26
|
+
}
|
|
27
|
+
setSize({ width, height });
|
|
28
|
+
});
|
|
29
|
+
resizeObserver.observe(element, { box: "border-box" });
|
|
30
|
+
return () => resizeObserver.unobserve(element);
|
|
31
|
+
} else {
|
|
32
|
+
setSize(void 0);
|
|
33
|
+
}
|
|
34
|
+
}, [element]);
|
|
35
|
+
return size;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
useSize
|
|
39
|
+
};
|