forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadioButton.js
More file actions
75 lines (67 loc) · 2.18 KB
/
RadioButton.js
File metadata and controls
75 lines (67 loc) · 2.18 KB
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
import React, { Component, PropTypes } from 'react';
import classnames from 'classnames';
import { themr } from 'react-css-themr';
import { RADIO } from '../identifiers.js';
import rippleFactory from '../ripple/Ripple.js';
import radioFactory from './Radio.js';
const factory = (Radio) => {
class RadioButton extends Component {
static propTypes = {
checked: PropTypes.bool,
className: PropTypes.string,
disabled: PropTypes.bool,
label: PropTypes.string,
name: PropTypes.string,
onBlur: PropTypes.func,
onChange: PropTypes.func,
onFocus: PropTypes.func,
theme: PropTypes.shape({
disabled: PropTypes.string.isRequired,
field: PropTypes.string.isRequired,
input: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
}),
value: PropTypes.any
};
static defaultProps = {
checked: false,
className: '',
disabled: false
};
handleClick = (event) => {
const {checked, disabled, onChange} = this.props;
if (event.pageX !== 0 && event.pageY !== 0) this.blur();
if (!disabled && !checked && onChange) onChange(event, this);
};
blur () {
this.refs.input.blur();
}
focus () {
this.refs.input.focus();
}
render () {
const { className, checked, disabled, label, theme, onChange, ...others } = this.props; // eslint-disable-line
const _className = classnames(theme[this.props.disabled ? 'disabled' : 'field'], className);
return (
<label data-react-toolbox='radio-button' className={_className}>
<input
{...others}
className={theme.input}
onClick={this.handleClick}
readOnly
ref='input'
type='radio'
/>
<Radio checked={checked} disabled={disabled} theme={theme} />
{label ? <span className={theme.text}>{label}</span> : null}
</label>
);
}
}
return RadioButton;
};
const Radio = radioFactory(rippleFactory({ centered: true, spread: 2.6 }));
const RadioButton = factory(Radio);
export default themr(RADIO)(RadioButton);
export { factory as radioButtonFactory };
export { RadioButton };