blob: 35bc286514e4129a6c95561eedbb63fd5e1d54aa (
plain)
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
|
import React, { Component } from "react"
import cx from "classnames"
import PropTypes from "prop-types"
const noop = () => { }
const ParameterIncludeEmptyPropTypes = {
isIncluded: PropTypes.bool.isRequired,
isDisabled: PropTypes.bool.isRequired,
isIncludedOptions: PropTypes.object,
onChange: PropTypes.func.isRequired,
}
const ParameterIncludeEmptyDefaultProps = {
onChange: noop,
isIncludedOptions: {},
}
export default class ParameterIncludeEmpty extends Component {
static propTypes = ParameterIncludeEmptyPropTypes
static defaultProps = ParameterIncludeEmptyDefaultProps
componentDidMount() {
const { isIncludedOptions, onChange } = this.props
const { shouldDispatchInit, defaultValue } = isIncludedOptions
if (shouldDispatchInit) {
onChange(defaultValue)
}
}
onCheckboxChange = e => {
const { onChange } = this.props
onChange(e.target.checked)
}
render() {
let { isIncluded, isDisabled } = this.props
return (
<div>
<label
htmlFor="include_empty_value"
className={cx("parameter__empty_value_toggle", {
"disabled": isDisabled
})}
>
<input
id="include_empty_value"
type="checkbox"
disabled={isDisabled}
checked={!isDisabled && isIncluded}
onChange={this.onCheckboxChange}
/>
Send empty value
</label>
</div>
)
}
}
|