@colisweb/rescript-toolkit 2.51.0 → 2.51.2

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.51.0",
3
+ "version": "2.51.2",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build -with-deps",
@@ -13,6 +13,7 @@ let make = (
13
13
  ~buttonClassName="",
14
14
  ~containerClassName="",
15
15
  ~defaultIsOpen=false,
16
+ ~onButtonClick=?,
16
17
  ~buttonColor: Toolkit__Ui_Button.color=#white,
17
18
  ~buttonSize: Toolkit__Ui_Button.size=#md,
18
19
  ~buttonVariant: Toolkit__Ui_Button.variant=#default,
@@ -44,6 +45,7 @@ let make = (
44
45
  color=buttonColor
45
46
  buttonRef={ReactDOM.Ref.domRef(buttonRef)}
46
47
  onClick={event => {
48
+ onButtonClick->Option.forEach(fn => fn())
47
49
  isOpen ? hide() : toggle()
48
50
  }}
49
51
  className={cx([buttonClassName, "dropdown-button"])}>
@@ -64,24 +66,21 @@ let make = (
64
66
  let {left, top, width, height} =
65
67
  buttonRef->Browser.DomElement.getBoundingClientRect
66
68
  let dropdown = ref->Browser.DomElement.getBoundingClientRect
67
-
68
69
  let left = left +. width /. 2. -. dropdown.width /. 2.
69
70
 
70
- let left = switch left {
71
- | left if left < 0. => "0px"
71
+ let adjustmentStyle = ReactDOM.Style.make(
72
+ ~top=`${(top +. height)->Js.Float.toString}px`,
73
+ ~opacity="1",
74
+ )
75
+
76
+ let adjustmentStyle = switch left {
77
+ | left if left < 0. => adjustmentStyle(~left="8px", ())
72
78
  | left if left +. dropdown.width > Browser.innerWidth->Int.toFloat =>
73
- `${(Browser.innerWidth->Int.toFloat -. dropdown.width)->Js.Float.toString}px`
74
- | left => `${left->Js.Float.toString}px`
79
+ adjustmentStyle(~right="8px", ())
80
+ | left => adjustmentStyle(~left=`${left->Js.Float.toString}px`, ())
75
81
  }
76
82
 
77
- setAdjustmentStyle(_ => Some(
78
- ReactDOM.Style.make(
79
- ~left,
80
- ~top=`${(top +. height)->Js.Float.toString}px`,
81
- ~opacity="1",
82
- (),
83
- ),
84
- ))
83
+ setAdjustmentStyle(_ => Some(adjustmentStyle))
85
84
  }
86
85
 
87
86
  | _ => ()