Skip to content

Commit 6692344

Browse files
committed
Added propTypes to field components.
1 parent d771cbd commit 6692344

File tree

13 files changed

+143
-10
lines changed

13 files changed

+143
-10
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
schema: {
3+
type: "array",
4+
title: "title",
5+
default: ["default1", "default2"],
6+
items: {
7+
type: "string",
8+
title: "item"
9+
}
10+
},
11+
onChange: console.log.bind(console)
12+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
schema: {
3+
type: "array",
4+
title: "title",
5+
items: {
6+
type: "string",
7+
title: "item"
8+
}
9+
},
10+
formData: ["item1", "item2"],
11+
onChange: console.log.bind(console)
12+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
schema: {
3+
type: "boolean",
4+
title: "My boolean",
5+
default: true,
6+
},
7+
onChange: console.log.bind(console)
8+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
schema: {
3+
type: "boolean",
4+
title: "My boolean",
5+
},
6+
formData: true,
7+
onChange: console.log.bind(console)
8+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
schema: {
3+
type: "object",
4+
title: "object title",
5+
default: {
6+
string: "a default string",
7+
bool: true
8+
},
9+
properties: {
10+
string: {
11+
type: "string",
12+
title: "string"
13+
},
14+
bool: {
15+
type: "boolean",
16+
title: "bool"
17+
}
18+
}
19+
},
20+
onChange: console.log.bind(console)
21+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
schema: {
3+
type: "object",
4+
title: "object title",
5+
properties: {
6+
string: {
7+
type: "string",
8+
title: "string"
9+
},
10+
bool: {
11+
type: "boolean",
12+
title: "bool"
13+
}
14+
}
15+
},
16+
formData: {
17+
string: "an existing string",
18+
bool: true
19+
},
20+
onChange: console.log.bind(console)
21+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
schema: {
3+
type: "string",
4+
title: "string",
5+
default: "a default string"
6+
}
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
schema: {
3+
type: "string",
4+
title: "string",
5+
},
6+
formData: "an existing string"
7+
};

src/components/fields/ArrayField.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import React, { Component } from "react";
1+
import React, { Component, PropTypes } from "react";
22

33
import { defaultTypeValue } from "../../utils";
44
import SchemaField from "./SchemaField";
55

66

77
export default class ArrayField extends Component {
8+
static propTypes = {
9+
schema: PropTypes.object.isRequired,
10+
onChange: PropTypes.func.isRequired,
11+
formData: PropTypes.array,
12+
}
13+
814
constructor(props) {
915
super(props);
1016
const formData = Array.isArray(props.formData) ? props.formData : null;

src/components/fields/BooleanField.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from "react";
1+
import React, { PropTypes } from "react";
22

33
import { defaultFieldValue } from "../../utils";
44
import CheckboxField from "./../widgets/CheckboxWidget";
55

6-
export default function BooleanField({schema, formData, required, onChange}) {
6+
function BooleanField({schema, formData, required, onChange}) {
77
const {title, description} = schema;
88
const commonProps = {
99
type: schema.type,
@@ -17,3 +17,12 @@ export default function BooleanField({schema, formData, required, onChange}) {
1717
// XXX handle uiSchema.widget here
1818
return <CheckboxField {...commonProps} />;
1919
}
20+
21+
BooleanField.propTypes = {
22+
schema: PropTypes.object.isRequired,
23+
onChange: PropTypes.func.isRequired,
24+
formData: PropTypes.bool,
25+
required: PropTypes.bool,
26+
};
27+
28+
export default BooleanField;

0 commit comments

Comments
 (0)