Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ts typings #6

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
declare module 'use-form-react' {
import React from 'react';
export type ValidationFunc<Fields> = (fields: Fields) => string | undefined;

export interface UseFormConfig<Fields extends Record<string, any>> {
initialValues?: Partial<Fields>;
validation?: Partial<Record<keyof Fields, ValidationFunc<Fields>>>;
debug?: boolean;
callback?: (inputs: Fields)=> void;
}

export interface UseFormState<Fields> {
onSubmit: (event: React.SyntheticEvent<HTMLFormElement>) => void,
onChange: (event: React.SyntheticEvent<HTMLInputElement>) => void,
inputs: Fields,
submitting: boolean,
dirty: boolean,
reset: () => void,
setInputs: (fields: Fields) => void,
errors: Record<keyof Fields, string>,
valid: boolean,
}

const useForm: <Fields = any>(name: string, config: UseFormConfig<Fields>) => UseFormState<Fields>;

export default useForm;
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"type": "git",
"url": "https://github.com/amazingandyyy/use-form-react.git"
},
"types": "index.d.ts",
"peerDependencies": {
"react": "^16.8.0"
},
Expand All @@ -25,6 +26,7 @@
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/preset-react": "^7.0.0",
"@types/react": "^16.8.18",
"babel-jest": "^24.7.1",
"jest": "^24.7.1",
"parcel-bundler": "^1.12.3",
Expand Down