-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathVisibilitySelect.js
86 lines (75 loc) · 2.17 KB
/
VisibilitySelect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, {Fragment, Component} from 'react';
import PropTypes from 'prop-types';
import {connectToContainer} from 'lib';
import {MULTI_VALUED_PLACEHOLDER} from 'lib/constants';
import Field from './Field';
import Radio from './Radio';
import Dropdown from './Dropdown';
export class UnconnectedVisibilitySelect extends Component {
constructor(props, context) {
super(props, context);
this.setMode = this.setMode.bind(this);
this.setLocals = this.setLocals.bind(this);
this.setLocals(props);
}
componentWillReceiveProps(props) {
this.setLocals(props);
}
setLocals(props) {
this.mode =
props.fullValue === undefined || props.fullValue === MULTI_VALUED_PLACEHOLDER // eslint-disable-line no-undefined
? this.props.defaultOpt
: props.fullValue;
}
setMode(mode) {
this.props.updateContainer({[this.props.attr]: mode});
}
render() {
const {dropdown, clearable, options, showOn, attr, label} = this.props;
return (
<Fragment>
{dropdown ? (
<Dropdown
attr={attr}
label={label}
options={options}
fullValue={this.mode}
updatePlot={this.setMode}
clearable={clearable}
/>
) : (
<Radio
attr={attr}
label={label}
options={options}
fullValue={this.mode}
updatePlot={this.setMode}
/>
)}
{(Array.isArray(showOn) && showOn.includes(this.mode)) || this.mode === showOn
? this.props.children
: null}
</Fragment>
);
}
}
UnconnectedVisibilitySelect.propTypes = {
fullValue: PropTypes.any,
updatePlot: PropTypes.func,
dropdown: PropTypes.bool,
clearable: PropTypes.bool,
showOn: PropTypes.oneOfType([
PropTypes.number,
PropTypes.bool,
PropTypes.string,
PropTypes.array,
]),
defaultOpt: PropTypes.oneOfType([PropTypes.number, PropTypes.bool, PropTypes.string]),
label: PropTypes.string,
attr: PropTypes.string,
...Field.propTypes,
};
UnconnectedVisibilitySelect.contextTypes = {
updateContainer: PropTypes.func,
};
export default connectToContainer(UnconnectedVisibilitySelect);