@colisweb/rescript-toolkit 2.65.6 → 2.66.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.65.6",
3
+ "version": "2.66.1",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build -with-deps",
@@ -19,6 +19,7 @@ let make = (
19
19
  let (selectedOptions, setSelectedOptions) = React.useState(() => defaultValue)
20
20
  let previousDefaultValue = Toolkit__Hooks.usePrevious(defaultValue)
21
21
  let (search, setSearch) = React.useState(() => "")
22
+ let allowFilter = options->Array.length > 5 && allowFilter
22
23
 
23
24
  React.useEffect2(() => {
24
25
  let prev =
@@ -61,6 +62,7 @@ let make = (
61
62
  ? <div className="mb-3">
62
63
  <Toolkit__Ui_TextInput
63
64
  id="search"
65
+ autoFocus={true}
64
66
  placeholder=?{searchPlaceholder}
65
67
  onChange={event => {
66
68
  let target = event->ReactEvent.Form.currentTarget
@@ -85,12 +87,16 @@ let make = (
85
87
  ->Js.String2.replaceByRe(%re("/[\u0300-\u036f]/g"), "")
86
88
  ->Js.String2.includes(search)
87
89
  )
88
- ->Array.map(item => {
90
+ ->Array.mapWithIndex((i, item) => {
89
91
  let {itemLabel, label, value} = item
90
92
 
91
93
  <div
92
94
  key={`multiselectoption-${label}-${value}`}
93
- className={cx(["flex flex-row items-center gap-2 mt-3 pt-3 text-left", itemClassName])}>
95
+ className={cx([
96
+ "flex flex-row items-center gap-2 pt-3 text-left",
97
+ i > 0 ? "mt-3" : "",
98
+ itemClassName,
99
+ ])}>
94
100
  <Toolkit__Ui_Checkbox
95
101
  value
96
102
  className="w-full flex-shrink-0"
@@ -108,8 +114,8 @@ let make = (
108
114
  } else {
109
115
  setSelectedOptions(selectedOptions => {
110
116
  let value =
111
- selectedOptions->Array.keep(selectedItem =>
112
- selectedItem.value != value && selectedItem.label != label
117
+ selectedOptions->Array.keep(
118
+ selectedItem => selectedItem.value != value && selectedItem.label != label,
113
119
  )
114
120
 
115
121
  onChange(value)
@@ -139,12 +139,12 @@ module ReactSelectMultipleCreateInput = {
139
139
  @module("react-select/creatable") @react.component
140
140
  external make: (
141
141
  ~components: components,
142
- ~inputValue: string,
142
+ ~inputValue: string=?,
143
143
  ~isClearable: option<bool>=?,
144
144
  ~isMulti: option<bool>=?,
145
145
  ~menuIsOpen: option<bool>=?,
146
- ~onChange: array<string> => unit,
147
- ~onInputChange: string => unit,
146
+ ~onChange: array<string> => unit=?,
147
+ ~onInputChange: string => unit=?,
148
148
  ~onKeyDown: ReactEvent.Keyboard.t => unit,
149
149
  ~placeholder: option<string>=?,
150
150
  ~value: array<string>,
@@ -157,10 +157,10 @@ module ReactSelectMultipleCreateInput = {
157
157
 
158
158
  @react.component
159
159
  let make = (
160
- ~inputValue: string,
161
- ~onInputChange: string => unit,
160
+ ~inputValue: option<string>=?,
161
+ ~onInputChange: option<string => unit>=?,
162
162
  ~value: array<string>,
163
- ~onChange: array<string> => unit,
163
+ ~onChange: option<array<string> => unit>=?,
164
164
  ~isClearable=true,
165
165
  ~placeholder="",
166
166
  ~isDisabled=false,
@@ -172,14 +172,15 @@ module ReactSelectMultipleCreateInput = {
172
172
  components={"DropDownIndicator": React.null}
173
173
  isMulti=true
174
174
  onKeyDown={e => {
175
- if inputValue === "" {
176
- ()
177
- } else {
175
+ switch inputValue {
176
+ | Some("")
177
+ | None => ()
178
+ | Some(inputValue) =>
178
179
  switch e->ReactEvent.Keyboard.key {
179
180
  | "Enter"
180
181
  | "Tab" => {
181
- onInputChange("")
182
- onChange(value->Array.concat([inputValue]))
182
+ onInputChange->Option.forEach(fn => fn(""))
183
+ onChange->Option.forEach(fn => fn(value->Array.concat([inputValue])))
183
184
  e->ReactEvent.Keyboard.preventDefault
184
185
  }
185
186
 
@@ -188,10 +189,10 @@ module ReactSelectMultipleCreateInput = {
188
189
  }
189
190
  }}
190
191
  menuIsOpen={false}
191
- inputValue
192
+ ?inputValue
192
193
  isClearable
193
- onChange
194
- onInputChange
194
+ ?onChange
195
+ ?onInputChange
195
196
  placeholder
196
197
  value
197
198
  isDisabled