@apia/validations 0.1.3 → 0.2.4
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.ts +96 -33
- package/dist/index.js +2229 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
3
|
import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration } from '@apia/util';
|
|
4
|
-
import { BoxProps, ButtonProps, InputProps,
|
|
4
|
+
import { BoxProps, ButtonProps, InputProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@apia/theme';
|
|
5
5
|
import { TNumberInput } from '@apia/components';
|
|
6
6
|
|
|
7
7
|
declare const formcheckLanguage: {
|
|
@@ -34,11 +34,6 @@ declare const formcheckLanguage: {
|
|
|
34
34
|
errorsTitle: string;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
declare global {
|
|
38
|
-
interface Window {
|
|
39
|
-
[key: string]: string;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
37
|
type TValidate = Partial<TModify<Record<keyof typeof formcheckLanguage, boolean>, {
|
|
43
38
|
digitmin: number;
|
|
44
39
|
digitltd: [number, number];
|
|
@@ -175,7 +170,7 @@ interface IForm<ValueType extends Record<string, unknown>, SubmitValueType exten
|
|
|
175
170
|
* Impide que se apliquen los estilos que indican que un campo fue alterado.
|
|
176
171
|
*/
|
|
177
172
|
avoidFieldsTouch?: boolean;
|
|
178
|
-
children:
|
|
173
|
+
children: React__default.ReactNode;
|
|
179
174
|
className?: string;
|
|
180
175
|
initialValues?: Partial<ValueType>;
|
|
181
176
|
name?: string;
|
|
@@ -192,14 +187,67 @@ interface IForm<ValueType extends Record<string, unknown>, SubmitValueType exten
|
|
|
192
187
|
*/
|
|
193
188
|
unregisterOnUnmount?: boolean;
|
|
194
189
|
}
|
|
195
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Cuando se desea usar el sistema de validación,
|
|
192
|
+
* se debe utilizar este componente como form contenedor
|
|
193
|
+
* de todos los campos que quieran validarse.
|
|
194
|
+
*
|
|
195
|
+
* Es importante que no se coloquen formularios dentro
|
|
196
|
+
* de formularios ya que esto podría afectar negativamente
|
|
197
|
+
* el proceso de validación.
|
|
198
|
+
*
|
|
199
|
+
* @props
|
|
200
|
+
* *name:* Se puede pasar un nombre para identificar
|
|
201
|
+
* el form. Este nombre será utilizado para almacenar
|
|
202
|
+
* la información en Redux, por lo que si se desea
|
|
203
|
+
* acceder a la información recolectada por la librería,
|
|
204
|
+
* es conveniente pasar un nombre conocido y único. En
|
|
205
|
+
* caso de no se pase ningún nombre, la aplicación
|
|
206
|
+
* generará un nombre único automaticamente.
|
|
207
|
+
*
|
|
208
|
+
* *onValidate:* Un callback que será llamado cuando
|
|
209
|
+
* se invoque el método validateForm del store o cuando
|
|
210
|
+
* se lance el evento de submit del elemento form (por
|
|
211
|
+
* ejemplo mediante un click en un botón que no tenga
|
|
212
|
+
* type="button"), con el resultado de la validación.
|
|
213
|
+
*
|
|
214
|
+
* avoidFieldsOverride
|
|
215
|
+
* avoidFieldsTouch
|
|
216
|
+
*
|
|
217
|
+
* @see useField
|
|
218
|
+
* @see useForm
|
|
219
|
+
*
|
|
220
|
+
* @important Debido a que este hook renderiza un elemento
|
|
221
|
+
* form en el DOM, es importante agregar el atributo
|
|
222
|
+
* type="button" a todos los botones dentro del formulario
|
|
223
|
+
* que no se desea que disparen la validación.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* Para ver un ejemplo funcional, mira el componente
|
|
227
|
+
* Invitations.tsx
|
|
228
|
+
*
|
|
229
|
+
* // IMPORTANTE: El tipado del componente Form es genérico
|
|
230
|
+
* // por lo que es posible instanciarlo como se muestra a
|
|
231
|
+
* // continuación, lo que nos da el tipado correcto en el
|
|
232
|
+
* // callback onValidate.
|
|
233
|
+
* <Form<FormDataType> onValidate={(res) => {
|
|
234
|
+
* if(hasSucceedValidation(res)) {
|
|
235
|
+
* // Do something with submitValues
|
|
236
|
+
* } else {
|
|
237
|
+
* // Do something with errors
|
|
238
|
+
* }
|
|
239
|
+
* }}>
|
|
240
|
+
* ...{children}
|
|
241
|
+
* </Form>
|
|
242
|
+
*/
|
|
243
|
+
declare const Form: <ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>({ avoidFieldsOverride, avoidFieldsTouch, children, className, name, initialValues, onUnmount, onValidate, unregisterOnUnmount, }: IForm<ValueType, SubmitValueType>) => React__default.JSX.Element | null;
|
|
196
244
|
|
|
197
245
|
interface IFormContext<ValueType extends Record<string, unknown> = Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> {
|
|
198
246
|
avoidFieldsTouch?: boolean;
|
|
199
247
|
name: string;
|
|
200
248
|
validate: () => Promise<TValidationResult<ValueType, SubmitValueType>>;
|
|
201
249
|
}
|
|
202
|
-
declare const FormContext:
|
|
250
|
+
declare const FormContext: React__default.Context<IFormContext<Record<string, unknown>, Record<string, unknown>>>;
|
|
203
251
|
/**
|
|
204
252
|
* Provee acceso de forma sencilla al contexto de
|
|
205
253
|
* validación, que básicamente posee el nombre del
|
|
@@ -216,6 +264,11 @@ declare const FormContext: React.Context<IFormContext<Record<string, unknown>, R
|
|
|
216
264
|
*/
|
|
217
265
|
declare function useFormContext(): IFormContext<Record<string, unknown>, Record<string, unknown>>;
|
|
218
266
|
|
|
267
|
+
declare global {
|
|
268
|
+
interface Window {
|
|
269
|
+
MSG_WRONG_VALIDATION_NO_FOCUSED_FILE: string;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
219
272
|
declare const validationsStore: {
|
|
220
273
|
activeForms: string[];
|
|
221
274
|
timeouts: Record<string, ReturnType<typeof setTimeout> | true>;
|
|
@@ -318,6 +371,13 @@ declare function useFormSelector<Selected = any>(formName: string, selector: TPr
|
|
|
318
371
|
declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, selector?: TPropsSelector<Selected, TValidationField<ValueType, SubmitValueType>>, comparator?: TPropsComparator<Selected>): Selected;
|
|
319
372
|
declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, configurator?: TPropsConfiguration<Selected, TValidationField<ValueType, SubmitValueType>>): Selected;
|
|
320
373
|
|
|
374
|
+
declare global {
|
|
375
|
+
interface Window {
|
|
376
|
+
NO_LANGUAGE_EXCEPTION: string;
|
|
377
|
+
MSG_INVALID_REG_EXP: string;
|
|
378
|
+
GNR_INVALID_NAME: string;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
321
381
|
/**
|
|
322
382
|
* Determina si la validación de un campo resultó exitosa.
|
|
323
383
|
*/
|
|
@@ -403,20 +463,25 @@ declare function useField<ValueType = unknown, SubmitValueType = ValueType>(fiel
|
|
|
403
463
|
error: string | null | undefined;
|
|
404
464
|
isTouched: boolean;
|
|
405
465
|
name: string;
|
|
406
|
-
onChange: (ev:
|
|
466
|
+
onChange: (ev: React__default.ChangeEvent | ValueType) => void;
|
|
407
467
|
updateValidations: ({ validationFunction, validationRules, }: Pick<TValidationField, 'validationRules' | 'validationFunction'>) => void;
|
|
408
468
|
value: ValueType;
|
|
409
469
|
};
|
|
410
470
|
|
|
471
|
+
declare global {
|
|
472
|
+
interface Window {
|
|
473
|
+
SHOW_REQUIRED_POSITION: string;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
411
476
|
interface IWrapper extends BoxProps {
|
|
412
477
|
avoidSemicolon?: boolean;
|
|
413
|
-
children:
|
|
478
|
+
children: React__default.ReactNode;
|
|
414
479
|
label?: string;
|
|
415
480
|
name: string;
|
|
416
481
|
required?: boolean;
|
|
417
482
|
type?: 'checkbox';
|
|
418
483
|
}
|
|
419
|
-
declare const FieldWrapper: ({ name, label, avoidSemicolon, children, className, as, type, ...props }: IWrapper) =>
|
|
484
|
+
declare const FieldWrapper: ({ name, label, avoidSemicolon, children, className, as, type, ...props }: IWrapper) => React__default.JSX.Element;
|
|
420
485
|
|
|
421
486
|
type TDefaultFieldType<ValueType = string> = Omit<TUseField<ValueType>, 'error' | 'value' | 'isTouched'> & {
|
|
422
487
|
label?: string;
|
|
@@ -430,31 +495,29 @@ type TCaptchaProps = {
|
|
|
430
495
|
className?: string;
|
|
431
496
|
};
|
|
432
497
|
type TCaptcha = TCaptchaProps & Omit<TDefaultFieldType, 'validationFunction' | 'validationRules' | 'validationClass'>;
|
|
433
|
-
declare const InnerCaptcha: ({ className, name, imageUrl, avoidRegisterIfExists, avoidSemicolon, formName, label, removeOnUnmount, submitName, submitValueParser, validationValueParser, }: TCaptcha) =>
|
|
498
|
+
declare const InnerCaptcha: ({ className, name, imageUrl, avoidRegisterIfExists, avoidSemicolon, formName, label, removeOnUnmount, submitName, submitValueParser, validationValueParser, }: TCaptcha) => React__default.JSX.Element;
|
|
434
499
|
|
|
435
500
|
type TCheckbox = Omit<ButtonProps, 'onChange'> & Omit<Pick<InputProps, 'onChange'>, 'value'> & TDefaultFieldType<boolean | string> & {
|
|
436
501
|
native?: boolean;
|
|
437
502
|
};
|
|
438
|
-
declare const Checkbox:
|
|
503
|
+
declare const Checkbox: React__default.ForwardRefExoticComponent<Omit<TCheckbox, "ref"> & React__default.RefAttributes<HTMLButtonElement>>;
|
|
439
504
|
|
|
440
505
|
type TDeletableInput = InputProps & TDefaultFieldType;
|
|
441
|
-
declare const DeletableInput:
|
|
442
|
-
|
|
443
|
-
type TFieldLabel = LabelProps & {
|
|
444
|
-
avoidSemicolon?: boolean;
|
|
445
|
-
children?: React.ReactNode;
|
|
446
|
-
required?: boolean;
|
|
447
|
-
};
|
|
448
|
-
declare const FieldLabel: ({ avoidSemicolon, children, required, ...props }: TFieldLabel) => theme_ui_jsx_runtime.JSX.Element;
|
|
506
|
+
declare const DeletableInput: React__default.ForwardRefExoticComponent<Omit<TDeletableInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
|
|
449
507
|
|
|
450
508
|
type TFileInput = Omit<InputProps, 'onChange' | 'type' | 'value' | 'multiple'> & TDefaultFieldType<File | null> & Pick<TUseField, 'removeOnUnmount'> & Pick<IWrapper, 'avoidSemicolon'>;
|
|
451
|
-
declare const FileInput:
|
|
509
|
+
declare const FileInput: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TFileInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
|
|
452
510
|
|
|
453
511
|
type TInput$1 = InputProps & TDefaultFieldType;
|
|
454
|
-
declare const Input:
|
|
512
|
+
declare const Input: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TInput$1, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
|
|
455
513
|
|
|
514
|
+
declare global {
|
|
515
|
+
interface Window {
|
|
516
|
+
GNR_NUMERIC: string;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
456
519
|
type TInput = TNumberInput & TDefaultFieldType;
|
|
457
|
-
declare const NumberInputf:
|
|
520
|
+
declare const NumberInputf: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
|
|
458
521
|
|
|
459
522
|
type TRadio = RadioProps & TDefaultFieldType & {
|
|
460
523
|
options: {
|
|
@@ -462,7 +525,7 @@ type TRadio = RadioProps & TDefaultFieldType & {
|
|
|
462
525
|
label: string;
|
|
463
526
|
}[];
|
|
464
527
|
};
|
|
465
|
-
declare const Radio:
|
|
528
|
+
declare const Radio: React__default.ForwardRefExoticComponent<Omit<TRadio, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
|
|
466
529
|
|
|
467
530
|
type TSelect = Omit<SelectProps, 'defaultValue'> & TDefaultFieldType & {
|
|
468
531
|
options: {
|
|
@@ -470,15 +533,15 @@ type TSelect = Omit<SelectProps, 'defaultValue'> & TDefaultFieldType & {
|
|
|
470
533
|
label: string;
|
|
471
534
|
}[];
|
|
472
535
|
};
|
|
473
|
-
declare const Select:
|
|
536
|
+
declare const Select: React__default.ForwardRefExoticComponent<Omit<TSelect, "ref"> & React__default.RefAttributes<HTMLSelectElement>>;
|
|
474
537
|
|
|
475
538
|
type TSwitchbox = Omit<SwitchProps, 'onChange'> & Pick<InputProps, 'onChange'> & TDefaultFieldType & {
|
|
476
539
|
reverse?: boolean;
|
|
477
540
|
};
|
|
478
|
-
declare const Switchbox:
|
|
541
|
+
declare const Switchbox: React__default.ForwardRefExoticComponent<Omit<TSwitchbox, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
|
|
479
542
|
|
|
480
543
|
type TTextarea = TextareaProps & TDefaultFieldType;
|
|
481
|
-
declare const Textarea:
|
|
544
|
+
declare const Textarea: React__default.ForwardRefExoticComponent<Omit<TTextarea, "ref"> & React__default.RefAttributes<HTMLTextAreaElement>>;
|
|
482
545
|
|
|
483
546
|
/**
|
|
484
547
|
* Renderiza los errores del campo con el nombre pasado
|
|
@@ -491,7 +554,7 @@ declare const Textarea: React.ForwardRefExoticComponent<Omit<TTextarea, "ref"> &
|
|
|
491
554
|
*/
|
|
492
555
|
declare const ValidationError: ({ name }: {
|
|
493
556
|
name: string;
|
|
494
|
-
}) =>
|
|
557
|
+
}) => React.JSX.Element | null;
|
|
495
558
|
|
|
496
559
|
declare function useFieldStatesClassNames<T = unknown>(name: string, formName?: string): string;
|
|
497
560
|
|
|
@@ -544,4 +607,4 @@ declare function useValidationClass<T>({ customValidation, validationClass, vali
|
|
|
544
607
|
};
|
|
545
608
|
};
|
|
546
609
|
|
|
547
|
-
export { InnerCaptcha as Captcha, Checkbox, DeletableInput,
|
|
610
|
+
export { InnerCaptcha as Captcha, Checkbox, DeletableInput, FieldWrapper, FileInput, Form, FormContext, IWrapper, Input, NumberInputf, Radio, Select, Switchbox, TCheckbox, TDefaultFieldType, TInput$1 as TInput, TOnValidate, TRadio, TSelect, TSwitchbox, TUseField, TValidationResult, Textarea, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };
|