@colisweb/rescript-toolkit 1.28.3 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "1.28.3",
3
+ "version": "1.29.1",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build",
@@ -4,9 +4,6 @@ module type Config = {
4
4
  }
5
5
 
6
6
  module Make = (Config: Config) => {
7
- let trigger = (key: Config.Request.argument): unit =>
8
- Toolkit__Hooks.triggerFetcher(Config.key(key))
9
-
10
7
  let key: Config.Request.argument => array<string> = Config.key
11
8
 
12
9
  let use = (
@@ -11,7 +11,7 @@ module ErrorMessage = {
11
11
  @react.component
12
12
  let make = (~error=?, ~className="") =>
13
13
  error->Option.isSome
14
- ? <p className={cx([className, "text-danger-600 text-sm mt-1"])}>
14
+ ? <p className={cx([className, "text-danger-600 text-sm mt-1 form-error-feedback"])}>
15
15
  {error->Option.getExn->React.string}
16
16
  </p>
17
17
  : React.null
@@ -59,8 +59,6 @@ let useInitialPreviousDistinct = (~compare=(a, b) => a === b, value) => {
59
59
 
60
60
  type fetcher<'data> = ('data, bool, unit => Promise.t<result<bool, Js.Promise.error>>)
61
61
 
62
- let triggerFetcher = Swr.trigger
63
-
64
62
  let useFetcher = (~options: option<Swr.fetcherOptions>=?, key: 'key, fn: 'fn): fetcher<'data> => {
65
63
  let {data, isValidating, mutate} = Swr.useSwr(
66
64
  key,
@@ -7,6 +7,7 @@ module Spread = Toolkit__Ui_Spread
7
7
  module DatetimeInput = Toolkit__Ui_DatetimeInput
8
8
  module TextInput = Toolkit__Ui_TextInput
9
9
  module Tooltip = Toolkit__Ui_Tooltip
10
+ module TooltipV2 = Toolkit__Ui_TooltipV2
10
11
  module Switch = Toolkit__Ui_Switch
11
12
  module Radio = Toolkit__Ui_Radio
12
13
  module Checkbox = Toolkit__Ui_Checkbox
@@ -75,7 +75,7 @@ module Item = {
75
75
  "bg-white p-3 rounded shadow transition duration-500 ease-in-out mt-3 transform ",
76
76
  {
77
77
  open Css
78
- style(list{bottom(40->px)})
78
+ style(list{bottom(40->px), unsafe("pointer-events", "all")})
79
79
  },
80
80
  mounted ? "-translate-y-14" : "!opacity-0",
81
81
  isVisible ? "opacity-100" : "opacity-0 translate-x-[200px]",
@@ -127,7 +127,7 @@ module Provider = {
127
127
 
128
128
  <ReachUi.Portal>
129
129
  <div
130
- className="z-[2147483647] fixed right-0 top-0 transform translate-y-14 h-full p-4 flex flex-col items-end justify-end">
130
+ className="z-[2147483647] pointer-events-none fixed right-0 top-0 transform translate-y-14 h-full p-4 flex flex-col items-end justify-end">
131
131
  {list
132
132
  ->Array.map(e => {
133
133
  <Item key={e.id->Obj.magic} options=e />
@@ -0,0 +1,85 @@
1
+ type position = [
2
+ | #bottom
3
+ | #right
4
+ | #top
5
+ | #left
6
+ ]
7
+
8
+ @react.component
9
+ let make = (
10
+ ~label: React.element,
11
+ ~children,
12
+ ~tooltipClassName="",
13
+ ~containerClassName="",
14
+ ~position=#bottom,
15
+ ) => {
16
+ let ref = React.useRef(Js.Nullable.null)
17
+ let (position, setPosition) = React.useState(() => position)
18
+ let (children, isHover) = ReactUse.useHover(children)
19
+ let (adjustmentStyle, setAdjustmentStyle) = React.useState(() => None)
20
+
21
+ React.useEffect2(() => {
22
+ if isHover {
23
+ ref.current
24
+ ->Js.Nullable.toOption
25
+ ->Option.forEach(dom => {
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
+ }
40
+
41
+ switch position {
42
+ | #left if left < 0. => setPosition(_ => #right)
43
+ | #right if right < 0. => setPosition(_ => #left)
44
+ | #top if top < 0. => setPosition(_ => #bottom)
45
+ | _ => ()
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
+ ))
57
+ })
58
+ } else {
59
+ setAdjustmentStyle(_ => None)
60
+ }
61
+ None
62
+ }, (isHover, ref))
63
+
64
+ <div className={cx(["relative", containerClassName])}>
65
+ children
66
+ {isHover
67
+ ? <div
68
+ ref={ReactDOM.Ref.domRef(ref)}
69
+ className={cx([
70
+ "dropdown",
71
+ "absolute z-20 text-sm p-2 transform transition duration-150 ease-in-out shadow rounded font-normal bg-gray-800 text-white opacity-0",
72
+ switch position {
73
+ | #bottom => "left-1/2 top-full -translate-x-1/2 mt-2"
74
+ | #top => "left-1/2 bottom-full -translate-x-1/2 mb-2"
75
+ | #left => "right-full top-1/2 -translate-y-1/2 ml-2"
76
+ | #right => "left-full top-1/2 -translate-y-1/2 ml-2"
77
+ },
78
+ tooltipClassName,
79
+ ])}
80
+ style={adjustmentStyle->Option.getWithDefault(ReactDOM.Style.make())}>
81
+ label
82
+ </div>
83
+ : React.null}
84
+ </div>
85
+ }
@@ -45,3 +45,6 @@ module DomElement = {
45
45
  }
46
46
  @send external getBoundingClientRect: Dom.element => rect = "getBoundingClientRect"
47
47
  }
48
+
49
+ @val
50
+ external innerWidth: int = "window.innerWidth"
@@ -33,3 +33,5 @@ module DomElement: {
33
33
  }
34
34
  let getBoundingClientRect: Dom.element => rect
35
35
  }
36
+
37
+ let innerWidth: int
@@ -43,3 +43,6 @@ external usePreviousDistinct: (~compare: option<('a, 'b) => bool>=?, 'a, unit) =
43
43
 
44
44
  @module("react-use")
45
45
  external useGetSet: (unit => 'a) => ('a, 'a => 'a) = "useGetSet"
46
+
47
+ @module("react-use")
48
+ external useHover: React.element => (React.element, bool) = "useHover"
@@ -52,8 +52,6 @@ external useSwr: ('key, 'fn, 'fetcherOptions) => fetcher<'data> = "default"
52
52
  @module("swr")
53
53
  external useSwrOptional: ('key, 'fn, 'fetcherOptions) => fetcher<option<'data>> = "default"
54
54
 
55
- @module("swr") external trigger: 'key => unit = "trigger"
56
-
57
55
  type cache
58
56
  @module("swr") external cache: cache = "cache"
59
57
  @send external clear: cache => unit = "clear"