@thecb/components 7.7.7 → 7.7.8-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "7.7.7",
3
+ "version": "7.7.8-beta.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
package/src/.DS_Store ADDED
Binary file
Binary file
@@ -67,6 +67,7 @@ const HighlightTabRow = ({
67
67
  color={themeValues.textColor}
68
68
  weight={FONT_WEIGHT_SEMIBOLD}
69
69
  extraStyles="display: block; white-space: nowrap;"
70
+ id={`${t}-tab-text`}
70
71
  >
71
72
  {t}
72
73
  </Text>
package/src/util/index.js CHANGED
@@ -3,5 +3,13 @@ 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";
6
7
 
7
- export { formats, general, theme, useFocusInvalidInput, useOutsideClick };
8
+ export {
9
+ formats,
10
+ general,
11
+ theme,
12
+ useFocusInvalidInput,
13
+ useOutsideClick,
14
+ useCheckElementsInViewport
15
+ };
@@ -0,0 +1,49 @@
1
+ import { useEffect, 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, e.g.:
16
+ ".alert-info, .alert-warning, .alert-error"
17
+
18
+ This will return the first element that matches *any* of the provided selectors
19
+
20
+ If every element in the array is fully within the viewport, function returns true
21
+ */
22
+
23
+ const useCheckElementsInViewport = (elements = []) => {
24
+ const [elementsVisible, setElementsVisible] = useState(false);
25
+ const viewportWidth =
26
+ window.innerWidth || document.documentElement.clientWidth;
27
+ const viewportHeight =
28
+ window.innerHeight || document.documentElement.clientHeight;
29
+
30
+ useEffect(() => {
31
+ elements.forEach(element => {
32
+ const domEl = document.querySelector(element);
33
+ const boundingBox = domEl.getBoundingClientRect();
34
+
35
+ if (
36
+ boundingBox.top >= 0 &&
37
+ boundingBox.left >= 0 &&
38
+ boundingBox.right <= viewportWidth &&
39
+ boundingBox.bottom <= viewportHeight
40
+ ) {
41
+ setElementsVisible(true);
42
+ }
43
+ });
44
+ }, [elements]);
45
+
46
+ return elementsVisible;
47
+ };
48
+
49
+ export default useCheckElementsInViewport;