blob: 483521ac593b43076c757bf8485fd39488d8bc52 (
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
|
import React from 'react';
import PropTypes from 'prop-types';
class Radio extends React.Component {
render() {
let {checked, disabled, value, label, className, inputRef, name} = this.props;
let dataTestId = this.props['data-test-id'];
return (
<div className={`sdc-radio ${className}`}>
<label>
<input
ref={inputRef}
className='sdc-radio__input'
value={value}
data-test-id={dataTestId}
type='radio'
name={name}
checked={checked}
onChange={(e) => this.onChange(e)}
disabled={disabled} />
<span className='sdc-radio__label'>{label}</span>
</label>
</div>
);
}
onChange(e) {
let {onChange} = this.props;
if (onChange) {
onChange(e.target.checked);
}
}
getChecked() {
return this.props.checked;
}
getValue() {
return this.props.value;
}
}
Radio.propTypes = {
checked: PropTypes.bool,
value: PropTypes.any,
label: PropTypes.string,
className: PropTypes.string,
inputRef: PropTypes.func,
name: PropTypes.string,
disabled: PropTypes.bool
};
Radio.defaultProps = {
checked: false,
className: ''
};
export default Radio;
|