@colisweb/rescript-toolkit 5.16.7 → 5.17.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
|
@@ -46,6 +46,7 @@ module type MakeWithUnitConfig = {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
module MakeWithUnit = (Config: MakeWithUnitConfig) => {
|
|
49
|
+
module Unit = Config.Unit
|
|
49
50
|
let decodeFromString = (string: string) => {
|
|
50
51
|
// match a positive int or float followed by it's unit (capturing int/float in group1 and unit in group2)
|
|
51
52
|
let regexp = %re("/^(\d+(?:\.\d*)?)\s*(\D*)$/")
|
|
@@ -23,7 +23,7 @@ module Msg = {
|
|
|
23
23
|
defaultMessage: "Format requis : 14 chiffres",
|
|
24
24
|
}
|
|
25
25
|
let requiredStrictPosInt = {
|
|
26
|
-
defaultMessage: "Doit
|
|
26
|
+
defaultMessage: "Doit être un entier strictement positif",
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
let stringNonEmpty = {defaultMessage: "Champ requis"}
|
|
@@ -98,6 +98,14 @@ let optionalPosInt = (intl, value) => {
|
|
|
98
98
|
| _ => None
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
let optionalStrictPosInt = (intl, value) => {
|
|
102
|
+
switch value {
|
|
103
|
+
| "" => None
|
|
104
|
+
| value if !Toolkit__Utils_Regex.Test.isStrictPositiveInt(value) =>
|
|
105
|
+
Some(Intl.formatMessage(intl, Msg.requiredStrictPosInt))
|
|
106
|
+
| _ => None
|
|
107
|
+
}
|
|
108
|
+
}
|
|
101
109
|
let requiredPosFloat = (intl, value) => {
|
|
102
110
|
switch value {
|
|
103
111
|
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
@@ -4,7 +4,7 @@ type rec state = {list: array<options>}
|
|
|
4
4
|
and options = {
|
|
5
5
|
id: id,
|
|
6
6
|
isVisible: bool,
|
|
7
|
-
title:
|
|
7
|
+
title: React.element,
|
|
8
8
|
content: option<React.element>,
|
|
9
9
|
closable: bool,
|
|
10
10
|
variant: variant,
|
|
@@ -40,7 +40,7 @@ let show = (~title, ~content=?, ~closable=true, ~variant, ~timeout=5000, ()) =>
|
|
|
40
40
|
Show({
|
|
41
41
|
id,
|
|
42
42
|
isVisible: true,
|
|
43
|
-
title,
|
|
43
|
+
title: title->React.string,
|
|
44
44
|
content,
|
|
45
45
|
closable,
|
|
46
46
|
variant,
|
|
@@ -49,6 +49,49 @@ let show = (~title, ~content=?, ~closable=true, ~variant, ~timeout=5000, ()) =>
|
|
|
49
49
|
)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
let success = title => {
|
|
53
|
+
let id: id = Js.Math.random()->Js.Float.toString->Obj.magic
|
|
54
|
+
store.dispatch(
|
|
55
|
+
Show({
|
|
56
|
+
id,
|
|
57
|
+
isVisible: true,
|
|
58
|
+
title,
|
|
59
|
+
content: None,
|
|
60
|
+
closable: true,
|
|
61
|
+
variant: Success,
|
|
62
|
+
timeout: 5000,
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
let warning = title => {
|
|
67
|
+
let id: id = Js.Math.random()->Js.Float.toString->Obj.magic
|
|
68
|
+
store.dispatch(
|
|
69
|
+
Show({
|
|
70
|
+
id,
|
|
71
|
+
isVisible: true,
|
|
72
|
+
title,
|
|
73
|
+
content: None,
|
|
74
|
+
closable: true,
|
|
75
|
+
variant: Warning,
|
|
76
|
+
timeout: 5000,
|
|
77
|
+
}),
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
let error = title => {
|
|
81
|
+
let id: id = Js.Math.random()->Js.Float.toString->Obj.magic
|
|
82
|
+
store.dispatch(
|
|
83
|
+
Show({
|
|
84
|
+
id,
|
|
85
|
+
isVisible: true,
|
|
86
|
+
title,
|
|
87
|
+
content: None,
|
|
88
|
+
closable: true,
|
|
89
|
+
variant: Danger,
|
|
90
|
+
timeout: 5000,
|
|
91
|
+
}),
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
52
95
|
let remove = id => store.dispatch(Remove(id))
|
|
53
96
|
let hide = id => {
|
|
54
97
|
store.dispatch(Hide(id))
|
|
@@ -117,7 +160,7 @@ module Item = {
|
|
|
117
160
|
| Danger => "text-danger-700"
|
|
118
161
|
},
|
|
119
162
|
])}>
|
|
120
|
-
{title
|
|
163
|
+
{title}
|
|
121
164
|
</p>
|
|
122
165
|
</Toast.Title>
|
|
123
166
|
</div>
|