Skip to content

Commit a425589

Browse files
committed
Added propTypes to widget components.
1 parent 4a88c72 commit a425589

File tree

15 files changed

+133
-46
lines changed

15 files changed

+133
-46
lines changed

dist/react-jsonschema-form-0.2.0.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-jsonschema-form-0.2.0.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
type: "boolean",
23
label: "foo",
34
onChange: console.log.bind(console)
45
};
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module.exports = {
2-
schema: {
3-
type: "string",
4-
title: "foo",
5-
default: "b"
6-
},
7-
options: ["a", "b"]
2+
type: "string",
3+
label: "foo",
4+
defaultValue: "b",
5+
options: ["a", "b"],
6+
onChange: console.log.bind(console)
87
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
type: "string",
3+
label: "foo",
4+
options: ["foo", "bar", "baz"],
5+
onChange: console.log.bind(console)
6+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
type: "string",
3+
label: "foo",
4+
value: "plop",
5+
onChange: console.log.bind(console)
6+
};

fixtures/widgets/Wrapper/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var React = require("react");
2+
3+
module.exports = {
4+
type: "string",
5+
label: "foo",
6+
required: true,
7+
children: React.createElement("div", {}, "content")
8+
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "0.2.0",
44
"description": "A simple React component capable of building HTML forms out of a JSON schema.",
55
"scripts": {
6-
"dist": "babel -d lib/ src/ && rimraf dist && webpack --config webpack.config.dist.js --optimize-minimize",
6+
"build:lib": "rimraf lib && babel -d lib/ src/",
7+
"build:dist": "rimraf dist && webpack --config webpack.config.dist.js --optimize-minimize",
8+
"dist": "npm run build:lib && npm run build:dist",
79
"lint": "eslint src test",
810
"publish": "npm run dist && npm publish",
911
"start": "node devServer.js",

src/components/fields/BooleanField.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import CheckboxField from "./../widgets/CheckboxWidget";
66
export default function BooleanField({schema, formData, required, onChange}) {
77
const {title, description} = schema;
88
const commonProps = {
9+
type: schema.type,
910
onChange,
1011
label: title,
1112
placeholder: description,
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import React from "react";
22

3-
import TextField from "./../widgets/TextWidget";
4-
import SelectField from "./../widgets/SelectWidget";
3+
import { defaultFieldValue } from "../../utils";
4+
import TextWidget from "./../widgets/TextWidget";
5+
import SelectWidget from "./../widgets/SelectWidget";
56

67

78
export default function StringField({schema, formData, required, onChange}) {
9+
const {type, title, description} = schema;
810
const commonProps = {
9-
schema,
11+
type: type,
12+
label: title,
13+
placeholder: description,
1014
onChange,
11-
label: schema.title,
12-
formData: formData,
15+
value: formData,
1316
required: required,
17+
defaultValue: defaultFieldValue(formData, schema),
1418
};
1519
if (Array.isArray(schema.enum)) {
16-
return <SelectField options={schema.enum} {...commonProps} />;
20+
// XXX uiSchema: Could also be a list of radio buttons
21+
return <SelectWidget options={schema.enum} {...commonProps} />;
1722
}
18-
return <TextField placeholder={schema.description} {...commonProps} />;
23+
// XXX uiSchema: Could also be a textarea for longer texts
24+
return <TextWidget {...commonProps} />;
1925
}

0 commit comments

Comments
 (0)