@colisweb/rescript-toolkit 2.66.1 → 2.66.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.66.1",
3
+ "version": "2.66.2",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build -with-deps",
@@ -133,21 +133,25 @@ module ReactAsyncSelectMultiple = {
133
133
  }
134
134
 
135
135
  module ReactSelectMultipleCreateInput = {
136
+ type labelOption<'value> = {
137
+ label: string,
138
+ value: 'value,
139
+ }
136
140
  module ReactSelect = {
137
- type components = {"DropDownIndicator": React.element}
138
-
141
+ type components = {"DropdownIndicator": React.element}
142
+ type labeledValue = {value: string, label: string}
139
143
  @module("react-select/creatable") @react.component
140
144
  external make: (
141
145
  ~components: components,
142
- ~inputValue: string=?,
146
+ ~inputValue: string,
143
147
  ~isClearable: option<bool>=?,
144
148
  ~isMulti: option<bool>=?,
145
149
  ~menuIsOpen: option<bool>=?,
146
- ~onChange: array<string> => unit=?,
147
- ~onInputChange: string => unit=?,
150
+ ~onChange: array<labelOption<'a>> => unit,
151
+ ~onInputChange: string => unit,
148
152
  ~onKeyDown: ReactEvent.Keyboard.t => unit,
149
153
  ~placeholder: option<string>=?,
150
- ~value: array<string>,
154
+ ~value: array<labelOption<'a>>,
151
155
  ~isDisabled: option<bool>=?,
152
156
  ~isLoading: option<bool>=?,
153
157
  ~className: option<string>=?,
@@ -157,10 +161,8 @@ module ReactSelectMultipleCreateInput = {
157
161
 
158
162
  @react.component
159
163
  let make = (
160
- ~inputValue: option<string>=?,
161
- ~onInputChange: option<string => unit>=?,
162
164
  ~value: array<string>,
163
- ~onChange: option<array<string> => unit>=?,
165
+ ~onChange: array<string> => unit,
164
166
  ~isClearable=true,
165
167
  ~placeholder="",
166
168
  ~isDisabled=false,
@@ -168,19 +170,21 @@ module ReactSelectMultipleCreateInput = {
168
170
  ~className: option<string>=?,
169
171
  ~id: option<string>=?,
170
172
  ) => {
173
+ let (inputValue, onInputChange) = React.useState(() => "")
174
+ let onInputChange = v => onInputChange(_ => v)
175
+
171
176
  <ReactSelect
172
- components={"DropDownIndicator": React.null}
177
+ components={"DropdownIndicator": React.null}
173
178
  isMulti=true
174
179
  onKeyDown={e => {
175
- switch inputValue {
176
- | Some("")
177
- | None => ()
178
- | Some(inputValue) =>
180
+ if inputValue === "" {
181
+ ()
182
+ } else {
179
183
  switch e->ReactEvent.Keyboard.key {
180
184
  | "Enter"
181
185
  | "Tab" => {
182
- onInputChange->Option.forEach(fn => fn(""))
183
- onChange->Option.forEach(fn => fn(value->Array.concat([inputValue])))
186
+ onInputChange("")
187
+ onChange(value->Array.concat([inputValue]))
184
188
  e->ReactEvent.Keyboard.preventDefault
185
189
  }
186
190
 
@@ -189,12 +193,12 @@ module ReactSelectMultipleCreateInput = {
189
193
  }
190
194
  }}
191
195
  menuIsOpen={false}
192
- ?inputValue
196
+ inputValue
193
197
  isClearable
194
- ?onChange
195
- ?onInputChange
198
+ onChange={values => onChange(values->Array.map(({label}) => label))}
199
+ onInputChange
196
200
  placeholder
197
- value
201
+ value={value->Array.mapWithIndex((i, v) => {label: v, value: v ++ i->Js.Int.toString})}
198
202
  isDisabled
199
203
  isLoading
200
204
  ?className