1+ import React from 'react' ;
2+ import PropTypes from 'prop-types' ;
3+
4+ import Vfield from '../../Vfield' ;
5+
6+ import styleSpec from '../../../vendor/style-spec/style-spec' ;
7+
8+ export default class VpropertyBoolean extends React . Component {
9+
10+ static propTypes = {
11+ property : PropTypes . shape ( {
12+ type : PropTypes . string . isRequired ,
13+ name : PropTypes . string . isRequired , // string of position . separated
14+ value : PropTypes . bool ,
15+ placeholder : PropTypes . string ,
16+ error : PropTypes . oneOfType ( [
17+ PropTypes . string ,
18+ PropTypes . object
19+ ] )
20+ } ) ,
21+ focus : PropTypes . string ,
22+ handle : PropTypes . object
23+ }
24+
25+ constructor ( props ) {
26+ super ( props ) ;
27+ const { handle, property} = this . props ;
28+
29+
30+ this . fieldHandle = {
31+ ...handle ,
32+ backout :( f ) => {
33+
34+ } ,
35+ change :( f ) => {
36+ const val = ( f . value === 'true' ) ? true : false ;
37+ handle . change ( {
38+ name :f . name ,
39+ value :val
40+ } ) ;
41+ }
42+ } ;
43+
44+ for ( let i in this . fieldHandle ) {
45+ this . fieldHandle [ i ] = this . fieldHandle [ i ] . bind ( this ) ;
46+ }
47+
48+ }
49+
50+ render ( ) {
51+ const { property, focus} = this . props ;
52+
53+ const options = [
54+ { name :'true' , value :'true' } ,
55+ { name :'false' , value :'false' }
56+ ] ;
57+
58+ const val = ( property . value ) ? 'true' : 'false' ;
59+
60+ return < div className = "form-group mb-0" >
61+ < Vfield field = { {
62+ type :'select' ,
63+ name :property . name ,
64+ value :val ,
65+ controlled :false ,
66+ autoFocus :property . name === focus ,
67+ options :options
68+ } } handle = { this . fieldHandle } />
69+ </ div >
70+ }
71+ } ;
0 commit comments