@conform-to/react 0.1.0 → 0.1.1
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/helpers.d.ts +1 -1
- package/helpers.js +13 -5
- package/hooks.js +0 -1
- package/module/helpers.js +13 -5
- package/module/hooks.js +0 -1
- package/package.json +2 -2
package/helpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FieldConfig } from '@conform-to/dom';
|
|
2
2
|
import { type InputHTMLAttributes, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react';
|
|
3
|
-
export declare function input<Type extends string | number | Date | undefined>(config: FieldConfig<Type>, { type, value }?: {
|
|
3
|
+
export declare function input<Type extends string | number | Date | boolean | undefined>(config: FieldConfig<Type>, { type, value }?: {
|
|
4
4
|
type?: string;
|
|
5
5
|
value?: string;
|
|
6
6
|
}): InputHTMLAttributes<HTMLInputElement>;
|
package/helpers.js
CHANGED
|
@@ -3,20 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
function input(config) {
|
|
6
|
-
var _config$
|
|
6
|
+
var _config$constraint, _config$constraint2, _config$constraint3, _config$constraint4, _config$constraint5, _config$constraint6, _config$constraint7;
|
|
7
7
|
|
|
8
8
|
var {
|
|
9
9
|
type,
|
|
10
10
|
value
|
|
11
11
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
12
12
|
var isCheckboxOrRadio = type === 'checkbox' || type === 'radio';
|
|
13
|
-
|
|
13
|
+
var attributes = {
|
|
14
14
|
type,
|
|
15
15
|
name: config.name,
|
|
16
16
|
form: config.form,
|
|
17
|
-
value: isCheckboxOrRadio ? value : undefined,
|
|
18
|
-
defaultValue: !isCheckboxOrRadio ? "".concat((_config$initialValue = config.initialValue) !== null && _config$initialValue !== void 0 ? _config$initialValue : '') : undefined,
|
|
19
|
-
defaultChecked: isCheckboxOrRadio ? config.initialValue === value : undefined,
|
|
20
17
|
required: (_config$constraint = config.constraint) === null || _config$constraint === void 0 ? void 0 : _config$constraint.required,
|
|
21
18
|
minLength: (_config$constraint2 = config.constraint) === null || _config$constraint2 === void 0 ? void 0 : _config$constraint2.minLength,
|
|
22
19
|
maxLength: (_config$constraint3 = config.constraint) === null || _config$constraint3 === void 0 ? void 0 : _config$constraint3.maxLength,
|
|
@@ -25,6 +22,17 @@ function input(config) {
|
|
|
25
22
|
step: (_config$constraint6 = config.constraint) === null || _config$constraint6 === void 0 ? void 0 : _config$constraint6.step,
|
|
26
23
|
pattern: (_config$constraint7 = config.constraint) === null || _config$constraint7 === void 0 ? void 0 : _config$constraint7.pattern
|
|
27
24
|
};
|
|
25
|
+
|
|
26
|
+
if (isCheckboxOrRadio) {
|
|
27
|
+
attributes.value = value !== null && value !== void 0 ? value : 'on';
|
|
28
|
+
attributes.defaultChecked = config.initialValue === attributes.value;
|
|
29
|
+
} else {
|
|
30
|
+
var _config$initialValue;
|
|
31
|
+
|
|
32
|
+
attributes.defaultValue = "".concat((_config$initialValue = config.initialValue) !== null && _config$initialValue !== void 0 ? _config$initialValue : '');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return attributes;
|
|
28
36
|
}
|
|
29
37
|
function select(config) {
|
|
30
38
|
var _config$initialValue2, _config$constraint8, _config$constraint9;
|
package/hooks.js
CHANGED
|
@@ -277,7 +277,6 @@ function useFieldList(config) {
|
|
|
277
277
|
name: "".concat(config.name, "[").concat(index, "]"),
|
|
278
278
|
initialValue: (_config$initialValue2 = config.initialValue) === null || _config$initialValue2 === void 0 ? void 0 : _config$initialValue2[index],
|
|
279
279
|
error: (_config$error2 = config.error) === null || _config$error2 === void 0 ? void 0 : _config$error2[index],
|
|
280
|
-
// @ts-expect-error
|
|
281
280
|
constraint: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, config.constraint), {}, {
|
|
282
281
|
multiple: false
|
|
283
282
|
})
|
package/module/helpers.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
function input(config) {
|
|
2
|
-
var _config$
|
|
2
|
+
var _config$constraint, _config$constraint2, _config$constraint3, _config$constraint4, _config$constraint5, _config$constraint6, _config$constraint7;
|
|
3
3
|
|
|
4
4
|
var {
|
|
5
5
|
type,
|
|
6
6
|
value
|
|
7
7
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
8
|
var isCheckboxOrRadio = type === 'checkbox' || type === 'radio';
|
|
9
|
-
|
|
9
|
+
var attributes = {
|
|
10
10
|
type,
|
|
11
11
|
name: config.name,
|
|
12
12
|
form: config.form,
|
|
13
|
-
value: isCheckboxOrRadio ? value : undefined,
|
|
14
|
-
defaultValue: !isCheckboxOrRadio ? "".concat((_config$initialValue = config.initialValue) !== null && _config$initialValue !== void 0 ? _config$initialValue : '') : undefined,
|
|
15
|
-
defaultChecked: isCheckboxOrRadio ? config.initialValue === value : undefined,
|
|
16
13
|
required: (_config$constraint = config.constraint) === null || _config$constraint === void 0 ? void 0 : _config$constraint.required,
|
|
17
14
|
minLength: (_config$constraint2 = config.constraint) === null || _config$constraint2 === void 0 ? void 0 : _config$constraint2.minLength,
|
|
18
15
|
maxLength: (_config$constraint3 = config.constraint) === null || _config$constraint3 === void 0 ? void 0 : _config$constraint3.maxLength,
|
|
@@ -21,6 +18,17 @@ function input(config) {
|
|
|
21
18
|
step: (_config$constraint6 = config.constraint) === null || _config$constraint6 === void 0 ? void 0 : _config$constraint6.step,
|
|
22
19
|
pattern: (_config$constraint7 = config.constraint) === null || _config$constraint7 === void 0 ? void 0 : _config$constraint7.pattern
|
|
23
20
|
};
|
|
21
|
+
|
|
22
|
+
if (isCheckboxOrRadio) {
|
|
23
|
+
attributes.value = value !== null && value !== void 0 ? value : 'on';
|
|
24
|
+
attributes.defaultChecked = config.initialValue === attributes.value;
|
|
25
|
+
} else {
|
|
26
|
+
var _config$initialValue;
|
|
27
|
+
|
|
28
|
+
attributes.defaultValue = "".concat((_config$initialValue = config.initialValue) !== null && _config$initialValue !== void 0 ? _config$initialValue : '');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return attributes;
|
|
24
32
|
}
|
|
25
33
|
function select(config) {
|
|
26
34
|
var _config$initialValue2, _config$constraint8, _config$constraint9;
|
package/module/hooks.js
CHANGED
|
@@ -273,7 +273,6 @@ function useFieldList(config) {
|
|
|
273
273
|
name: "".concat(config.name, "[").concat(index, "]"),
|
|
274
274
|
initialValue: (_config$initialValue2 = config.initialValue) === null || _config$initialValue2 === void 0 ? void 0 : _config$initialValue2[index],
|
|
275
275
|
error: (_config$error2 = config.error) === null || _config$error2 === void 0 ? void 0 : _config$error2[index],
|
|
276
|
-
// @ts-expect-error
|
|
277
276
|
constraint: _objectSpread2(_objectSpread2({}, config.constraint), {}, {
|
|
278
277
|
multiple: false
|
|
279
278
|
})
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@conform-to/react",
|
|
3
3
|
"description": "Conform view adapter for react",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.1",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "module/index.js",
|
|
8
8
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "https://github.com/edmundhung/conform/issues"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@conform-to/dom": "0.1.
|
|
22
|
+
"@conform-to/dom": "0.1.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": ">=16.8"
|