@truedat/core 4.40.3 → 4.40.7

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": "@truedat/core",
3
- "version": "4.40.3",
3
+ "version": "4.40.7",
4
4
  "description": "Truedat Web Core",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -32,7 +32,7 @@
32
32
  "@babel/plugin-transform-modules-commonjs": "^7.15.0",
33
33
  "@babel/preset-env": "^7.15.0",
34
34
  "@babel/preset-react": "^7.14.5",
35
- "@truedat/test": "4.40.3",
35
+ "@truedat/test": "4.40.5",
36
36
  "babel-jest": "^27.0.6",
37
37
  "babel-plugin-dynamic-import-node": "^2.3.3",
38
38
  "babel-plugin-lodash": "^3.3.4",
@@ -106,5 +106,5 @@
106
106
  "react-dom": ">= 16.8.6 < 17",
107
107
  "semantic-ui-react": ">= 0.88.2 < 2.1"
108
108
  },
109
- "gitHead": "03104a28941b568007ad53b85874ff58225eaa6a"
109
+ "gitHead": "57ce60d30f6238ab63207ae402dfc0bc0e5c934a"
110
110
  }
@@ -2,3 +2,4 @@ export * from "./useActiveRoute";
2
2
  export * from "./useActiveRoutes";
3
3
  export * from "./useAuthorized";
4
4
  export * from "./usePath";
5
+ export * from "./useOnScreen";
@@ -0,0 +1,16 @@
1
+ import { useState, useEffect } from "react";
2
+ import { useWindowSize } from "./useWindowSize";
3
+
4
+ export const useIsOverflow = (ref) => {
5
+ const [isOverflow, setIsOverflow] = useState(undefined);
6
+ const size = useWindowSize();
7
+
8
+ useEffect(() => {
9
+ const { current } = ref;
10
+ if (current) {
11
+ setIsOverflow(current.scrollWidth > current.clientWidth);
12
+ }
13
+ }, [ref, size]);
14
+
15
+ return isOverflow;
16
+ };
@@ -0,0 +1,26 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ export const useOnScreen = (ref, rootMargin = "0px") => {
4
+ const [isVisible, setIsVisible] = useState(false);
5
+
6
+ useEffect(() => {
7
+ const observer = new IntersectionObserver(
8
+ ([entry]) => {
9
+ setIsVisible(entry.isIntersecting);
10
+ },
11
+ { rootMargin }
12
+ );
13
+
14
+ const currentElement = ref?.current;
15
+
16
+ if (currentElement) {
17
+ observer.observe(currentElement);
18
+ }
19
+
20
+ return () => observer.unobserve(currentElement);
21
+ }, []);
22
+
23
+ return isVisible;
24
+ };
25
+
26
+ export default useOnScreen;
@@ -0,0 +1,23 @@
1
+ import _ from "lodash/fp";
2
+ import { useState, useEffect } from "react";
3
+
4
+ export const useWindowSize = (delay = 600) => {
5
+ const [size, setSize] = useState();
6
+
7
+ useEffect(() => {
8
+ const handleResize = () => {
9
+ setSize({
10
+ width: window.innerWidth,
11
+ height: window.innerHeight,
12
+ });
13
+ };
14
+
15
+ const debouncedHandleResize = _.debounce(delay)(handleResize);
16
+ window.addEventListener("resize", debouncedHandleResize);
17
+ return () => {
18
+ window.removeEventListener("resize", debouncedHandleResize);
19
+ };
20
+ }, [delay]);
21
+
22
+ return size;
23
+ };