@jsenv/navi 0.9.2 → 0.10.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/dist/jsenv_navi.js +581 -408
- package/index.js +5 -0
- package/package.json +1 -1
- package/src/components/callout/callout.js +3 -1
- package/src/components/details/details.jsx +7 -8
- package/src/components/field/button.jsx +6 -63
- package/src/components/field/checkbox_list.jsx +0 -1
- package/src/components/field/form.jsx +2 -17
- package/src/components/field/input_checkbox.jsx +0 -1
- package/src/components/field/input_textual.jsx +5 -142
- package/src/components/field/radio_list.jsx +0 -1
- package/src/components/field/select.jsx +0 -2
- package/src/components/field/use_form_events.js +4 -0
- package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +1 -1
- package/src/components/link/link.jsx +27 -25
- package/src/components/text/text.jsx +28 -18
- package/src/validation/constraints/native_constraints.js +43 -18
- package/src/validation/constraints/same_as_constraint.js +42 -0
- package/src/validation/custom_constraint_validation.js +262 -59
- package/src/validation/demos/demo_same_as_constraint.html +259 -0
- package/src/validation/input_change_effect.js +106 -0
|
@@ -24,25 +24,36 @@ import.meta.css = /* css */ `
|
|
|
24
24
|
}
|
|
25
25
|
`;
|
|
26
26
|
|
|
27
|
-
export const
|
|
28
|
-
color
|
|
29
|
-
bold
|
|
30
|
-
italic
|
|
31
|
-
underline
|
|
32
|
-
size
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
export const useTypographyStyle = (props) => {
|
|
28
|
+
const color = props.color;
|
|
29
|
+
const bold = props.bold;
|
|
30
|
+
const italic = props.italic;
|
|
31
|
+
const underline = props.underline;
|
|
32
|
+
const size = props.size;
|
|
33
|
+
delete props.color;
|
|
34
|
+
delete props.bold;
|
|
35
|
+
delete props.italic;
|
|
36
|
+
delete props.underline;
|
|
37
|
+
delete props.size;
|
|
38
|
+
return {
|
|
39
|
+
color,
|
|
40
|
+
fontWeight: bold ? "bold" : bold === undefined ? undefined : "normal",
|
|
41
|
+
fontStyle: italic ? "italic" : italic === undefined ? undefined : "normal",
|
|
42
|
+
fontSize: size,
|
|
43
|
+
textDecoration: underline
|
|
44
|
+
? "underline"
|
|
45
|
+
: underline === undefined
|
|
46
|
+
? undefined
|
|
47
|
+
: "none",
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const Text = ({ style, children, ...rest }) => {
|
|
37
52
|
const { all } = useLayoutStyle(rest);
|
|
38
53
|
const innerStyle = withPropsStyle(
|
|
39
54
|
{
|
|
40
55
|
...all,
|
|
41
|
-
|
|
42
|
-
fontWeight: bold ? "bold" : undefined,
|
|
43
|
-
fontStyle: italic ? "italic" : undefined,
|
|
44
|
-
fontSize: size,
|
|
45
|
-
textDecoration: underline ? "underline" : undefined,
|
|
56
|
+
...useTypographyStyle(rest),
|
|
46
57
|
},
|
|
47
58
|
style,
|
|
48
59
|
);
|
|
@@ -54,13 +65,12 @@ export const Text = ({
|
|
|
54
65
|
);
|
|
55
66
|
};
|
|
56
67
|
|
|
57
|
-
export const Icon = ({
|
|
68
|
+
export const Icon = ({ style, children, ...rest }) => {
|
|
58
69
|
const { all } = useLayoutStyle(rest);
|
|
59
70
|
const innerStyle = withPropsStyle(
|
|
60
71
|
{
|
|
61
72
|
...all,
|
|
62
|
-
|
|
63
|
-
fontSize: size,
|
|
73
|
+
...useTypographyStyle(rest),
|
|
64
74
|
},
|
|
65
75
|
style,
|
|
66
76
|
);
|
|
@@ -71,10 +71,25 @@ export const REQUIRED_CONSTRAINT = {
|
|
|
71
71
|
: undefined,
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
if (
|
|
75
|
-
return
|
|
74
|
+
if (element.value) {
|
|
75
|
+
return null;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
if (requiredMessage) {
|
|
78
|
+
return requiredMessage;
|
|
79
|
+
}
|
|
80
|
+
if (element.type === "password") {
|
|
81
|
+
return element.hasAttribute("data-same-as")
|
|
82
|
+
? `Veuillez confirmer le mot de passe.`
|
|
83
|
+
: `Veuillez saisir un mot de passe.`;
|
|
84
|
+
}
|
|
85
|
+
if (element.type === "email") {
|
|
86
|
+
return element.hasAttribute("data-same-as")
|
|
87
|
+
? `Veuillez confirmer l'adresse e-mail`
|
|
88
|
+
: `Veuillez saisir une adresse e-mail.`;
|
|
89
|
+
}
|
|
90
|
+
return element.hasAttribute("data-same-as")
|
|
91
|
+
? `Veuillez confirmer le champ précédent`
|
|
92
|
+
: `Veuillez remplir ce champ.`;
|
|
78
93
|
},
|
|
79
94
|
};
|
|
80
95
|
export const PATTERN_CONSTRAINT = {
|
|
@@ -89,19 +104,19 @@ export const PATTERN_CONSTRAINT = {
|
|
|
89
104
|
return null;
|
|
90
105
|
}
|
|
91
106
|
const regex = new RegExp(pattern);
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
if (patternMessage) {
|
|
95
|
-
return patternMessage;
|
|
96
|
-
}
|
|
97
|
-
let message = `Veuillez respecter le format requis.`;
|
|
98
|
-
const title = input.title;
|
|
99
|
-
if (title) {
|
|
100
|
-
message += `<br />${title}`;
|
|
101
|
-
}
|
|
102
|
-
return message;
|
|
107
|
+
if (regex.test(value)) {
|
|
108
|
+
return null;
|
|
103
109
|
}
|
|
104
|
-
|
|
110
|
+
const patternMessage = input.getAttribute("data-pattern-message");
|
|
111
|
+
if (patternMessage) {
|
|
112
|
+
return patternMessage;
|
|
113
|
+
}
|
|
114
|
+
let message = `Veuillez respecter le format requis.`;
|
|
115
|
+
const title = input.title;
|
|
116
|
+
if (title) {
|
|
117
|
+
message += `<br />${title}`;
|
|
118
|
+
}
|
|
119
|
+
return message;
|
|
105
120
|
},
|
|
106
121
|
};
|
|
107
122
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/email#validation
|
|
@@ -149,10 +164,11 @@ export const MIN_LENGTH_CONSTRAINT = {
|
|
|
149
164
|
return null;
|
|
150
165
|
}
|
|
151
166
|
if (valueLength < minLength) {
|
|
167
|
+
const thisField = generateThisFieldText(element);
|
|
152
168
|
if (valueLength === 1) {
|
|
153
|
-
return
|
|
169
|
+
return `${thisField} doit contenir au moins ${minLength} caractère (il contient actuellement un seul caractère).`;
|
|
154
170
|
}
|
|
155
|
-
return
|
|
171
|
+
return `${thisField} doit contenir au moins ${minLength} caractères (il contient actuellement ${valueLength} caractères).`;
|
|
156
172
|
}
|
|
157
173
|
return null;
|
|
158
174
|
},
|
|
@@ -166,6 +182,14 @@ const INPUT_TYPE_SUPPORTING_MIN_LENGTH_SET = new Set([
|
|
|
166
182
|
"password",
|
|
167
183
|
]);
|
|
168
184
|
|
|
185
|
+
const generateThisFieldText = (field) => {
|
|
186
|
+
return field.type === "password"
|
|
187
|
+
? "Ce mot de passe"
|
|
188
|
+
: field.type === "email"
|
|
189
|
+
? "Cette adresse e-mail"
|
|
190
|
+
: "Ce champ";
|
|
191
|
+
};
|
|
192
|
+
|
|
169
193
|
export const MAX_LENGTH_CONSTRAINT = {
|
|
170
194
|
name: "max_length",
|
|
171
195
|
check: (element) => {
|
|
@@ -185,7 +209,8 @@ export const MAX_LENGTH_CONSTRAINT = {
|
|
|
185
209
|
const value = element.value;
|
|
186
210
|
const valueLength = value.length;
|
|
187
211
|
if (valueLength > maxLength) {
|
|
188
|
-
|
|
212
|
+
const thisField = generateThisFieldText(element);
|
|
213
|
+
return `${thisField} doit contenir au maximum ${maxLength} caractères (il contient actuellement ${valueLength} caractères).`;
|
|
189
214
|
}
|
|
190
215
|
return null;
|
|
191
216
|
},
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const SAME_AS_CONSTRAINT = {
|
|
2
|
+
name: "same_as",
|
|
3
|
+
check: (element) => {
|
|
4
|
+
const sameAs = element.getAttribute("data-same-as");
|
|
5
|
+
if (!sameAs) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const otherElement = document.querySelector(sameAs);
|
|
10
|
+
if (!otherElement) {
|
|
11
|
+
console.warn(
|
|
12
|
+
`Same as constraint: could not find element for selector ${sameAs}`,
|
|
13
|
+
);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const value = element.value;
|
|
18
|
+
const otherValue = otherElement.value;
|
|
19
|
+
if (value === "" || otherValue === "") {
|
|
20
|
+
// don't validate if one of the two values is empty
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (value === otherValue) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const message = element.getAttribute("data-same-as-message");
|
|
29
|
+
if (message) {
|
|
30
|
+
return message;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const type = element.type;
|
|
34
|
+
if (type === "password") {
|
|
35
|
+
return `Ce mot de passe doit être identique au précédent.`;
|
|
36
|
+
}
|
|
37
|
+
if (type === "email") {
|
|
38
|
+
return `Cette adresse e-mail doit être identique a la précédente.`;
|
|
39
|
+
}
|
|
40
|
+
return `Ce champ doit être identique au précédent.`;
|
|
41
|
+
},
|
|
42
|
+
};
|