@colisweb/rescript-toolkit 4.15.0 → 4.15.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": "4.15.0",
3
+ "version": "4.15.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -82,9 +82,10 @@ let make = (
82
82
  onClick={event => {
83
83
  switch dropDownRef.current->Js.Nullable.toOption {
84
84
  | None => toggle()
85
- | Some(_dropDownRef) => {
86
- let isButton = ReactEvent.Mouse.target(event)["tagName"] === "BUTTON"
87
- if isButton {
85
+ | Some(dropDownRef) => {
86
+ let clickedElement = event->ReactEvent.Mouse.target->Browser.DomElement.toDomElement
87
+
88
+ if !(dropDownRef->Browser.DomElement.Node.contains(clickedElement)) {
88
89
  toggle()
89
90
  }
90
91
  }
@@ -101,6 +101,7 @@ let make = (
101
101
  ~disabled: option<bool>=?,
102
102
  ~onCancel: option<unit => unit>=?,
103
103
  ~validateMessage: option<React.element>=?,
104
+ ~showCarret=true,
104
105
  ) => {
105
106
  let (selectedOption, setSelectedOption) = React.useState(() => defaultValue)
106
107
  let previousDefaultValue = Toolkit__Hooks.usePrevious(defaultValue)
@@ -130,18 +131,22 @@ let make = (
130
131
  | None =>
131
132
  <p className="flex flex-row gap-2 w-full items-center relative">
132
133
  <span> {placeholder} </span>
133
- <span className="absolute inset-y-0 right-0 flex items-center">
134
- <ReactIcons.FaAngleDown />
135
- </span>
134
+ {showCarret
135
+ ? <span className="absolute inset-y-0 right-0 flex items-center">
136
+ <ReactIcons.FaAngleDown />
137
+ </span>
138
+ : React.null}
136
139
  </p>
137
140
  | Some(selectedOption) =>
138
141
  <div className="table table-fixed w-full" title={selectedOption.label}>
139
142
  <span className="table-cell truncate text-left w-full">
140
143
  {selectedOption.itemLabel->Option.getWithDefault(selectedOption.label->React.string)}
141
144
  </span>
142
- <span className="absolute inset-y-0 right-2 flex items-center">
143
- <ReactIcons.FaAngleDown />
144
- </span>
145
+ {showCarret
146
+ ? <span className="absolute inset-y-0 right-2 flex items-center">
147
+ <ReactIcons.FaAngleDown />
148
+ </span>
149
+ : React.null}
145
150
  </div>
146
151
  }}>
147
152
  <div className="py-2 pl-2 pr-1 max-h-[300px] overflow-y-scroll">
@@ -20,4 +20,5 @@ let make: (
20
20
  ~disabled: bool=?,
21
21
  ~onCancel: unit => unit=?,
22
22
  ~validateMessage: React.element=?,
23
+ ~showCarret: bool=?,
23
24
  ) => React.element
@@ -48,6 +48,18 @@ module DomElement = {
48
48
  @send external getBoundingClientRect: Dom.element => rect = "getBoundingClientRect"
49
49
 
50
50
  @send external focus: Dom.element => unit = "focus"
51
+
52
+ external toDomElement: 'a => Dom.element = "%identity"
53
+
54
+ module ClassList = {
55
+ @send @scope("classList")
56
+ external contains: (Dom.element, string) => bool = "contains"
57
+ }
58
+
59
+ module Node = {
60
+ @send
61
+ external contains: (Dom.element, Dom.element) => bool = "contains"
62
+ }
51
63
  }
52
64
 
53
65
  @val
@@ -34,6 +34,17 @@ module DomElement: {
34
34
  }
35
35
  let getBoundingClientRect: Dom.element => rect
36
36
  let focus: Dom.element => unit
37
+
38
+ external toDomElement: 'a => Dom.element = "%identity"
39
+
40
+ module ClassList: {
41
+ @send @scope("classList")
42
+ external contains: (Dom.element, string) => bool = "contains"
43
+ }
44
+ module Node: {
45
+ @send
46
+ external contains: (Dom.element, Dom.element) => bool = "contains"
47
+ }
37
48
  }
38
49
 
39
50
  let innerWidth: int