From 92d2d87d8a844c1c6a7962d7e305e075a5e263f4 Mon Sep 17 00:00:00 2001 From: iamdanfox Date: Wed, 20 Jul 2016 01:17:48 +0100 Subject: [PATCH] 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 --- .../react-jsonschema-form-tests.tsx | 84 +++++++++++++++++++ .../react-jsonschema-form.d.ts | 35 ++++++++ 2 files changed, 119 insertions(+) create mode 100644 react-jsonschema-form/react-jsonschema-form-tests.tsx create mode 100644 react-jsonschema-form/react-jsonschema-form.d.ts diff --git a/react-jsonschema-form/react-jsonschema-form-tests.tsx b/react-jsonschema-form/react-jsonschema-form-tests.tsx new file mode 100644 index 0000000000..5fa0fd914a --- /dev/null +++ b/react-jsonschema-form/react-jsonschema-form-tests.tsx @@ -0,0 +1,84 @@ +/// +/// + +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 { + 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 ( +
+ {
this.setState({formData})} /> } +
+ ); + } +} diff --git a/react-jsonschema-form/react-jsonschema-form.d.ts b/react-jsonschema-form/react-jsonschema-form.d.ts new file mode 100644 index 0000000000..5004bb132d --- /dev/null +++ b/react-jsonschema-form/react-jsonschema-form.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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 {} +}