@conform-to/react 0.1.0 → 0.3.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 +551 -6
- package/helpers.d.ts +4 -4
- package/helpers.js +27 -22
- package/hooks.d.ts +114 -35
- package/hooks.js +396 -279
- package/index.d.ts +1 -1
- package/index.js +4 -4
- package/module/helpers.js +27 -22
- package/module/hooks.js +398 -281
- 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 FormState, type FieldsetConstraint, type Schema, type Submission, createSubmission, createValidate, } from '@conform-to/dom';
|
|
2
2
|
export * from './hooks';
|
|
3
3
|
export * as conform from './helpers';
|
package/index.js
CHANGED
|
@@ -8,13 +8,13 @@ var helpers = require('./helpers.js');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Object.defineProperty(exports, '
|
|
11
|
+
Object.defineProperty(exports, 'createSubmission', {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return dom.
|
|
13
|
+
get: function () { return dom.createSubmission; }
|
|
14
14
|
});
|
|
15
|
-
Object.defineProperty(exports, '
|
|
15
|
+
Object.defineProperty(exports, 'createValidate', {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return dom.
|
|
17
|
+
get: function () { return dom.createValidate; }
|
|
18
18
|
});
|
|
19
19
|
exports.useControlledInput = hooks.useControlledInput;
|
|
20
20
|
exports.useFieldList = hooks.useFieldList;
|
package/module/helpers.js
CHANGED
|
@@ -1,48 +1,53 @@
|
|
|
1
1
|
function input(config) {
|
|
2
|
-
var _config$initialValue, _config$constraint, _config$constraint2, _config$constraint3, _config$constraint4, _config$constraint5, _config$constraint6, _config$constraint7;
|
|
3
|
-
|
|
4
2
|
var {
|
|
5
3
|
type,
|
|
6
4
|
value
|
|
7
5
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
6
|
var isCheckboxOrRadio = type === 'checkbox' || type === 'radio';
|
|
9
|
-
|
|
7
|
+
var attributes = {
|
|
10
8
|
type,
|
|
11
9
|
name: config.name,
|
|
12
10
|
form: config.form,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
step: (_config$constraint6 = config.constraint) === null || _config$constraint6 === void 0 ? void 0 : _config$constraint6.step,
|
|
22
|
-
pattern: (_config$constraint7 = config.constraint) === null || _config$constraint7 === void 0 ? void 0 : _config$constraint7.pattern
|
|
11
|
+
required: config.required,
|
|
12
|
+
minLength: config.minLength,
|
|
13
|
+
maxLength: config.maxLength,
|
|
14
|
+
min: config.min,
|
|
15
|
+
max: config.max,
|
|
16
|
+
step: config.step,
|
|
17
|
+
pattern: config.pattern,
|
|
18
|
+
multiple: config.multiple
|
|
23
19
|
};
|
|
20
|
+
|
|
21
|
+
if (isCheckboxOrRadio) {
|
|
22
|
+
attributes.value = value !== null && value !== void 0 ? value : 'on';
|
|
23
|
+
attributes.defaultChecked = config.defaultValue === attributes.value;
|
|
24
|
+
} else {
|
|
25
|
+
attributes.defaultValue = config.defaultValue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return attributes;
|
|
24
29
|
}
|
|
25
30
|
function select(config) {
|
|
26
|
-
var _config$
|
|
31
|
+
var _config$defaultValue;
|
|
27
32
|
|
|
28
33
|
return {
|
|
29
34
|
name: config.name,
|
|
30
35
|
form: config.form,
|
|
31
|
-
defaultValue: "".concat((_config$
|
|
32
|
-
required:
|
|
33
|
-
multiple:
|
|
36
|
+
defaultValue: config.multiple ? Array.isArray(config.defaultValue) ? config.defaultValue : [] : "".concat((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : ''),
|
|
37
|
+
required: config.required,
|
|
38
|
+
multiple: config.multiple
|
|
34
39
|
};
|
|
35
40
|
}
|
|
36
41
|
function textarea(config) {
|
|
37
|
-
var _config$
|
|
42
|
+
var _config$defaultValue2;
|
|
38
43
|
|
|
39
44
|
return {
|
|
40
45
|
name: config.name,
|
|
41
46
|
form: config.form,
|
|
42
|
-
defaultValue: "".concat((_config$
|
|
43
|
-
required:
|
|
44
|
-
minLength:
|
|
45
|
-
maxLength:
|
|
47
|
+
defaultValue: "".concat((_config$defaultValue2 = config.defaultValue) !== null && _config$defaultValue2 !== void 0 ? _config$defaultValue2 : ''),
|
|
48
|
+
required: config.required,
|
|
49
|
+
minLength: config.minLength,
|
|
50
|
+
maxLength: config.maxLength
|
|
46
51
|
};
|
|
47
52
|
}
|
|
48
53
|
|