@juantroconisf/lib 3.1.3 → 3.1.5
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -5
- package/dist/index.mjs +12 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -55,7 +55,7 @@ type GetValidationResponse = {
|
|
|
55
55
|
isValid: boolean;
|
|
56
56
|
validationProps: NextUIError;
|
|
57
57
|
};
|
|
58
|
-
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types
|
|
58
|
+
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types?: ValidatorParams, errorMessages?: ValidatorErrorMessage) => GetValidationResponse;
|
|
59
59
|
interface UseValidationFunc {
|
|
60
60
|
getValidation: GetValidationFunc<unknown>;
|
|
61
61
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ type GetValidationResponse = {
|
|
|
55
55
|
isValid: boolean;
|
|
56
56
|
validationProps: NextUIError;
|
|
57
57
|
};
|
|
58
|
-
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types
|
|
58
|
+
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types?: ValidatorParams, errorMessages?: ValidatorErrorMessage) => GetValidationResponse;
|
|
59
59
|
interface UseValidationFunc {
|
|
60
60
|
getValidation: GetValidationFunc<unknown>;
|
|
61
61
|
}
|
package/dist/index.js
CHANGED
|
@@ -153,6 +153,7 @@ function useComponentLanguage() {
|
|
|
153
153
|
function useValidation() {
|
|
154
154
|
const { lang } = useComponentLanguage();
|
|
155
155
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
156
|
+
if (!types) return { isValid: true, validationProps: nxError() };
|
|
156
157
|
const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
|
|
157
158
|
if (value === "" && !isRequired || !isTouched)
|
|
158
159
|
return { isValid: true, validationProps: nxError() };
|
|
@@ -230,11 +231,17 @@ function useFormChange({
|
|
|
230
231
|
onValueChange: (v) => onValueChange(id, v),
|
|
231
232
|
value: state[id]
|
|
232
233
|
}),
|
|
233
|
-
select: (id) =>
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
select: (id) => {
|
|
235
|
+
const isString = typeof state[id] === "string";
|
|
236
|
+
return {
|
|
237
|
+
...registerHandle(id),
|
|
238
|
+
onSelectionChange: (v) => onSelectionChange(
|
|
239
|
+
id,
|
|
240
|
+
isString ? v.currentKey : v
|
|
241
|
+
),
|
|
242
|
+
selectedKeys: isString ? [state[id]] : state[id]
|
|
243
|
+
};
|
|
244
|
+
}
|
|
238
245
|
}),
|
|
239
246
|
[registerHandle]
|
|
240
247
|
),
|
package/dist/index.mjs
CHANGED
|
@@ -134,6 +134,7 @@ function useComponentLanguage() {
|
|
|
134
134
|
function useValidation() {
|
|
135
135
|
const { lang } = useComponentLanguage();
|
|
136
136
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
137
|
+
if (!types) return { isValid: true, validationProps: nxError() };
|
|
137
138
|
const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
|
|
138
139
|
if (value === "" && !isRequired || !isTouched)
|
|
139
140
|
return { isValid: true, validationProps: nxError() };
|
|
@@ -211,11 +212,17 @@ function useFormChange({
|
|
|
211
212
|
onValueChange: (v) => onValueChange(id, v),
|
|
212
213
|
value: state[id]
|
|
213
214
|
}),
|
|
214
|
-
select: (id) =>
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
select: (id) => {
|
|
216
|
+
const isString = typeof state[id] === "string";
|
|
217
|
+
return {
|
|
218
|
+
...registerHandle(id),
|
|
219
|
+
onSelectionChange: (v) => onSelectionChange(
|
|
220
|
+
id,
|
|
221
|
+
isString ? v.currentKey : v
|
|
222
|
+
),
|
|
223
|
+
selectedKeys: isString ? [state[id]] : state[id]
|
|
224
|
+
};
|
|
225
|
+
}
|
|
219
226
|
}),
|
|
220
227
|
[registerHandle]
|
|
221
228
|
),
|