Add definitions for react-jsonschema-form 0.30.1 (#10104)

* react-jsonschema-form 0.30.1

Very barebones typings, intended to serve as a baseline for improvement.

* rename react-jsonschema-form-test.tsx -> ...-tests.tsx
This commit is contained in:
iamdanfox
2016-07-19 17:17:48 -07:00
committed by Mohamed Hegazy
parent 289a6cb70c
commit 92d2d87d8a
2 changed files with 119 additions and 0 deletions
@@ -0,0 +1,84 @@
/// <reference path="react-jsonschema-form.d.ts" />
/// <reference path="../react/react.d.ts" />
import * as React from "react";
import Form from "react-jsonschema-form";
// example taken from the react-jsonschema-form playground:
// https://github.com/mozilla-services/react-jsonschema-form/blob/fedd830294417969d88e38fb9f6b3a85e6ad105e/playground/samples/simple.js
const schema = {
"title": "A registration form",
"type": "object",
"required": [
"firstName",
"lastName"
],
"properties": {
"firstName": {
"type": "string",
"title": "First name"
},
"lastName": {
"type": "string",
"title": "Last name"
},
"age": {
"type": "integer",
"title": "Age"
},
"bio": {
"type": "string",
"title": "Bio"
},
"password": {
"type": "string",
"title": "Password",
"minLength": 3
}
}
};
const uiSchema = {
age: {
"ui:widget": "updown"
},
bio: {
"ui:widget": "textarea"
},
password: {
"ui:widget": "password",
"ui:help": "Hint: Make it strong!"
},
date: {
"ui:widget": "alt-datetime"
}
};
interface IExampleState {
formData: any;
}
export class Example extends React.Component<any, IExampleState> {
constructor(props: any) {
super(props);
this.state.formData = {
firstName: "Chuck",
lastName: "Norris",
age: 75,
bio: "Roundhouse kicking asses since 1940",
password: "noneed"
};
}
public render() {
return (
<div className="react-jsonschema-form-example">
{ <Form schema={schema}
uiSchema={uiSchema}
formData={this.state}
onChange={(formData) => this.setState({formData})} /> }
</div>
);
}
}
+35
View File
@@ -0,0 +1,35 @@
// Type definitions for react-jsonschema-form 0.30.1
// Project: https://github.com/mozilla-services/react-jsonschema-form
// Definitions by: Dan Fox <https://github.com/iamdanfox>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../react/react.d.ts" />
declare module "react-jsonschema-form" {
import * as React from "react";
export interface FormProps {
schema: {};
uiSchema?: {};
formData?: any;
widgets?: {};
fields?: {};
validate?: (formData: any, errors: any) => any;
onChange?: (e: IChangeEvent) => any;
onError?: (e: any) => any;
onSubmit?: (e: any) => any;
liveValidate?: boolean;
safeRenderCompletion?: boolean;
}
export interface IChangeEvent {
edit: boolean;
formData: any;
errors: any[];
errorSchema: any;
idSchema: any;
status: string;
}
export default class Form extends React.Component<FormProps, any> {}
}