@formality-ui/react 0.3.1 → 0.4.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 +2 -2
- package/dist/index.cjs +44 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +45 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -67,8 +67,8 @@ function App() {
|
|
|
67
67
|
return (
|
|
68
68
|
<FormalityProvider inputs={inputs}>
|
|
69
69
|
<Form config={config} onSubmit={(values) => console.log(values)}>
|
|
70
|
-
{({
|
|
71
|
-
<form onSubmit={
|
|
70
|
+
{({ handleSubmit }) => (
|
|
71
|
+
<form onSubmit={handleSubmit(console.log)}>
|
|
72
72
|
<Field name="name" />
|
|
73
73
|
<Field name="email" />
|
|
74
74
|
<Field name="subscribed" />
|
package/dist/index.cjs
CHANGED
|
@@ -279,7 +279,11 @@ function Form({
|
|
|
279
279
|
for (const field of affected) {
|
|
280
280
|
pendingAffectedFields.current.add(field);
|
|
281
281
|
}
|
|
282
|
-
const
|
|
282
|
+
const fieldConfig = config[name];
|
|
283
|
+
const fieldDebounce = core.resolveFieldOverType(
|
|
284
|
+
fieldConfig?.debounce,
|
|
285
|
+
inputConfig?.debounce
|
|
286
|
+
);
|
|
283
287
|
if (fieldDebounce === false) {
|
|
284
288
|
executeAutoSaveRef.current?.();
|
|
285
289
|
} else if (typeof fieldDebounce === "number") {
|
|
@@ -289,7 +293,7 @@ function Form({
|
|
|
289
293
|
}
|
|
290
294
|
}
|
|
291
295
|
},
|
|
292
|
-
[autoSave, getAffectedFields]
|
|
296
|
+
[autoSave, getAffectedFields, config]
|
|
293
297
|
);
|
|
294
298
|
const setFieldValidating = react.useCallback(
|
|
295
299
|
(name, isValidating) => {
|
|
@@ -593,13 +597,17 @@ function transformValuesForSubmit(values, config, inputs) {
|
|
|
593
597
|
const fieldConfig = config[name];
|
|
594
598
|
const type = fieldConfig?.type ?? "textField";
|
|
595
599
|
const inputConfig = inputs[type];
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
600
|
+
const effectiveGetSubmitField = core.resolveFieldOverType(
|
|
601
|
+
fieldConfig?.getSubmitField,
|
|
602
|
+
inputConfig?.getSubmitField
|
|
603
|
+
);
|
|
604
|
+
const effectiveValueField = core.resolveFieldOverType(
|
|
605
|
+
fieldConfig?.valueField,
|
|
606
|
+
inputConfig?.valueField
|
|
607
|
+
);
|
|
608
|
+
const submitName = core.transformFieldName(name, effectiveGetSubmitField);
|
|
609
|
+
const submitValue = core.extractValueField(value, effectiveValueField);
|
|
610
|
+
result[submitName] = submitValue;
|
|
603
611
|
}
|
|
604
612
|
return result;
|
|
605
613
|
}
|
|
@@ -1076,8 +1084,22 @@ function useField({
|
|
|
1076
1084
|
groupContext.state.isVisible
|
|
1077
1085
|
]);
|
|
1078
1086
|
const label = react.useMemo(() => {
|
|
1079
|
-
return core.resolveLabel(
|
|
1080
|
-
|
|
1087
|
+
return core.resolveLabel(
|
|
1088
|
+
name,
|
|
1089
|
+
fieldConfig,
|
|
1090
|
+
fieldSelectProps,
|
|
1091
|
+
restProps,
|
|
1092
|
+
providerSelectProps,
|
|
1093
|
+
formSelectProps
|
|
1094
|
+
);
|
|
1095
|
+
}, [
|
|
1096
|
+
name,
|
|
1097
|
+
fieldConfig,
|
|
1098
|
+
fieldSelectProps,
|
|
1099
|
+
restProps,
|
|
1100
|
+
providerSelectProps,
|
|
1101
|
+
formSelectProps
|
|
1102
|
+
]);
|
|
1081
1103
|
const passSubscriptionsEnabled = fieldConfig.passSubscriptions === true;
|
|
1082
1104
|
const provideStateEnabled = fieldConfig.provideState === true;
|
|
1083
1105
|
const subscribedWatchNames = react.useMemo(
|
|
@@ -1156,23 +1178,25 @@ function useField({
|
|
|
1156
1178
|
name,
|
|
1157
1179
|
setFieldValidating
|
|
1158
1180
|
]);
|
|
1181
|
+
const effectiveParser = react.useMemo(
|
|
1182
|
+
() => core.resolveFieldOverType(fieldConfig.parser, inputConfig.parser),
|
|
1183
|
+
[fieldConfig.parser, inputConfig.parser]
|
|
1184
|
+
);
|
|
1185
|
+
const effectiveFormatter = react.useMemo(
|
|
1186
|
+
() => core.resolveFieldOverType(fieldConfig.formatter, inputConfig.formatter),
|
|
1187
|
+
[fieldConfig.formatter, inputConfig.formatter]
|
|
1188
|
+
);
|
|
1159
1189
|
const handleChange = react.useCallback(
|
|
1160
1190
|
(onChange) => (newValue) => {
|
|
1161
1191
|
const parsedValue = core.parse(
|
|
1162
1192
|
newValue,
|
|
1163
|
-
|
|
1193
|
+
effectiveParser,
|
|
1164
1194
|
providerConfig.parsers
|
|
1165
1195
|
);
|
|
1166
1196
|
onChange(parsedValue);
|
|
1167
1197
|
changeField(name, parsedValue, inputConfig);
|
|
1168
1198
|
},
|
|
1169
|
-
[
|
|
1170
|
-
inputConfig.parser,
|
|
1171
|
-
providerConfig.parsers,
|
|
1172
|
-
changeField,
|
|
1173
|
-
name,
|
|
1174
|
-
inputConfig
|
|
1175
|
-
]
|
|
1199
|
+
[effectiveParser, providerConfig.parsers, changeField, name, inputConfig]
|
|
1176
1200
|
);
|
|
1177
1201
|
const fieldStateRef = react.useRef(
|
|
1178
1202
|
{}
|
|
@@ -1190,7 +1214,7 @@ function useField({
|
|
|
1190
1214
|
render: ({ field, fieldState, formState }) => {
|
|
1191
1215
|
const formattedValue = core.format(
|
|
1192
1216
|
field.value,
|
|
1193
|
-
|
|
1217
|
+
effectiveFormatter,
|
|
1194
1218
|
providerConfig.formatters
|
|
1195
1219
|
);
|
|
1196
1220
|
const stateInjection = {};
|