Added type definitions for react-material-ui-form-validator

This commit is contained in:
Frank Brullo
2019-02-12 16:31:20 -05:00
parent c8792a3fb0
commit 9a8085f271
5 changed files with 111 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
// Type definitions for react-material-ui-form-validator v2.0.3
// Project: https://github.com/NewOldMax/react-material-ui-form-validator
// Definitions by: Frank Brullo <https://github.com/FrankBrullo/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.1.3
import * as React from "react";
import { TextFieldProps } from "material-ui";
export interface ValidatorFormProps {
className?: string;
onSubmit: (event: React.FormEventHandler) => void;
instantValidate?: boolean;
onError?: (errors: any[]) => {};
debounceTime?: number;
}
export class ValidatorForm extends React.Component<ValidatorFormProps> {
public static addValidationRule(name: string, callback: (value: any) => boolean): void;
public isFormValid(dryRun: boolean): boolean;
public resetValidations(): void;
}
export interface ValidatorComponentProps {
errorMessages?: any[] | string;
validators?: any[];
name: string;
value: any;
validatorListener?: (isValid: boolean) => void;
withRequiredValidator?: boolean;
}
export class ValidatorComponent extends React.Component<ValidatorComponentProps & TextFieldProps> {}
export class TextValidator extends ValidatorComponent {}
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"@material-ui/core": "3.9.0"
}
}
@@ -0,0 +1,47 @@
import * as React from 'react';
import {
TextValidator,
ValidatorComponent,
ValidatorForm
} from 'react-material-ui-form-validator';
class Test extends React.Component {
onSubmitted = (event: React.FormEventHandler) => {};
onError = (errors: any[]) => {};
onValidate = (isValid: boolean) => {};
onTextFieldChanged = (event: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {};
render() {
return (
<ValidatorForm
instantValidate={true}
debounceTime={10}
onSubmit={this.onSubmitted}
onError={this.onError}
>
<ValidatorComponent
errorMessages={['Field is required']}
validators={['required']}
name={'Field'}
value={'value'}
validatorListener={this.onValidate}
withRequiredValidator={true}
/>
<TextValidator
id="email"
label="Email Address"
type="email"
name="email"
autoComplete="email"
placeholder="email"
margin="normal"
variant="outlined"
value="value"
onChange={this.onTextFieldChanged}
validatorListener={this.onValidate}
validators={['required', 'isEmail']}
errorMessages={['Email is required', 'Enter a valid email address']}
/>
</ValidatorForm>
);
}
}
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"jsx": "react",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"./react-material-ui-form-validator-tests.tsx"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }