@thecb/components 7.7.8-beta.0 → 7.7.8-beta.10
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/index.cjs.js +81 -25
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +81 -25
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/highlight-tab-row/HighlightTabRow.js +1 -0
- package/src/components/molecules/module/Module.js +22 -13
- package/src/util/index.js +3 -1
- package/src/util/useCheckElementsInViewport.js +33 -27
- package/src/util/useGetViewportOnResize.js +47 -0
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React, { Fragment, memo } from "react";
|
|
2
2
|
import { themeComponent } from "../../../util/themeUtils";
|
|
3
3
|
import { fallbackValues } from "./Module.theme";
|
|
4
|
-
import Heading from "../../atoms/heading";
|
|
5
4
|
import Title from "../../atoms/title";
|
|
6
|
-
import { Box } from "../../atoms/layouts";
|
|
5
|
+
import { Box, Cluster } from "../../atoms/layouts";
|
|
7
6
|
|
|
8
7
|
/*
|
|
9
8
|
New (01/22) - updated <Module /> to use <Title /> atom
|
|
@@ -25,6 +24,8 @@ const Module = ({
|
|
|
25
24
|
variant = "default",
|
|
26
25
|
fontSize,
|
|
27
26
|
as,
|
|
27
|
+
titleID = "",
|
|
28
|
+
rightTitleContent,
|
|
28
29
|
children
|
|
29
30
|
}) => {
|
|
30
31
|
const themedFontSize =
|
|
@@ -37,20 +38,28 @@ const Module = ({
|
|
|
37
38
|
const themedElemType =
|
|
38
39
|
variant === "small" ? "h6" : variant === "default" ? "h5" : "h2";
|
|
39
40
|
const computedElemType = as || themedElemType;
|
|
41
|
+
const headingText = (
|
|
42
|
+
<Title
|
|
43
|
+
weight={themeValues.fontWeight}
|
|
44
|
+
color={themeValues.fontColor}
|
|
45
|
+
margin={`${spacing} 0 ${themeValues.titleSpacing} 0`}
|
|
46
|
+
textAlign={themeValues.textAlign}
|
|
47
|
+
as={computedElemType}
|
|
48
|
+
extraStyles={`font-size: ${computedFontSize};`}
|
|
49
|
+
id={titleID}
|
|
50
|
+
>
|
|
51
|
+
{heading}
|
|
52
|
+
</Title>
|
|
53
|
+
);
|
|
40
54
|
|
|
41
55
|
return (
|
|
42
56
|
<Fragment>
|
|
43
|
-
{heading &&
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
as={computedElemType}
|
|
50
|
-
extraStyles={`font-size: ${computedFontSize};`}
|
|
51
|
-
>
|
|
52
|
-
{heading}
|
|
53
|
-
</Title>
|
|
57
|
+
{heading && !rightTitleContent && headingText}
|
|
58
|
+
{heading && rightTitleContent && (
|
|
59
|
+
<Cluster justify="space-between" align="center" nowrap>
|
|
60
|
+
{headingText}
|
|
61
|
+
{rightTitleContent}
|
|
62
|
+
</Cluster>
|
|
54
63
|
)}
|
|
55
64
|
<Box padding={`0 0 ${spacingBottom}`}>
|
|
56
65
|
<Box
|
package/src/util/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as theme from "./themeUtils";
|
|
|
4
4
|
import useFocusInvalidInput from "./focusFirstInvalidInputHook";
|
|
5
5
|
import useOutsideClick from "./useOutsideClick";
|
|
6
6
|
import useCheckElementsInViewport from "./useCheckElementsInViewport";
|
|
7
|
+
import useGetViewportOnResize from "./useGetViewportOnResize";
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
10
|
formats,
|
|
@@ -11,5 +12,6 @@ export {
|
|
|
11
12
|
theme,
|
|
12
13
|
useFocusInvalidInput,
|
|
13
14
|
useOutsideClick,
|
|
14
|
-
useCheckElementsInViewport
|
|
15
|
+
useCheckElementsInViewport,
|
|
16
|
+
useGetViewportOnResize
|
|
15
17
|
};
|
|
@@ -1,49 +1,55 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
1
|
+
import { useEffect, useLayoutEffect, useState } from "react";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
Hook that determines whether every element in an array of DOM selectors is fully present
|
|
5
5
|
within the user's current viewport.
|
|
6
6
|
|
|
7
|
-
(elements: Array<String
|
|
7
|
+
(elements: Array<String>, Number, Number) => Boolean;
|
|
8
|
+
(["#submit-button", "#.module-small", "h2.alert-title"], 1024, 768) => true;
|
|
8
9
|
|
|
9
10
|
Takes an array of strings that correspond to DOM selectors. Examples:
|
|
10
11
|
"#submit-button", ".module-small", "h2.alert-title"
|
|
11
12
|
|
|
13
|
+
Also takes numbers that represent the current viewport width and height.
|
|
14
|
+
You can either calculate these once in your application before running this hook
|
|
15
|
+
(so that they only update when the component running the hook re-renders), or you can
|
|
16
|
+
use the useGetViewportOnResize hook to calculate them when the browser window is resized
|
|
17
|
+
|
|
12
18
|
The document query function will return the *first* element in the document that matches
|
|
13
19
|
the string given.
|
|
14
20
|
|
|
15
|
-
A combination string of multiple selectors can also be provided, e.g.:
|
|
16
|
-
".alert-info, .alert-warning, .alert-error"
|
|
21
|
+
A combination string of multiple selectors can also be provided as an item in the array, e.g.:
|
|
22
|
+
".alert-info, .alert-warning, .alert-error". This will return the first element that matches *any* of the provided selectors.
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
If the element is present in the DOM (domEL !== null), the function examines the element's bounding box
|
|
25
|
+
to determine if the element is within the viewport. If any portion of the element is outside of
|
|
26
|
+
the viewport, the function returns false.
|
|
19
27
|
|
|
20
|
-
If
|
|
28
|
+
If all elements that exist are within the viewport, the function returns true.
|
|
21
29
|
*/
|
|
22
30
|
|
|
23
|
-
const useCheckElementsInViewport = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const useCheckElementsInViewport = (
|
|
32
|
+
elements = [],
|
|
33
|
+
viewportWidth,
|
|
34
|
+
viewportHeight
|
|
35
|
+
) => {
|
|
36
|
+
for (let i = 0; i < elements.length; i++) {
|
|
37
|
+
const domEl = document.querySelector(elements[i]);
|
|
38
|
+
const boundingBox = domEl?.getBoundingClientRect();
|
|
39
|
+
timesRun++;
|
|
40
|
+
|
|
41
|
+
if (domEl !== null) {
|
|
35
42
|
if (
|
|
36
|
-
boundingBox.top
|
|
37
|
-
boundingBox.left
|
|
38
|
-
boundingBox.right
|
|
39
|
-
boundingBox.bottom
|
|
43
|
+
boundingBox.top < 0 ||
|
|
44
|
+
boundingBox.left < 0 ||
|
|
45
|
+
boundingBox.right > viewportWidth ||
|
|
46
|
+
boundingBox.bottom > viewportHeight
|
|
40
47
|
) {
|
|
41
|
-
|
|
48
|
+
return false;
|
|
42
49
|
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return elementsVisible;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
47
53
|
};
|
|
48
54
|
|
|
49
55
|
export default useCheckElementsInViewport;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Hook that adds a resize listener to the window and updates viewport size via
|
|
5
|
+
a provided handler function
|
|
6
|
+
|
|
7
|
+
(Object: {width: Number, height: Number}, Function) => undefined;
|
|
8
|
+
|
|
9
|
+
Provide the current value of the user's viewport and a handler function to receive updated values
|
|
10
|
+
|
|
11
|
+
Best used in combination with a useState hook in your component to receive updated values
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const useGetViewportOnResize = (viewport, updateViewport) => {
|
|
15
|
+
let timeoutID = false;
|
|
16
|
+
let delay = 250;
|
|
17
|
+
|
|
18
|
+
const updateViewportValues = () => {
|
|
19
|
+
clearTimeout(timeoutID);
|
|
20
|
+
|
|
21
|
+
timeoutID = setTimeout(() => {
|
|
22
|
+
let newWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
23
|
+
let newHeight =
|
|
24
|
+
window.innerHeight || document.documentElement.clientHeight;
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
(viewport?.width && viewport?.width !== newWidth) ||
|
|
28
|
+
(viewport?.height && viewport?.height !== newHeight)
|
|
29
|
+
) {
|
|
30
|
+
updateViewport({
|
|
31
|
+
width: newWidth,
|
|
32
|
+
height: newHeight
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}, delay);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
window.addEventListener("resize", updateViewportValues);
|
|
40
|
+
|
|
41
|
+
return () => {
|
|
42
|
+
clearTimeout(timeoutID);
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default useGetViewportOnResize;
|