@conform-to/react 0.3.0 → 0.4.0-pre.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/README.md +99 -48
- package/helpers.js +20 -3
- package/hooks.d.ts +36 -12
- package/hooks.js +342 -160
- package/index.d.ts +1 -1
- package/index.js +12 -4
- package/module/helpers.js +20 -3
- package/module/hooks.js +343 -161
- package/module/index.js +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { type
|
|
1
|
+
export { type FieldsetConstraint, type FormState, type Submission, hasError, isFieldElement, parse, reportValidity, } from '@conform-to/dom';
|
|
2
2
|
export * from './hooks';
|
|
3
3
|
export * as conform from './helpers';
|
package/index.js
CHANGED
|
@@ -8,13 +8,21 @@ var helpers = require('./helpers.js');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Object.defineProperty(exports, '
|
|
11
|
+
Object.defineProperty(exports, 'hasError', {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return dom.
|
|
13
|
+
get: function () { return dom.hasError; }
|
|
14
14
|
});
|
|
15
|
-
Object.defineProperty(exports, '
|
|
15
|
+
Object.defineProperty(exports, 'isFieldElement', {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return dom.
|
|
17
|
+
get: function () { return dom.isFieldElement; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, 'parse', {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return dom.parse; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, 'reportValidity', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return dom.reportValidity; }
|
|
18
26
|
});
|
|
19
27
|
exports.useControlledInput = hooks.useControlledInput;
|
|
20
28
|
exports.useFieldList = hooks.useFieldList;
|
package/module/helpers.js
CHANGED
|
@@ -18,6 +18,10 @@ function input(config) {
|
|
|
18
18
|
multiple: config.multiple
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
if (config.initialError && config.initialError.length > 0) {
|
|
22
|
+
attributes.autoFocus = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
if (isCheckboxOrRadio) {
|
|
22
26
|
attributes.value = value !== null && value !== void 0 ? value : 'on';
|
|
23
27
|
attributes.defaultChecked = config.defaultValue === attributes.value;
|
|
@@ -30,25 +34,38 @@ function input(config) {
|
|
|
30
34
|
function select(config) {
|
|
31
35
|
var _config$defaultValue;
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
var attributes = {
|
|
34
38
|
name: config.name,
|
|
35
39
|
form: config.form,
|
|
36
40
|
defaultValue: config.multiple ? Array.isArray(config.defaultValue) ? config.defaultValue : [] : "".concat((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : ''),
|
|
37
41
|
required: config.required,
|
|
38
42
|
multiple: config.multiple
|
|
39
43
|
};
|
|
44
|
+
|
|
45
|
+
if (config.initialError && config.initialError.length > 0) {
|
|
46
|
+
attributes.autoFocus = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return attributes;
|
|
40
50
|
}
|
|
41
51
|
function textarea(config) {
|
|
42
52
|
var _config$defaultValue2;
|
|
43
53
|
|
|
44
|
-
|
|
54
|
+
var attributes = {
|
|
45
55
|
name: config.name,
|
|
46
56
|
form: config.form,
|
|
47
57
|
defaultValue: "".concat((_config$defaultValue2 = config.defaultValue) !== null && _config$defaultValue2 !== void 0 ? _config$defaultValue2 : ''),
|
|
48
58
|
required: config.required,
|
|
49
59
|
minLength: config.minLength,
|
|
50
|
-
maxLength: config.maxLength
|
|
60
|
+
maxLength: config.maxLength,
|
|
61
|
+
autoFocus: Boolean(config.initialError)
|
|
51
62
|
};
|
|
63
|
+
|
|
64
|
+
if (config.initialError && config.initialError.length > 0) {
|
|
65
|
+
attributes.autoFocus = true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return attributes;
|
|
52
69
|
}
|
|
53
70
|
|
|
54
71
|
export { input, select, textarea };
|