@colisweb/rescript-toolkit 1.29.0 → 1.29.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
|
@@ -23,21 +23,37 @@ let make = (
|
|
|
23
23
|
ref.current
|
|
24
24
|
->Js.Nullable.toOption
|
|
25
25
|
->Option.forEach(dom => {
|
|
26
|
-
let {left, right} = dom->Browser.DomElement.getBoundingClientRect
|
|
26
|
+
let {left, width, right, top} = dom->Browser.DomElement.getBoundingClientRect
|
|
27
|
+
|
|
28
|
+
let overflowFromRight = left +. width > Browser.innerWidth->Float.fromInt
|
|
29
|
+
let overflowFromLeft = left <= 0.
|
|
30
|
+
|
|
31
|
+
let overflowCorrection = {
|
|
32
|
+
if overflowFromRight {
|
|
33
|
+
Some(-.(width -. (Browser.innerWidth->Int.toFloat -. left)))
|
|
34
|
+
} else if overflowFromLeft {
|
|
35
|
+
Some(-.left)
|
|
36
|
+
} else {
|
|
37
|
+
None
|
|
38
|
+
}
|
|
39
|
+
}
|
|
27
40
|
|
|
28
41
|
switch position {
|
|
29
42
|
| #left if left < 0. => setPosition(_ => #right)
|
|
30
43
|
| #right if right < 0. => setPosition(_ => #left)
|
|
31
|
-
| _ =>
|
|
32
|
-
|
|
33
|
-
ReactDOM.Style.make(
|
|
34
|
-
~marginLeft=left < 0. ? `${-.left->Js.Float.toString}px` : "",
|
|
35
|
-
~marginRight=right < 0. ? `${-.right->Js.Float.toString}px` : "",
|
|
36
|
-
~opacity="1",
|
|
37
|
-
(),
|
|
38
|
-
),
|
|
39
|
-
))
|
|
44
|
+
| #top if top < 0. => setPosition(_ => #bottom)
|
|
45
|
+
| _ => ()
|
|
40
46
|
}
|
|
47
|
+
|
|
48
|
+
setAdjustmentStyle(_ => Some(
|
|
49
|
+
ReactDOM.Style.make(
|
|
50
|
+
~marginLeft=overflowCorrection->Option.mapWithDefault("", correction =>
|
|
51
|
+
`${correction->Js.Float.toString}px`
|
|
52
|
+
),
|
|
53
|
+
~opacity="1",
|
|
54
|
+
(),
|
|
55
|
+
),
|
|
56
|
+
))
|
|
41
57
|
})
|
|
42
58
|
} else {
|
|
43
59
|
setAdjustmentStyle(_ => None)
|
package/src/vendors/Browser.res
CHANGED