@colisweb/rescript-toolkit 2.56.1 → 2.56.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,3 +1,5 @@
|
|
|
1
|
+
open ReactIntl
|
|
2
|
+
|
|
1
3
|
module Helpers = {
|
|
2
4
|
let handleChange = (handleChange, event) => handleChange(ReactEvent.Form.target(event)["value"])
|
|
3
5
|
|
|
@@ -72,11 +74,26 @@ module Make = (StateLenses: Config) => {
|
|
|
72
74
|
form.submit()
|
|
73
75
|
}}>
|
|
74
76
|
children
|
|
75
|
-
<ReachUi.VisuallyHidden>
|
|
77
|
+
<ReachUi.VisuallyHidden>
|
|
78
|
+
<input type_="submit" hidden=true />
|
|
79
|
+
</ReachUi.VisuallyHidden>
|
|
76
80
|
</form>
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
84
|
+
module RadioGroup = {
|
|
85
|
+
@react.component
|
|
86
|
+
let make = (~field, ~elements, ~inline=?) =>
|
|
87
|
+
<Form.Field
|
|
88
|
+
field
|
|
89
|
+
render={({handleChange, error, value}) => <>
|
|
90
|
+
<Toolkit__Ui_RadioGroup
|
|
91
|
+
defaultValue=value onChange={v => handleChange(v)} elements ?inline
|
|
92
|
+
/>
|
|
93
|
+
<ErrorMessage ?error />
|
|
94
|
+
</>}
|
|
95
|
+
/>
|
|
96
|
+
}
|
|
80
97
|
module Input = {
|
|
81
98
|
@react.component
|
|
82
99
|
let make = (
|
|
@@ -189,4 +206,443 @@ module Make = (StateLenses: Config) => {
|
|
|
189
206
|
/>
|
|
190
207
|
}
|
|
191
208
|
}
|
|
209
|
+
|
|
210
|
+
module Int = {
|
|
211
|
+
@react.component
|
|
212
|
+
let make = (
|
|
213
|
+
~field,
|
|
214
|
+
~label=?,
|
|
215
|
+
~id,
|
|
216
|
+
~name=?,
|
|
217
|
+
~placeholder=?,
|
|
218
|
+
~autoFocus=?,
|
|
219
|
+
~disabled=?,
|
|
220
|
+
~isOptional=?,
|
|
221
|
+
~step=?,
|
|
222
|
+
~min=?,
|
|
223
|
+
~max=?,
|
|
224
|
+
~className=?,
|
|
225
|
+
) => {
|
|
226
|
+
let parseInt: string => option<int> = %raw(`
|
|
227
|
+
x => {
|
|
228
|
+
var result = parseInt(x, 10);
|
|
229
|
+
return isNaN(result) ? undefined : result;
|
|
230
|
+
}
|
|
231
|
+
`)
|
|
232
|
+
|
|
233
|
+
<Form.Field
|
|
234
|
+
field
|
|
235
|
+
render={({handleChange, error, value, validate, state}) => {
|
|
236
|
+
let isInvalid = error->Option.isSome
|
|
237
|
+
|
|
238
|
+
let onChange = event =>
|
|
239
|
+
ReactEvent.Form.target(event)["value"]->Option.flatMap(parseInt)->handleChange
|
|
240
|
+
|
|
241
|
+
let onBlur = _ =>
|
|
242
|
+
switch state {
|
|
243
|
+
| Pristine => ()
|
|
244
|
+
| _ => validate()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
<>
|
|
248
|
+
{switch label {
|
|
249
|
+
| None => React.null
|
|
250
|
+
| Some(label) =>
|
|
251
|
+
<Toolkit__Ui_Label
|
|
252
|
+
htmlFor=id
|
|
253
|
+
optionalMessage={isOptional->Option.getWithDefault(false)
|
|
254
|
+
? <FormattedMessage defaultMessage="(Optionnel)" />
|
|
255
|
+
: React.null}>
|
|
256
|
+
label
|
|
257
|
+
</Toolkit__Ui_Label>
|
|
258
|
+
}}
|
|
259
|
+
<Toolkit__Ui_TextInput
|
|
260
|
+
?className
|
|
261
|
+
id
|
|
262
|
+
value={value->Option.map(Js.Int.toString)->Option.getWithDefault("")}
|
|
263
|
+
type_="number"
|
|
264
|
+
?name
|
|
265
|
+
?disabled
|
|
266
|
+
?placeholder
|
|
267
|
+
?autoFocus
|
|
268
|
+
?step
|
|
269
|
+
?min
|
|
270
|
+
?max
|
|
271
|
+
isInvalid
|
|
272
|
+
onChange
|
|
273
|
+
onBlur
|
|
274
|
+
/>
|
|
275
|
+
<ErrorMessage ?error />
|
|
276
|
+
</>
|
|
277
|
+
}}
|
|
278
|
+
/>
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
module DateTime = {
|
|
283
|
+
@react.component
|
|
284
|
+
let make = (
|
|
285
|
+
~field,
|
|
286
|
+
~label=?,
|
|
287
|
+
~id,
|
|
288
|
+
~name=?,
|
|
289
|
+
~startDate=?,
|
|
290
|
+
~endDate=?,
|
|
291
|
+
~selectsStart=?,
|
|
292
|
+
~selectsEnd=?,
|
|
293
|
+
~minDate=?,
|
|
294
|
+
~showTimeSelect=?,
|
|
295
|
+
~showYearDropdown=?,
|
|
296
|
+
~placeholder=?,
|
|
297
|
+
~autoFocus=?,
|
|
298
|
+
~disabled=?,
|
|
299
|
+
~isOptional=?,
|
|
300
|
+
~timeCaption=?,
|
|
301
|
+
~timeFormat=?,
|
|
302
|
+
~minTime=?,
|
|
303
|
+
~maxTime=?,
|
|
304
|
+
~timeIntervals=?,
|
|
305
|
+
~inline=?,
|
|
306
|
+
) =>
|
|
307
|
+
<Form.Field
|
|
308
|
+
field
|
|
309
|
+
render={({handleChange, error, value, validate, state}) => {
|
|
310
|
+
let isInvalid = error->Option.isSome
|
|
311
|
+
|
|
312
|
+
let onChange = value => handleChange(value->Js.Nullable.toOption)
|
|
313
|
+
|
|
314
|
+
let onBlur = _ =>
|
|
315
|
+
switch state {
|
|
316
|
+
| Pristine => ()
|
|
317
|
+
| _ => validate()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
<>
|
|
321
|
+
{switch label {
|
|
322
|
+
| None => React.null
|
|
323
|
+
| Some(label) =>
|
|
324
|
+
<Toolkit__Ui_Label
|
|
325
|
+
htmlFor=id
|
|
326
|
+
optionalMessage={isOptional->Option.getWithDefault(false)
|
|
327
|
+
? <FormattedMessage defaultMessage="(Optionnel)" />
|
|
328
|
+
: React.null}>
|
|
329
|
+
label
|
|
330
|
+
</Toolkit__Ui_Label>
|
|
331
|
+
}}
|
|
332
|
+
<Toolkit__Ui_DatetimeInput
|
|
333
|
+
?value
|
|
334
|
+
?showTimeSelect
|
|
335
|
+
?showYearDropdown
|
|
336
|
+
?disabled
|
|
337
|
+
?startDate
|
|
338
|
+
?endDate
|
|
339
|
+
?inline
|
|
340
|
+
?selectsStart
|
|
341
|
+
?timeFormat
|
|
342
|
+
?timeCaption
|
|
343
|
+
?timeIntervals
|
|
344
|
+
?selectsEnd
|
|
345
|
+
?minTime
|
|
346
|
+
?maxTime
|
|
347
|
+
?minDate
|
|
348
|
+
id
|
|
349
|
+
?name
|
|
350
|
+
?placeholder
|
|
351
|
+
?autoFocus
|
|
352
|
+
onBlur
|
|
353
|
+
onChange
|
|
354
|
+
isInvalid
|
|
355
|
+
/>
|
|
356
|
+
<ErrorMessage ?error />
|
|
357
|
+
</>
|
|
358
|
+
}}
|
|
359
|
+
/>
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
module Textarea = {
|
|
363
|
+
@react.component
|
|
364
|
+
let make = (
|
|
365
|
+
~field,
|
|
366
|
+
~label=?,
|
|
367
|
+
~variant=#default,
|
|
368
|
+
~id,
|
|
369
|
+
~name=?,
|
|
370
|
+
~placeholder=?,
|
|
371
|
+
~autoFocus=?,
|
|
372
|
+
~disabled=?,
|
|
373
|
+
~isOptional=?,
|
|
374
|
+
~className=?,
|
|
375
|
+
) =>
|
|
376
|
+
<Form.Field
|
|
377
|
+
field
|
|
378
|
+
render={({handleChange, error, value, validate, state}) => {
|
|
379
|
+
let isInvalid = error->Option.isSome
|
|
380
|
+
|
|
381
|
+
let onChange = Helpers.handleChange(handleChange)
|
|
382
|
+
|
|
383
|
+
let onBlur = _ =>
|
|
384
|
+
switch state {
|
|
385
|
+
| Pristine => ()
|
|
386
|
+
| _ => validate()
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
<>
|
|
390
|
+
{switch label {
|
|
391
|
+
| None => React.null
|
|
392
|
+
| Some(label) =>
|
|
393
|
+
<Toolkit__Ui_Label
|
|
394
|
+
htmlFor=id
|
|
395
|
+
optionalMessage={isOptional->Option.getWithDefault(false)
|
|
396
|
+
? <FormattedMessage defaultMessage="(Optionnel)" />
|
|
397
|
+
: React.null}>
|
|
398
|
+
label
|
|
399
|
+
</Toolkit__Ui_Label>
|
|
400
|
+
}}
|
|
401
|
+
<Toolkit__Ui_TextareaInput
|
|
402
|
+
?className
|
|
403
|
+
id
|
|
404
|
+
variant
|
|
405
|
+
value
|
|
406
|
+
?name
|
|
407
|
+
?disabled
|
|
408
|
+
?placeholder
|
|
409
|
+
?autoFocus
|
|
410
|
+
isInvalid
|
|
411
|
+
onChange
|
|
412
|
+
onBlur
|
|
413
|
+
/>
|
|
414
|
+
<ErrorMessage ?error />
|
|
415
|
+
</>
|
|
416
|
+
}}
|
|
417
|
+
/>
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
module Checkbox = {
|
|
421
|
+
@react.component
|
|
422
|
+
let make = (~field, ~label, ~name=?, ~disabled=?, ~className=?) =>
|
|
423
|
+
<Form.Field
|
|
424
|
+
field
|
|
425
|
+
render={({handleChange, error, value}) => <>
|
|
426
|
+
<Toolkit__Ui_Checkbox
|
|
427
|
+
?className
|
|
428
|
+
checked={value->Obj.magic}
|
|
429
|
+
value={value->Obj.magic}
|
|
430
|
+
?name
|
|
431
|
+
?disabled
|
|
432
|
+
onChange={(checked, _value) => handleChange(checked)}>
|
|
433
|
+
label
|
|
434
|
+
</Toolkit__Ui_Checkbox>
|
|
435
|
+
<ErrorMessage ?error />
|
|
436
|
+
</>}
|
|
437
|
+
/>
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
module Select = {
|
|
441
|
+
@react.component
|
|
442
|
+
let make = (
|
|
443
|
+
~field,
|
|
444
|
+
~label=?,
|
|
445
|
+
~id,
|
|
446
|
+
~name=?,
|
|
447
|
+
~items,
|
|
448
|
+
~itemToLabel=?,
|
|
449
|
+
~itemToId=?,
|
|
450
|
+
~placeholder=?,
|
|
451
|
+
~hasPlaceholderOption=?,
|
|
452
|
+
~autoFocus=?,
|
|
453
|
+
~disabled=?,
|
|
454
|
+
~isOptional=?,
|
|
455
|
+
~className=?,
|
|
456
|
+
) => {
|
|
457
|
+
let valueRef = React.useRef(None)
|
|
458
|
+
|
|
459
|
+
<Form.Field
|
|
460
|
+
field
|
|
461
|
+
render={({handleChange, error, value, validate, state}) => {
|
|
462
|
+
let isInvalid = error->Option.isSome
|
|
463
|
+
|
|
464
|
+
let onChange = value => valueRef.current = Some(value)
|
|
465
|
+
|
|
466
|
+
let onBlur = _ => {
|
|
467
|
+
valueRef.current->Option.map(handleChange)->ignore
|
|
468
|
+
valueRef.current = None
|
|
469
|
+
|
|
470
|
+
switch state {
|
|
471
|
+
| Pristine => ()
|
|
472
|
+
| _ => validate()
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
<>
|
|
477
|
+
{switch label {
|
|
478
|
+
| None => React.null
|
|
479
|
+
| Some(label) =>
|
|
480
|
+
<Toolkit__Ui_Label
|
|
481
|
+
htmlFor=id
|
|
482
|
+
optionalMessage={isOptional->Option.getWithDefault(false)
|
|
483
|
+
? <FormattedMessage defaultMessage="(Optionnel)" />
|
|
484
|
+
: React.null}>
|
|
485
|
+
label
|
|
486
|
+
</Toolkit__Ui_Label>
|
|
487
|
+
}}
|
|
488
|
+
<Toolkit__Ui_ListboxInput.Select
|
|
489
|
+
?className
|
|
490
|
+
items
|
|
491
|
+
?name
|
|
492
|
+
?itemToLabel
|
|
493
|
+
?itemToId
|
|
494
|
+
id
|
|
495
|
+
?disabled
|
|
496
|
+
?placeholder
|
|
497
|
+
?hasPlaceholderOption
|
|
498
|
+
?autoFocus
|
|
499
|
+
isInvalid
|
|
500
|
+
onChange
|
|
501
|
+
onBlur
|
|
502
|
+
defaultValue=?value
|
|
503
|
+
/>
|
|
504
|
+
<ErrorMessage ?error />
|
|
505
|
+
</>
|
|
506
|
+
}}
|
|
507
|
+
/>
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
module SearchSelect = {
|
|
512
|
+
open! BsReactSelect
|
|
513
|
+
|
|
514
|
+
@react.component
|
|
515
|
+
let make = (
|
|
516
|
+
~field,
|
|
517
|
+
~label=?,
|
|
518
|
+
~id,
|
|
519
|
+
~name,
|
|
520
|
+
~options,
|
|
521
|
+
~placeholder=?,
|
|
522
|
+
~isDisabled=?,
|
|
523
|
+
~className="",
|
|
524
|
+
~isOptional=?,
|
|
525
|
+
~valueFormat,
|
|
526
|
+
~autoFocus=?,
|
|
527
|
+
) => {
|
|
528
|
+
<Form.Field
|
|
529
|
+
field
|
|
530
|
+
render={({handleChange, error, value}) => {
|
|
531
|
+
let isInvalid = error->Option.isSome
|
|
532
|
+
|
|
533
|
+
<>
|
|
534
|
+
{switch label {
|
|
535
|
+
| None => React.null
|
|
536
|
+
| Some(label) =>
|
|
537
|
+
<Toolkit__Ui_Label
|
|
538
|
+
htmlFor=id
|
|
539
|
+
optionalMessage={isOptional->Option.getWithDefault(false)
|
|
540
|
+
? <FormattedMessage defaultMessage="(Optionnel)" />
|
|
541
|
+
: React.null}>
|
|
542
|
+
label
|
|
543
|
+
</Toolkit__Ui_Label>
|
|
544
|
+
}}
|
|
545
|
+
<ReactSelect
|
|
546
|
+
defaultMenuIsOpen=?autoFocus
|
|
547
|
+
?autoFocus
|
|
548
|
+
name
|
|
549
|
+
?isDisabled
|
|
550
|
+
classNamePrefix="react-select"
|
|
551
|
+
className={cx([className, isInvalid ? "errored" : ""])}
|
|
552
|
+
?placeholder
|
|
553
|
+
onChange={o => handleChange(Some(o.value))}
|
|
554
|
+
value=?{value->Option.map(valueFormat)}
|
|
555
|
+
options
|
|
556
|
+
/>
|
|
557
|
+
<ErrorMessage ?error />
|
|
558
|
+
</>
|
|
559
|
+
}}
|
|
560
|
+
/>
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
module MultiSelect = {
|
|
565
|
+
@react.component
|
|
566
|
+
let make = (
|
|
567
|
+
~field,
|
|
568
|
+
~label=?,
|
|
569
|
+
~id,
|
|
570
|
+
~name=?,
|
|
571
|
+
~items,
|
|
572
|
+
~itemToLabel,
|
|
573
|
+
~itemToId,
|
|
574
|
+
~placeholder=?,
|
|
575
|
+
~hasPlaceholderOption=?,
|
|
576
|
+
~autoFocus=?,
|
|
577
|
+
~disabled=?,
|
|
578
|
+
~isOptional=?,
|
|
579
|
+
~className=?,
|
|
580
|
+
) => {
|
|
581
|
+
let valueRef = React.useRef(None)
|
|
582
|
+
|
|
583
|
+
<Form.Field
|
|
584
|
+
field
|
|
585
|
+
render={({handleChange, error, value, validate, state}) => {
|
|
586
|
+
let isInvalid = error->Option.isSome
|
|
587
|
+
|
|
588
|
+
let onChange = value => valueRef.current = Some(value)
|
|
589
|
+
|
|
590
|
+
let onBlur = _ => {
|
|
591
|
+
valueRef.current->Option.map(handleChange)->ignore
|
|
592
|
+
valueRef.current = None
|
|
593
|
+
|
|
594
|
+
switch state {
|
|
595
|
+
| Pristine => ()
|
|
596
|
+
| _ => validate()
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
<>
|
|
601
|
+
{switch label {
|
|
602
|
+
| None => React.null
|
|
603
|
+
| Some(label) =>
|
|
604
|
+
<Toolkit__Ui_Label
|
|
605
|
+
htmlFor=id
|
|
606
|
+
optionalMessage={isOptional->Option.getWithDefault(false)
|
|
607
|
+
? <FormattedMessage defaultMessage="(Optionnel)" />
|
|
608
|
+
: React.null}>
|
|
609
|
+
label
|
|
610
|
+
</Toolkit__Ui_Label>
|
|
611
|
+
}}
|
|
612
|
+
<Toolkit__Ui_ListboxInput.MultiSelect
|
|
613
|
+
?className
|
|
614
|
+
items
|
|
615
|
+
?name
|
|
616
|
+
itemToLabel
|
|
617
|
+
itemToId
|
|
618
|
+
id
|
|
619
|
+
value
|
|
620
|
+
?disabled
|
|
621
|
+
?placeholder
|
|
622
|
+
?hasPlaceholderOption
|
|
623
|
+
?autoFocus
|
|
624
|
+
isInvalid
|
|
625
|
+
onChange
|
|
626
|
+
onBlur
|
|
627
|
+
/>
|
|
628
|
+
<ErrorMessage ?error />
|
|
629
|
+
</>
|
|
630
|
+
}}
|
|
631
|
+
/>
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
module Switch = {
|
|
636
|
+
@react.component
|
|
637
|
+
let make = (~field, ~label=?, ~id, ~size=?) =>
|
|
638
|
+
<Form.Field
|
|
639
|
+
field
|
|
640
|
+
render={({handleChange, value}) => <>
|
|
641
|
+
{label->Option.mapWithDefault(React.null, label =>
|
|
642
|
+
<Toolkit__Ui_Label htmlFor=id> label </Toolkit__Ui_Label>
|
|
643
|
+
)}
|
|
644
|
+
<Toolkit__Ui_Switch onChange={value => handleChange(value)} name=id checked=value ?size />
|
|
645
|
+
</>}
|
|
646
|
+
/>
|
|
647
|
+
}
|
|
192
648
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
open ReachUi
|
|
2
|
+
module Radio = Toolkit__Ui.Radio
|
|
3
|
+
|
|
4
|
+
type element = {
|
|
5
|
+
label: React.element,
|
|
6
|
+
value: string,
|
|
7
|
+
disabled: bool,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@react.component
|
|
11
|
+
let make = (~onChange, ~elements: array<element>, ~defaultValue=?, ~inline=false) => {
|
|
12
|
+
let name = "radio-" ++ AutoId.use("")
|
|
13
|
+
let (value, setValue) = React.useState(() => defaultValue->Option.getWithDefault(""))
|
|
14
|
+
|
|
15
|
+
React.useEffect1(() => {
|
|
16
|
+
onChange(value)
|
|
17
|
+
None
|
|
18
|
+
}, [value])
|
|
19
|
+
|
|
20
|
+
<div className={inline ? "flex gap-3" : ""}>
|
|
21
|
+
{elements
|
|
22
|
+
->Array.mapWithIndex((i, element) =>
|
|
23
|
+
<Radio
|
|
24
|
+
key={"radio-" ++ string_of_int(i)}
|
|
25
|
+
value=element.value
|
|
26
|
+
name
|
|
27
|
+
disabled=element.disabled
|
|
28
|
+
checked={element.value === value}
|
|
29
|
+
onChange={value => {
|
|
30
|
+
setValue(_ => value)
|
|
31
|
+
}}>
|
|
32
|
+
element.label
|
|
33
|
+
</Radio>
|
|
34
|
+
)
|
|
35
|
+
->React.array}
|
|
36
|
+
</div>
|
|
37
|
+
}
|
|
@@ -5923,6 +5923,12 @@ module FaUserCog = {
|
|
|
5923
5923
|
"FaUserCog"
|
|
5924
5924
|
}
|
|
5925
5925
|
|
|
5926
|
+
module FaUserCircle = {
|
|
5927
|
+
@module("react-icons/fa") @react.component
|
|
5928
|
+
external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element =
|
|
5929
|
+
"FaUserCircle"
|
|
5930
|
+
}
|
|
5931
|
+
|
|
5926
5932
|
module FaRedo = {
|
|
5927
5933
|
@module("react-icons/fa") @react.component
|
|
5928
5934
|
external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element = "FaRedo"
|