mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 04:01:52 +00:00
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:
committed by
Mohamed Hegazy
parent
289a6cb70c
commit
92d2d87d8a
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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> {}
|
||||
}
|
||||
Reference in New Issue
Block a user