Skip to content

Commit 1aeef21

Browse files
committed
added boolean type field
1 parent 0733d06 commit 1aeef21

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
};

src/view/Vproperty/index.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Map, List} from 'immutable';
66
import Vfield from '../Vfield';
77

88
import VpropertyArray from './VpropertyArray';
9+
import VpropertyBoolean from './VpropertyBoolean';
910
import VpropertyExpression from './VpropertyExpression';
1011
import VpropertyMetadata from './VpropertyMetadata';
1112
import VpropertyFunction from './VpropertyFunction';
@@ -128,6 +129,16 @@ export default class Vproperty extends React.Component {
128129
error:property.error
129130
}} focus={focus} handle={handle}/>
130131
</div>;
132+
} else if (spec.type === 'boolean'){
133+
elem = <div>
134+
<VpropertyBoolean property={{
135+
type:'boolean',
136+
name:property.name,
137+
value:property.value,
138+
placeholder:doc,
139+
error:property.error
140+
}} focus={focus} handle={handle}/>
141+
</div>;
131142
} else if (spec.type === 'enum'){
132143
let options = [];
133144
for (let i in spec.values){

0 commit comments

Comments
 (0)