@colisweb/rescript-toolkit 2.33.1 → 2.34.0
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
package/src/Toolkit.res
CHANGED
|
@@ -9,5 +9,6 @@ module Router = Toolkit__Router
|
|
|
9
9
|
module Ui = Toolkit__Ui
|
|
10
10
|
module Utils = Toolkit__Utils
|
|
11
11
|
module Form = Toolkit__Form
|
|
12
|
+
module FormValidationFunctions = Toolkit__FormValidationFunctions
|
|
12
13
|
module BrowserLogger = Toolkit__BrowserLogger
|
|
13
14
|
module NativeLogger = Toolkit__NativeLogger
|
|
@@ -19,7 +19,7 @@ module Msg = {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
let
|
|
22
|
+
let toReSchemaResult = (opt: option<string>): ReSchema.fieldState =>
|
|
23
23
|
switch opt {
|
|
24
24
|
| Some(e) => Error(e)
|
|
25
25
|
| None => Valid
|
|
@@ -35,7 +35,7 @@ let requiredStringNonEmpty = (intl, value) => {
|
|
|
35
35
|
let requiredPosInt = (intl, value) => {
|
|
36
36
|
switch value {
|
|
37
37
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
38
|
-
| value if !
|
|
38
|
+
| value if !Toolkit__Utils_Regex.Test.isPositiveInt(value) =>
|
|
39
39
|
Some(Intl.formatMessage(intl, Msg.requiredPosInt))
|
|
40
40
|
| _ => None
|
|
41
41
|
}
|
|
@@ -44,7 +44,7 @@ let requiredPosInt = (intl, value) => {
|
|
|
44
44
|
let optionalPosInt = (intl, value) => {
|
|
45
45
|
switch value {
|
|
46
46
|
| "" => None
|
|
47
|
-
| value if !
|
|
47
|
+
| value if !Toolkit__Utils_Regex.Test.isPositiveInt(value) =>
|
|
48
48
|
Some(Intl.formatMessage(intl, Msg.requiredPosInt))
|
|
49
49
|
| _ => None
|
|
50
50
|
}
|
|
@@ -52,7 +52,7 @@ let optionalPosInt = (intl, value) => {
|
|
|
52
52
|
let requiredPosFloat = (intl, value) => {
|
|
53
53
|
switch value {
|
|
54
54
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
55
|
-
| value if !
|
|
55
|
+
| value if !Toolkit__Utils_Regex.Test.isPositiveIntOrFloat(value) =>
|
|
56
56
|
Some(Intl.formatMessage(intl, Msg.requiredPosIntOrFloat))
|
|
57
57
|
| _ => None
|
|
58
58
|
}
|
|
@@ -62,7 +62,7 @@ let requiredFloat = (intl, value) => {
|
|
|
62
62
|
switch value->Js.String2.split("-") {
|
|
63
63
|
| _ if value === "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
64
64
|
| ["", value]
|
|
65
|
-
| [value] if
|
|
65
|
+
| [value] if Toolkit__Utils_Regex.Test.isPositiveIntOrFloat(value) =>
|
|
66
66
|
None
|
|
67
67
|
| _ => Some(Intl.formatMessage(intl, Msg.requiredPosIntOrFloat))
|
|
68
68
|
}
|
|
@@ -72,7 +72,7 @@ let optionalFloat = (intl, value) => {
|
|
|
72
72
|
switch value->Js.String2.split("-") {
|
|
73
73
|
| _ if value === "" => None
|
|
74
74
|
| ["", value]
|
|
75
|
-
| [value] if
|
|
75
|
+
| [value] if Toolkit__Utils_Regex.Test.isPositiveIntOrFloat(value) =>
|
|
76
76
|
None
|
|
77
77
|
| _ => Some(Intl.formatMessage(intl, Msg.requiredPosIntOrFloat))
|
|
78
78
|
}
|
|
@@ -82,7 +82,7 @@ let requiredPosFloatCurrencyEur = (intl, value) => {
|
|
|
82
82
|
switch value {
|
|
83
83
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
84
84
|
| v =>
|
|
85
|
-
switch v->
|
|
85
|
+
switch v->Toolkit__Decoders.UnitMeasure.Currency.WithUnit.decodeFromString {
|
|
86
86
|
| Ok(#EUR(_)) => None
|
|
87
87
|
| _ =>
|
|
88
88
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 EUR' '0.5 EUR'"}))
|
|
@@ -94,7 +94,7 @@ let requiredPosFloatTimeHour = (intl, value) => {
|
|
|
94
94
|
switch value {
|
|
95
95
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
96
96
|
| v =>
|
|
97
|
-
switch v->
|
|
97
|
+
switch v->Toolkit__Decoders.UnitMeasure.Time.WithUnit.decodeFromString {
|
|
98
98
|
| Ok(#h(_)) => None
|
|
99
99
|
| _ => Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 h' '0.5 h'"}))
|
|
100
100
|
}
|
|
@@ -105,7 +105,7 @@ let requiredPosFloatTimeMin = (intl, value) => {
|
|
|
105
105
|
switch value {
|
|
106
106
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
107
107
|
| v =>
|
|
108
|
-
switch v->
|
|
108
|
+
switch v->Toolkit__Decoders.UnitMeasure.Time.WithUnit.decodeFromString {
|
|
109
109
|
| Ok(#min(_)) => None
|
|
110
110
|
| _ =>
|
|
111
111
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 min' '0.5 min'"}))
|
|
@@ -117,7 +117,7 @@ let requiredPosFloatTimeHour_Min = (intl, value) => {
|
|
|
117
117
|
switch value {
|
|
118
118
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
119
119
|
| v =>
|
|
120
|
-
switch v->
|
|
120
|
+
switch v->Toolkit__Decoders.UnitMeasure.Time.WithUnit.decodeFromString {
|
|
121
121
|
| Ok(#h(_)) => None
|
|
122
122
|
| Ok(#min(_)) => None
|
|
123
123
|
| _ =>
|
|
@@ -130,7 +130,7 @@ let optionalPosFloatTimeMin = (intl, value) => {
|
|
|
130
130
|
switch value {
|
|
131
131
|
| "" => None
|
|
132
132
|
| v =>
|
|
133
|
-
switch v->
|
|
133
|
+
switch v->Toolkit__Decoders.UnitMeasure.Time.WithUnit.decodeFromString {
|
|
134
134
|
| Ok(#min(_)) => None
|
|
135
135
|
| _ =>
|
|
136
136
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 min' '0.5 min'"}))
|
|
@@ -142,7 +142,7 @@ let requiredPosFloatPriceEurByHour = (intl, value) => {
|
|
|
142
142
|
switch value {
|
|
143
143
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
144
144
|
| v =>
|
|
145
|
-
switch v->
|
|
145
|
+
switch v->Toolkit__Decoders.UnitMeasure.CompositeUnits.CurrencyPerTime.WithUnit.decodeFromString {
|
|
146
146
|
| Ok(#EUR_h(_)) => None
|
|
147
147
|
| _ =>
|
|
148
148
|
Some(
|
|
@@ -155,7 +155,7 @@ let requiredPosFloatPriceEurByKm = (intl, value) => {
|
|
|
155
155
|
switch value {
|
|
156
156
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
157
157
|
| v =>
|
|
158
|
-
switch v->
|
|
158
|
+
switch v->Toolkit__Decoders.UnitMeasure.CompositeUnits.CurrencyPerDistance.WithUnit.decodeFromString {
|
|
159
159
|
| Ok(#EUR_km(_)) => None
|
|
160
160
|
| _ =>
|
|
161
161
|
Some(
|
|
@@ -173,7 +173,7 @@ let requiredPosFloatDistanceKm = (intl, value) => {
|
|
|
173
173
|
switch value {
|
|
174
174
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
175
175
|
| v =>
|
|
176
|
-
switch v->
|
|
176
|
+
switch v->Toolkit__Decoders.UnitMeasure.Dimension.WithUnit.decodeFromString {
|
|
177
177
|
| Ok(#km(_)) => None
|
|
178
178
|
| _ =>
|
|
179
179
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 km' '0.5 km'"}))
|
|
@@ -184,7 +184,7 @@ let requiredPosFloatDistanceKm_M = (intl, value) => {
|
|
|
184
184
|
switch value {
|
|
185
185
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
186
186
|
| v =>
|
|
187
|
-
switch v->
|
|
187
|
+
switch v->Toolkit__Decoders.UnitMeasure.Dimension.WithUnit.decodeFromString {
|
|
188
188
|
| Ok(#km(_)) => None
|
|
189
189
|
| Ok(#m(_)) => None
|
|
190
190
|
| _ => Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'15 m' '0.5 km'"}))
|
|
@@ -196,7 +196,7 @@ let optionalPosFloatDistanceKm = (intl, value) => {
|
|
|
196
196
|
switch value {
|
|
197
197
|
| "" => None
|
|
198
198
|
| v =>
|
|
199
|
-
switch v->
|
|
199
|
+
switch v->Toolkit__Decoders.UnitMeasure.Dimension.WithUnit.decodeFromString {
|
|
200
200
|
| Ok(#km(_)) => None
|
|
201
201
|
| _ =>
|
|
202
202
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 km' '0.5 km'"}))
|
|
@@ -208,7 +208,7 @@ let requiredPosFloatVolumeM3 = (intl, value) => {
|
|
|
208
208
|
switch value {
|
|
209
209
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
210
210
|
| v =>
|
|
211
|
-
switch v->
|
|
211
|
+
switch v->Toolkit__Decoders.UnitMeasure.Volume.WithUnit.decodeFromString {
|
|
212
212
|
| Ok(#m3(_)) => None
|
|
213
213
|
| _ =>
|
|
214
214
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": `'10 m³' '0.5 m³'`}))
|
|
@@ -220,7 +220,7 @@ let requiredPosFloatDimensionCm = (intl, value) => {
|
|
|
220
220
|
switch value {
|
|
221
221
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
222
222
|
| v =>
|
|
223
|
-
switch v->
|
|
223
|
+
switch v->Toolkit__Decoders.UnitMeasure.Dimension.WithUnit.decodeFromString {
|
|
224
224
|
| Ok(#cm(_)) => None
|
|
225
225
|
| _ =>
|
|
226
226
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 cm' '0.5 cm'"}))
|
|
@@ -231,7 +231,7 @@ let requiredPosFloatDimensionCm_M = (intl, value) => {
|
|
|
231
231
|
switch value {
|
|
232
232
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
233
233
|
| v =>
|
|
234
|
-
switch v->
|
|
234
|
+
switch v->Toolkit__Decoders.UnitMeasure.Dimension.WithUnit.decodeFromString {
|
|
235
235
|
| Ok(#cm(_)) => None
|
|
236
236
|
| Ok(#m(_)) => None
|
|
237
237
|
| _ => Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 cm' '0.5 m'"}))
|
|
@@ -243,7 +243,7 @@ let requiredPosFloatWeightKg = (intl, value) => {
|
|
|
243
243
|
switch value {
|
|
244
244
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
245
245
|
| v =>
|
|
246
|
-
switch v->
|
|
246
|
+
switch v->Toolkit__Decoders.UnitMeasure.Weight.WithUnit.decodeFromString {
|
|
247
247
|
| Ok(#kg(_)) => None
|
|
248
248
|
| _ =>
|
|
249
249
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 kg' '0.5 kg'"}))
|
|
@@ -254,7 +254,7 @@ let optionalPosFloatWeightKg = (intl, value) => {
|
|
|
254
254
|
switch value {
|
|
255
255
|
| "" => None
|
|
256
256
|
| v =>
|
|
257
|
-
switch v->
|
|
257
|
+
switch v->Toolkit__Decoders.UnitMeasure.Weight.WithUnit.decodeFromString {
|
|
258
258
|
| Ok(#kg(_)) => None
|
|
259
259
|
| _ =>
|
|
260
260
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 kg' '0.5 kg'"}))
|
|
@@ -265,7 +265,7 @@ let requiredPosFloatWeightG = (intl, value) => {
|
|
|
265
265
|
switch value {
|
|
266
266
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
267
267
|
| v =>
|
|
268
|
-
switch v->
|
|
268
|
+
switch v->Toolkit__Decoders.UnitMeasure.Weight.WithUnit.decodeFromString {
|
|
269
269
|
| Ok(#g(_)) => None
|
|
270
270
|
| _ =>
|
|
271
271
|
Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 kg' '0.5 kg'"}))
|
package/src/mock/MockOverlay.res
CHANGED
|
@@ -8,7 +8,7 @@ let make = (~worker: Msw.worker, ~children) => {
|
|
|
8
8
|
->Option.mapWithDefault(false, bool_of_string)
|
|
9
9
|
)
|
|
10
10
|
|
|
11
|
-
React.
|
|
11
|
+
React.useLayoutEffect1(() => {
|
|
12
12
|
if mockEnabled {
|
|
13
13
|
worker->Msw.start
|
|
14
14
|
Browser.LocalStorage.setItem(localStorageKey, Js.Nullable.return("true"))
|
|
@@ -22,6 +22,7 @@ let make = (
|
|
|
22
22
|
~onChange=?,
|
|
23
23
|
~name=?,
|
|
24
24
|
~checked=?,
|
|
25
|
+
~defaultChecked=?,
|
|
25
26
|
~className="",
|
|
26
27
|
~size: size=#sm,
|
|
27
28
|
~checkboxClassName="",
|
|
@@ -31,6 +32,17 @@ let make = (
|
|
|
31
32
|
~hideLabel=false,
|
|
32
33
|
) => {
|
|
33
34
|
let (isChecked, setChecked) = React.useState(() => checked->Option.getWithDefault(false))
|
|
35
|
+
let previousChecked = Toolkit__Hooks.usePrevious(isChecked)
|
|
36
|
+
|
|
37
|
+
React.useEffect2(() => {
|
|
38
|
+
switch (previousChecked, checked) {
|
|
39
|
+
| (Some(previous), Some(checked)) if previous != checked => setChecked(_ => checked)
|
|
40
|
+
| _ => ()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
None
|
|
44
|
+
}, (previousChecked, checked))
|
|
45
|
+
|
|
34
46
|
<label
|
|
35
47
|
className={cx([
|
|
36
48
|
Styles.label,
|
|
@@ -45,6 +57,7 @@ let make = (
|
|
|
45
57
|
<input
|
|
46
58
|
type_="checkbox"
|
|
47
59
|
value
|
|
60
|
+
?defaultChecked
|
|
48
61
|
className="hidden"
|
|
49
62
|
onChange={event => {
|
|
50
63
|
let target = ReactEvent.Form.target(event)
|