Skip to content

Commit fd08dd8

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

File tree

14 files changed

+130
-45
lines changed

14 files changed

+130
-45
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+
};

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
}

src/components/widgets/CheckboxWidget.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { PropTypes } from "react";
33
import Wrapper from "./../widgets/Wrapper";
44

55
function CheckboxWidget({
6+
type,
67
onChange,
78
label,
89
defaultValue,
@@ -11,7 +12,7 @@ function CheckboxWidget({
1112
placeholder
1213
}) {
1314
return (
14-
<Wrapper label={label} required={required} type="boolean">
15+
<Wrapper label={label} required={required} type={type}>
1516
<input type="checkbox"
1617
title={placeholder}
1718
checked={value}
@@ -23,6 +24,7 @@ function CheckboxWidget({
2324
}
2425

2526
CheckboxWidget.propTypes = {
27+
type: PropTypes.string.isRequired,
2628
onChange: PropTypes.func,
2729
label: PropTypes.string,
2830
defaultValue: PropTypes.bool,

0 commit comments

Comments
 (0)