Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-formr

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-formr - npm Package Compare versions

Comparing version 1.3.4 to 1.4.0

10

package.json
{
"name": "react-formr",
"version": "1.3.4",
"version": "1.4.0",
"description": "Form managing component for React & React Native",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {

@@ -35,4 +35,2 @@ "test": "jest",

"devDependencies": {
"react-native": "^0.69.0",
"react": "^18.2.0",
"@babel/core": "^7.18.5",

@@ -54,2 +52,4 @@ "@babel/runtime": "^7.18.3",

"metro-react-native-babel-preset": "^0.71.1",
"react": "^18.2.0",
"react-native": "^0.69.0",
"react-native-testing-library": "^6.0.0",

@@ -56,0 +56,0 @@ "react-test-renderer": "18.2.0",

@@ -26,5 +26,5 @@ export interface FormMessages {

export interface AnyObject {
[key: string]: any;
}
export type AnyObject<T> = {
[key in keyof T]: any;
};

@@ -36,6 +36,15 @@ export type FormrValidation<T> = {

export interface FormrProps<T> {
/** Object of form fields which the formr needs to handle */
formFields: T;
/** Object of validation with respect to formFields */
validation?: FormrValidation<T>;
/** Control to disable autofocuse on return of input */
disbaleAutoFocus?: boolean;
/** The function used to lisen form field changes */
onChange?: (values: T) => void;
/** Function will be triggered after finished focusing the form inputs */
onFinishFocus?: (values: T) => void;

@@ -57,12 +66,71 @@ }

export interface FormrFunctions<T> {
/** Function to update form field values with field key & new field value
*
* @param {string} key - Key of the form field
* @param {any} value - Value of the form field
*
* e.g, onChangeHandler("name","New Name") */
onChangeHandler: (key: keyof T, value: any) => void;
/** Function to update form touched/focused status, calling this will set focused state to true
*
* @param {string} key - Key of the form field
*
* e.g, onBlurHandler("name") */
onBlurHandler: (key: keyof T) => void;
/** Function to be triggered when return key pressed (after finished editing) in the field, which will focus next field if available
*
* @param {string} key - Key of the form field
*
* e.g, onSubmitEditingHandler("name") */
onSubmitEditingHandler: (key: keyof T) => void;
/** Function to be triggered when the form to be submitted, the passed callback function will be called all the validation passed
*
* @param {function} callback(value) - callback function will be called with values when the validation is passed.
*
* e.g, onSubmitEditingHandler("name") */
onSubmitHandler: (callback: (values: T) => void) => boolean;
/** Function which consista all the handler which TextInput requires to handle values & focuse
*
* @param {string} key - key of the form fiels
*
* e.g, <TextInput {...inputBinder("name")} /> */
inputBinder: (key: keyof T) => InputBinderProps;
/** Function to update refs of in form input
*
* @param {string} key - Key of the form field
* @param {any} ref - ref of the form field
*
* e.g, onChangeHandler("name","New Name") */
refsHandler: (key: keyof T, ref: any) => void;
refs: AnyObject;
/** Function to reset form values, focused states & valid states
*
* @param {object} resetValue - Key of the form field
*
* e.g, onResetFormHandler("name","New Name") */
onResetFieldHandler: (key: keyof T) => void;
/** Function to reset form values, focused states & valid states
*
* @param {object} resetValue - Key of the form field
*
* e.g, onResetFormHandler("name","New Name") */
onResetFormHandler: (resetValue?: Partial<T>) => void;
/** Array of refs on form's inputs */
refs: AnyObject<T>;
/** Updated form values */
values: T;
/** Form field touched states, which can be used to show field error*/
touched: DerivedBoolObject<T>;
/** Form field valid states*/
valid: DerivedBoolObject<T>;
}

@@ -33,8 +33,5 @@ import { useState, useRef, useEffect, useCallback } from 'react';

// Setting valid helper
const setValid = useCallback(
(key: keyof T, validated: boolean) => {
valid.current = { ...valid.current, [key]: validated };
},
[valid]
);
const setValid = useCallback((key: keyof T, validated: boolean) => {
valid.current = { ...valid.current, [key]: validated };
}, []);

@@ -83,2 +80,28 @@ // run validation & set validation

// Form reset handler
const onResetFormHandler = useCallback<
FormrFunctions<T>['onResetFormHandler']
>(
(resetValues) => {
const values = { ...formFields, ...(resetValues ?? {}) };
setValues(values);
setTouched(fieldBools(values));
valid.current = fieldBools(
validation ?? {}
) as DerivedBoolObject<T>;
},
[valid.current, setValues, setTouched]
);
const onResetFieldHandler = useCallback<
FormrFunctions<T>['onResetFieldHandler']
>(
(key) => {
onChangeHandler(key, formFields[key]);
setTouched((prev) => ({ ...prev, [key]: false }));
setValid(key, false);
},
[onChangeHandler, setTouched, setValid]
);
// Input Blur listner

@@ -205,2 +228,3 @@ const onBlurHandler = useCallback<FormrFunctions<T>['onBlurHandler']>(

);
const outputRefs: any = { ...formFields };

@@ -216,2 +240,4 @@ Object.keys(formFields).map((val, key) => {

onSubmitHandler,
onResetFieldHandler,
onResetFormHandler,
inputBinder,

@@ -218,0 +244,0 @@ refsHandler,

{
"include": ["src"], /* Include only the src directory */
"compilerOptions": {
/* Basic Options */
"target": "ES2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"ES2019"
] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react-native" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true /* Do not emit outputs. */,
// "incremental": true, /* Enable incremental compilation */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"skipLibCheck": true
"target": "es2019" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"module": "commonjs" /* Specify what module code is generated. */,
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
"outDir": "dist",
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},

@@ -62,0 +13,0 @@ "exclude": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc