@ndla/ui 6.1.1 → 6.1.2
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/es/Masthead/utils.js +27 -14
- package/lib/Masthead/utils.js +26 -13
- package/package.json +2 -2
- package/src/Masthead/utils.ts +23 -11
package/es/Masthead/utils.js
CHANGED
|
@@ -17,11 +17,13 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
import { useState } from 'react';
|
|
20
|
+
import { useEffect, useState } from 'react';
|
|
21
21
|
import { resizeObserver } from '@ndla/util';
|
|
22
22
|
export var getMastheadHeight = function getMastheadHeight() {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (typeof window !== 'undefined') {
|
|
24
|
+
var masthead = document.getElementById('masthead');
|
|
25
|
+
return masthead === null || masthead === void 0 ? void 0 : masthead.getBoundingClientRect().height;
|
|
26
|
+
}
|
|
25
27
|
};
|
|
26
28
|
export var useMastheadHeight = function useMastheadHeight() {
|
|
27
29
|
var _useState = useState(),
|
|
@@ -29,17 +31,28 @@ export var useMastheadHeight = function useMastheadHeight() {
|
|
|
29
31
|
height = _useState2[0],
|
|
30
32
|
setHeight = _useState2[1];
|
|
31
33
|
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
var _useState3 = useState(false),
|
|
35
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
36
|
+
mounted = _useState4[0],
|
|
37
|
+
setMounted = _useState4[1];
|
|
38
|
+
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
setMounted(true);
|
|
41
|
+
}, []);
|
|
42
|
+
useEffect(function () {
|
|
43
|
+
if (mounted) {
|
|
44
|
+
var masthead = document.getElementById('masthead');
|
|
45
|
+
|
|
46
|
+
var handleHeightChange = function handleHeightChange(el) {
|
|
47
|
+
var newHeight = el.getBoundingClientRect().height;
|
|
48
|
+
setHeight(newHeight);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (masthead) {
|
|
52
|
+
resizeObserver(masthead, handleHeightChange);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, [mounted]);
|
|
43
56
|
return {
|
|
44
57
|
height: height
|
|
45
58
|
};
|
package/lib/Masthead/utils.js
CHANGED
|
@@ -22,8 +22,10 @@ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(
|
|
|
22
22
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
23
23
|
|
|
24
24
|
var getMastheadHeight = function getMastheadHeight() {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (typeof window !== 'undefined') {
|
|
26
|
+
var masthead = document.getElementById('masthead');
|
|
27
|
+
return masthead === null || masthead === void 0 ? void 0 : masthead.getBoundingClientRect().height;
|
|
28
|
+
}
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
exports.getMastheadHeight = getMastheadHeight;
|
|
@@ -34,17 +36,28 @@ var useMastheadHeight = function useMastheadHeight() {
|
|
|
34
36
|
height = _useState2[0],
|
|
35
37
|
setHeight = _useState2[1];
|
|
36
38
|
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
var _useState3 = (0, _react.useState)(false),
|
|
40
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
41
|
+
mounted = _useState4[0],
|
|
42
|
+
setMounted = _useState4[1];
|
|
43
|
+
|
|
44
|
+
(0, _react.useEffect)(function () {
|
|
45
|
+
setMounted(true);
|
|
46
|
+
}, []);
|
|
47
|
+
(0, _react.useEffect)(function () {
|
|
48
|
+
if (mounted) {
|
|
49
|
+
var masthead = document.getElementById('masthead');
|
|
50
|
+
|
|
51
|
+
var handleHeightChange = function handleHeightChange(el) {
|
|
52
|
+
var newHeight = el.getBoundingClientRect().height;
|
|
53
|
+
setHeight(newHeight);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (masthead) {
|
|
57
|
+
(0, _util.resizeObserver)(masthead, handleHeightChange);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, [mounted]);
|
|
48
61
|
return {
|
|
49
62
|
height: height
|
|
50
63
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/ui",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.2",
|
|
4
4
|
"description": "UI component library for NDLA.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "6002d3517851d20c9b1c2ab5267d0c91ec74721b"
|
|
85
85
|
}
|
package/src/Masthead/utils.ts
CHANGED
|
@@ -6,26 +6,38 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { useState } from 'react';
|
|
9
|
+
import { useEffect, useState } from 'react';
|
|
10
10
|
import { resizeObserver } from '@ndla/util';
|
|
11
11
|
|
|
12
12
|
export const getMastheadHeight = (): number | undefined => {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
const masthead = document.getElementById('masthead');
|
|
15
|
+
return masthead?.getBoundingClientRect().height;
|
|
16
|
+
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export const useMastheadHeight = () => {
|
|
18
20
|
const [height, setHeight] = useState<number>();
|
|
19
|
-
const
|
|
21
|
+
const [mounted, setMounted] = useState(false);
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
setMounted(true);
|
|
25
|
+
}, []);
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (mounted) {
|
|
29
|
+
const masthead = document.getElementById('masthead');
|
|
30
|
+
|
|
31
|
+
const handleHeightChange = (el: HTMLElement) => {
|
|
32
|
+
const newHeight = el.getBoundingClientRect().height;
|
|
33
|
+
setHeight(newHeight);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (masthead) {
|
|
37
|
+
resizeObserver(masthead, handleHeightChange);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, [mounted]);
|
|
29
41
|
|
|
30
42
|
return {
|
|
31
43
|
height,
|