@colisweb/rescript-toolkit 2.36.3 → 2.38.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": "@colisweb/rescript-toolkit",
3
- "version": "2.36.3",
3
+ "version": "2.38.1",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build",
@@ -240,3 +240,31 @@ let useOnClickOutside = (ref: React.ref<Js.Nullable.t<Dom.element>>, handler) =>
240
240
  )
241
241
  }, (ref, handler))
242
242
  }
243
+
244
+ let useIntersection = ReactUse.useIntersection
245
+
246
+ let useIsVisibleOnViewport = (~options: option<ReactUse.intersectionOptions<'a>>=?, domRef) => {
247
+ let (isVisible, setIsVisible) = React.useState(() => false)
248
+ let intersection = useIntersection(
249
+ domRef,
250
+ options->Option.getWithDefault({
251
+ root: Js.Nullable.null,
252
+ rootMargin: "0px",
253
+ threshold: 1.,
254
+ }),
255
+ )
256
+
257
+ React.useEffect1(() => {
258
+ intersection
259
+ ->Js.Nullable.toOption
260
+ ->Option.forEach(intersection => {
261
+ if intersection.intersectionRatio >= 1. {
262
+ setIsVisible(_ => true)
263
+ }
264
+ })
265
+
266
+ None
267
+ }, [intersection])
268
+
269
+ isVisible
270
+ }
@@ -2,49 +2,45 @@ open BsSentryReactNative
2
2
 
3
3
  @val external isDev: bool = "__DEV__"
4
4
 
5
- let debugStyle = "background-color: #208E9C; color: white; padding: 5px; font-size: 10px;"
6
- let warningStyle = "background-color: #FFAD2D; color: white; padding: 5px; font-size: 10px;"
7
- let errorStyle = "background-color: #FF4714; color: white; padding: 5px; font-size: 10px;"
8
-
9
5
  let debug = str => {
10
6
  if isDev {
11
- Js.Console.log3("%cDEBUG", debugStyle, str)
7
+ Js.Console.log2("DEBUG", str)
12
8
  }
13
9
  }
14
10
 
15
11
  let debug2 = (str, str2) => {
16
12
  if isDev {
17
- Js.Console.log4("%cDEBUG", debugStyle, str, str2)
13
+ Js.Console.log3("DEBUG", str, str2)
18
14
  }
19
15
  }
20
16
 
21
17
  let debugMany = (arr: array<string>) => {
22
18
  if isDev {
23
- Js.Console.logMany(["%cDEBUG", debugStyle]->Array.concat(arr))
19
+ Js.Console.logMany(["DEBUG"]->Array.concat(arr))
24
20
  }
25
21
  }
26
22
 
27
23
  let warning = str => {
28
24
  if isDev {
29
- Js.Console.log3("%cWARN", warningStyle, str)
25
+ Js.Console.log2("WARN", str)
30
26
  }
31
27
  }
32
28
 
33
29
  let warning2 = (str, str2) => {
34
30
  if isDev {
35
- Js.Console.log4("%cWARN", warningStyle, str, str2)
31
+ Js.Console.log3("WARN", str, str2)
36
32
  }
37
33
  }
38
34
 
39
35
  let warningMany = (arr: array<string>) => {
40
36
  if isDev {
41
- Js.Console.logMany(["%cWARN", warningStyle]->Array.concat(arr))
37
+ Js.Console.logMany(["WARN"]->Array.concat(arr))
42
38
  }
43
39
  }
44
40
 
45
41
  let error = str => {
46
42
  if isDev {
47
- Js.Console.log3("%cERROR", errorStyle, str)
43
+ Js.Console.log2("ERROR", str)
48
44
  } else {
49
45
  open Sentry
50
46
  withScope(_scope => {
@@ -55,7 +51,7 @@ let error = str => {
55
51
 
56
52
  let error2 = (str, str2) => {
57
53
  if isDev {
58
- Js.Console.log4("%cERROR", errorStyle, str, str2)
54
+ Js.Console.log3("ERROR", str, str2)
59
55
  } else {
60
56
  open Sentry
61
57
  withScope(scope => {
@@ -69,7 +65,7 @@ let errorMany = (arr: array<string>) => {
69
65
  let message = arr[0]
70
66
  let data = arr->Array.length > 1 ? arr->Array.sliceToEnd(1) : []
71
67
  if isDev {
72
- Js.Console.logMany(["%cERROR", errorStyle]->Array.concat(arr))
68
+ Js.Console.logMany(["ERROR"]->Array.concat(arr))
73
69
  } else {
74
70
  open Sentry
75
71
  withScope(scope => {
@@ -46,3 +46,17 @@ external useGetSet: (unit => 'a) => ('a, 'a => 'a) = "useGetSet"
46
46
 
47
47
  @module("react-use")
48
48
  external useHover: React.element => (React.element, bool) = "useHover"
49
+
50
+ type intersectionObserver = {intersectionRatio: float}
51
+
52
+ type intersectionOptions<'domElement> = {
53
+ root: Js.Nullable.t<'domElement>,
54
+ rootMargin: string,
55
+ threshold: float,
56
+ }
57
+
58
+ @module("react-use")
59
+ external useIntersection: (
60
+ React.ref<'a>,
61
+ intersectionOptions<'domElement>,
62
+ ) => Js.Nullable.t<intersectionObserver> = "useIntersection"