@altiore/form
Advanced tools
Comparing version 3.1.6 to 3.1.7
@@ -8,1 +8,2 @@ import { MutableRefObject } from 'react'; | ||
export declare const inputTypeByType: Map<FieldType, string>; | ||
export declare const getInputTypeByFieldType: (fieldType: FieldType) => string; |
@@ -83,4 +83,2 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
[FieldType.PASSWORD, 'password'], | ||
[FieldType.SELECT, 'text'], | ||
[FieldType.SELECT_MULTIPLE, 'text'], | ||
[FieldType.EMAIL, 'email'], | ||
@@ -91,3 +89,7 @@ [FieldType.TEXT, 'text'], | ||
[FieldType.FLOAT, 'number'], | ||
[FieldType.SELECT_MULTIPLE, 'select-multiple'], | ||
]); | ||
export var getInputTypeByFieldType = function (fieldType) { | ||
return inputTypeByType.has(fieldType) | ||
? inputTypeByType.get(fieldType) | ||
: fieldType; | ||
}; |
@@ -35,3 +35,3 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
return (React.createElement(ValidatedField, __assign({}, rest, { defaultValue: defaultValue, validators: validators, componentProps: componentProps, formRef: formState === null || formState === void 0 ? void 0 : formState.formRef, fieldMeta: field, name: name, type: fieldType }))); | ||
return (React.createElement(ValidatedField, __assign({}, rest, { defaultValue: defaultValue, validators: validators, componentProps: componentProps, formRef: formState === null || formState === void 0 ? void 0 : formState.formRef, fieldMeta: field, name: name, fieldType: fieldType }))); | ||
}; |
@@ -11,6 +11,6 @@ import { MutableRefObject } from 'react'; | ||
formRef?: MutableRefObject<HTMLFormElement>; | ||
type?: FieldType; | ||
fieldType?: FieldType; | ||
hideErrorInXSec?: false | number; | ||
}; | ||
export declare const ValidatedField: <FieldCustomProps extends Record<string, any>, Input extends HTMLElement = HTMLInputElement>({ component, componentProps, defaultValue, fieldMeta, formRef, name, type, validators, hideErrorInXSec, }: IProps<FieldCustomProps, Input>) => JSX.Element; | ||
export declare const ValidatedField: <FieldCustomProps extends Record<string, any>, Input extends HTMLElement = HTMLInputElement>({ component, componentProps, defaultValue, fieldMeta, formRef, name, fieldType, validators, hideErrorInXSec, }: IProps<FieldCustomProps, Input>) => JSX.Element; | ||
export {}; |
@@ -13,16 +13,13 @@ var __assign = (this && this.__assign) || function () { | ||
import React, { useMemo, useRef } from 'react'; | ||
import { FieldType } from '../../../@common/types'; | ||
import { inputTypeByType } from '../../../@common/utils'; | ||
import { getInputTypeByFieldType } from '../../../@common/utils'; | ||
import { useValidateInput } from './hooks/use-validate-input'; | ||
export var ValidatedField = function (_a) { | ||
var component = _a.component, componentProps = _a.componentProps, defaultValue = _a.defaultValue, fieldMeta = _a.fieldMeta, formRef = _a.formRef, name = _a.name, type = _a.type, validators = _a.validators, hideErrorInXSec = _a.hideErrorInXSec; | ||
var component = _a.component, componentProps = _a.componentProps, defaultValue = _a.defaultValue, fieldMeta = _a.fieldMeta, formRef = _a.formRef, name = _a.name, fieldType = _a.fieldType, validators = _a.validators, hideErrorInXSec = _a.hideErrorInXSec; | ||
var inputRef = useRef(); | ||
var _b = useValidateInput(inputRef, validators, formRef, fieldMeta, type, name, hideErrorInXSec), errors = _b.errors, setErrors = _b.setErrors; | ||
var _b = useValidateInput(inputRef, validators, formRef, fieldMeta, fieldType, name, hideErrorInXSec), errors = _b.errors, setErrors = _b.setErrors; | ||
return useMemo(function () { | ||
return React.createElement(component, __assign(__assign(__assign({}, componentProps), (fieldMeta || {})), { defaultValue: typeof (fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.defaultValue) === 'undefined' | ||
? defaultValue | ||
: fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.defaultValue, error: errors === null || errors === void 0 ? void 0 : errors[0], errors: errors, inputRef: inputRef, isInvalid: Boolean(errors.length), name: name, setErrors: setErrors, type: inputTypeByType.has(type) | ||
? inputTypeByType.get(type) | ||
: inputTypeByType.get(FieldType.TEXT) })); | ||
: fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.defaultValue, error: errors === null || errors === void 0 ? void 0 : errors[0], errors: errors, inputRef: inputRef, isInvalid: Boolean(errors.length), name: name, setErrors: setErrors, type: getInputTypeByFieldType(fieldType) })); | ||
}, [componentProps, fieldMeta, errors, inputRef, name, setErrors]); | ||
}; |
{ | ||
"name": "@altiore/form", | ||
"version": "3.1.6", | ||
"version": "3.1.7", | ||
"description": "Form helper for building powerful forms", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89478