1- import React from "react" ;
1+ import React , { PropTypes } from "react" ;
22
33import Wrapper from "./../widgets/Wrapper" ;
44
55
6- export default function RadioWidget ( { schema, formData, options, onChange} ) {
6+ function RadioWidget ( {
7+ type,
8+ options,
9+ label,
10+ placeholder,
11+ value,
12+ defaultValue,
13+ required,
14+ onChange
15+ } ) {
716 // Generating a unique field name to identify this set of radio buttons
817 const name = Math . random ( ) . toString ( ) ;
918 return (
10- < Wrapper type = { schema . type } label = { schema . title } >
19+ < Wrapper type = { type } label = { label } >
1120 {
1221 options . map ( ( option , i ) => {
13- const checked = formData ? option === formData :
14- option === schema . default ;
22+ const checked = value ? option === value :
23+ option === defaultValue ;
1524 return (
1625 < div key = { i } >
1726 < label >
1827 < input type = "radio"
1928 name = { name }
2029 value = { option }
2130 checked = { checked }
31+ placeholder = { placeholder }
2232 onChange = { _ => onChange ( option ) } />
2333 { option }
2434 </ label >
@@ -29,3 +39,16 @@ export default function RadioWidget({schema, formData, options, onChange}) {
2939 </ Wrapper >
3040 ) ;
3141}
42+
43+ RadioWidget . propTypes = {
44+ type : PropTypes . string . isRequired ,
45+ options : PropTypes . array . isRequired ,
46+ label : PropTypes . string ,
47+ placeholder : PropTypes . string ,
48+ value : PropTypes . any ,
49+ defaultValue : PropTypes . any ,
50+ required : PropTypes . bool ,
51+ onChange : PropTypes . func ,
52+ } ;
53+
54+ export default RadioWidget ;
0 commit comments