@thecb/components 7.7.8-beta.9 → 7.8.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.
- package/dist/index.cjs.js +59 -84
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +59 -85
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/image-box/ImageBox.js +40 -0
- package/src/components/atoms/image-box/ImageBox.styled.js +8 -0
- package/src/components/atoms/image-box/index.js +3 -0
- package/src/components/atoms/index.js +1 -0
- package/src/components/molecules/highlight-tab-row/HighlightTabRow.js +0 -1
- package/src/components/molecules/module/Module.js +13 -22
- package/src/util/index.js +1 -9
- package/src/util/useCheckElementsInViewport.js +0 -78
package/package.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Box } from "../layouts";
|
|
3
|
+
import { Image } from "./ImageBox.styled";
|
|
4
|
+
|
|
5
|
+
const ImageBox = ({
|
|
6
|
+
image,
|
|
7
|
+
minHeight,
|
|
8
|
+
minWidth,
|
|
9
|
+
maxWidth,
|
|
10
|
+
borderRadius,
|
|
11
|
+
imgWidth,
|
|
12
|
+
imgHeight,
|
|
13
|
+
objectFit,
|
|
14
|
+
objectPosition
|
|
15
|
+
}) => {
|
|
16
|
+
const boxMaxWidth = maxWidth || minWidth;
|
|
17
|
+
const { url = "", altText = "" } = image;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Box
|
|
21
|
+
padding="0"
|
|
22
|
+
minWidth={minWidth}
|
|
23
|
+
minHeight={minHeight}
|
|
24
|
+
maxWidth={boxMaxWidth}
|
|
25
|
+
borderRadius={borderRadius}
|
|
26
|
+
extraStyles={`height: ${minHeight};`}
|
|
27
|
+
>
|
|
28
|
+
<Image
|
|
29
|
+
width={imgWidth}
|
|
30
|
+
height={imgHeight}
|
|
31
|
+
objectFit={objectFit}
|
|
32
|
+
objectPosition={objectPosition}
|
|
33
|
+
src={url}
|
|
34
|
+
alt={altText}
|
|
35
|
+
/>
|
|
36
|
+
</Box>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default ImageBox;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
|
|
3
|
+
export const Image = styled.img`
|
|
4
|
+
width: ${({ width = "100%" }) => width};
|
|
5
|
+
height: ${({ height = "100%" }) => height};
|
|
6
|
+
object-fit: ${({ objectFit = "cover" }) => objectFit};
|
|
7
|
+
object-position: ${({ objectPosition = "center" }) => objectPosition};
|
|
8
|
+
`;
|
|
@@ -21,6 +21,7 @@ export { default as FormattedCreditCard } from "./formatted-credit-card";
|
|
|
21
21
|
export { default as HamburgerButton } from "./hamburger-button";
|
|
22
22
|
export { default as Heading } from "./heading";
|
|
23
23
|
export * from "./icons";
|
|
24
|
+
export { default as ImageBox } from "./image-box";
|
|
24
25
|
export { default as Jumbo } from "./jumbo";
|
|
25
26
|
export { default as LabeledAmount } from "./labeled-amount";
|
|
26
27
|
export * from "./layouts";
|
|
@@ -1,8 +1,9 @@
|
|
|
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";
|
|
4
5
|
import Title from "../../atoms/title";
|
|
5
|
-
import { Box
|
|
6
|
+
import { Box } from "../../atoms/layouts";
|
|
6
7
|
|
|
7
8
|
/*
|
|
8
9
|
New (01/22) - updated <Module /> to use <Title /> atom
|
|
@@ -24,8 +25,6 @@ const Module = ({
|
|
|
24
25
|
variant = "default",
|
|
25
26
|
fontSize,
|
|
26
27
|
as,
|
|
27
|
-
titleID = "",
|
|
28
|
-
rightTitleContent,
|
|
29
28
|
children
|
|
30
29
|
}) => {
|
|
31
30
|
const themedFontSize =
|
|
@@ -38,28 +37,20 @@ const Module = ({
|
|
|
38
37
|
const themedElemType =
|
|
39
38
|
variant === "small" ? "h6" : variant === "default" ? "h5" : "h2";
|
|
40
39
|
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
|
-
);
|
|
54
40
|
|
|
55
41
|
return (
|
|
56
42
|
<Fragment>
|
|
57
|
-
{heading &&
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
{
|
|
62
|
-
|
|
43
|
+
{heading && (
|
|
44
|
+
<Title
|
|
45
|
+
weight={themeValues.fontWeight}
|
|
46
|
+
color={themeValues.fontColor}
|
|
47
|
+
margin={`${spacing} 0 ${themeValues.titleSpacing} 0`}
|
|
48
|
+
textAlign={themeValues.textAlign}
|
|
49
|
+
as={computedElemType}
|
|
50
|
+
extraStyles={`font-size: ${computedFontSize};`}
|
|
51
|
+
>
|
|
52
|
+
{heading}
|
|
53
|
+
</Title>
|
|
63
54
|
)}
|
|
64
55
|
<Box padding={`0 0 ${spacingBottom}`}>
|
|
65
56
|
<Box
|
package/src/util/index.js
CHANGED
|
@@ -3,13 +3,5 @@ import * as general from "./general";
|
|
|
3
3
|
import * as theme from "./themeUtils";
|
|
4
4
|
import useFocusInvalidInput from "./focusFirstInvalidInputHook";
|
|
5
5
|
import useOutsideClick from "./useOutsideClick";
|
|
6
|
-
import useCheckElementsInViewport from "./useCheckElementsInViewport";
|
|
7
6
|
|
|
8
|
-
export {
|
|
9
|
-
formats,
|
|
10
|
-
general,
|
|
11
|
-
theme,
|
|
12
|
-
useFocusInvalidInput,
|
|
13
|
-
useOutsideClick,
|
|
14
|
-
useCheckElementsInViewport
|
|
15
|
-
};
|
|
7
|
+
export { formats, general, theme, useFocusInvalidInput, useOutsideClick };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
Hook that determines whether every element in an array of DOM selectors is fully present
|
|
5
|
-
within the user's current viewport.
|
|
6
|
-
|
|
7
|
-
(elements: Array<String>) => Boolean;
|
|
8
|
-
|
|
9
|
-
Takes an array of strings that correspond to DOM selectors. Examples:
|
|
10
|
-
"#submit-button", ".module-small", "h2.alert-title"
|
|
11
|
-
|
|
12
|
-
The document query function will return the *first* element in the document that matches
|
|
13
|
-
the string given.
|
|
14
|
-
|
|
15
|
-
A combination string of multiple selectors can also be provided as an item in the array, e.g.:
|
|
16
|
-
".alert-info, .alert-warning, .alert-error". This will return the first element that matches *any* of the provided selectors.
|
|
17
|
-
|
|
18
|
-
If the element is present in the DOM (domEL !== null), the function examines the element's bounding box
|
|
19
|
-
to determine if the element is within the viewport. If any portion of the element is outside of
|
|
20
|
-
the viewport, the function returns false.
|
|
21
|
-
|
|
22
|
-
If all elements that exist are within the viewport, the function returns true.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const useCheckElementsInViewport = (elements = []) => {
|
|
26
|
-
let elementsVisible = true;
|
|
27
|
-
let timeoutID = false;
|
|
28
|
-
let delay = 250;
|
|
29
|
-
const [viewportWidth, setViewportWidth] = useState(
|
|
30
|
-
window.innerWidth || document.documentElement.clientWidth
|
|
31
|
-
);
|
|
32
|
-
const [viewportHeight, setViewportHeight] = useState(
|
|
33
|
-
window.innerHeight || document.documentElement.clientHeight
|
|
34
|
-
);
|
|
35
|
-
const updateViewportValues = () => {
|
|
36
|
-
clearTimeout(timeoutID);
|
|
37
|
-
|
|
38
|
-
timeoutID = setTimeout(() => {
|
|
39
|
-
setViewportWidth(
|
|
40
|
-
window.innerWidth || document.documentElement.clientWidth
|
|
41
|
-
);
|
|
42
|
-
setViewportHeight(
|
|
43
|
-
window.innerHeight || document.documentElement.clientHeight
|
|
44
|
-
);
|
|
45
|
-
}, delay);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
window.addEventListener("resize", updateViewportValues);
|
|
50
|
-
|
|
51
|
-
return () => {
|
|
52
|
-
clearTimeout(timeoutID);
|
|
53
|
-
};
|
|
54
|
-
}, []);
|
|
55
|
-
|
|
56
|
-
useLayoutEffect(() => {
|
|
57
|
-
elements.forEach(element => {
|
|
58
|
-
const domEl = document.querySelector(element);
|
|
59
|
-
const boundingBox = domEl?.getBoundingClientRect();
|
|
60
|
-
|
|
61
|
-
// Skip any elements not in the DOM
|
|
62
|
-
if (domEl !== null) {
|
|
63
|
-
if (
|
|
64
|
-
boundingBox.top < 0 ||
|
|
65
|
-
boundingBox.left < 0 ||
|
|
66
|
-
boundingBox.right > viewportWidth ||
|
|
67
|
-
boundingBox.bottom > viewportHeight
|
|
68
|
-
) {
|
|
69
|
-
elementsVisible = false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}, [elements, viewportWidth, viewportHeight]);
|
|
74
|
-
|
|
75
|
-
return elementsVisible;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default useCheckElementsInViewport;
|