forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio-button.jsx
141 lines (121 loc) · 3.52 KB
/
radio-button.jsx
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var React = require('react');
var StylePropable = require('./mixins/style-propable');
var Transitions = require('./styles/transitions');
var EnhancedSwitch = require('./enhanced-switch');
var RadioButtonOff = require('./svg-icons/toggle-radio-button-off');
var RadioButtonOn = require('./svg-icons/toggle-radio-button-on');
var RadioButton = React.createClass({
mixins: [StylePropable],
contextTypes: {
muiTheme: React.PropTypes.object
},
propTypes: {
iconStyle: React.PropTypes.object,
onCheck: React.PropTypes.func
},
getTheme: function() {
return this.context.muiTheme.component.radioButton;
},
getStyles: function() {
var styles = {
icon: {
height: this.getTheme().size,
width: this.getTheme().size
},
target: {
transition: Transitions.easeOut(),
position: 'absolute',
opacity: 1,
transform: 'scale(1)',
fill: this.getTheme().borderColor
},
fill: {
position: 'absolute',
opacity: 1,
transform: 'scale(0)',
transformOrigin: '50% 50%',
transition: Transitions.easeOut(),
fill: this.getTheme().checkedColor
},
targetWhenChecked: {
opacity: 0,
transform: 'scale(0)'
},
fillWhenChecked: {
opacity: 1,
transform: 'scale(1)'
},
targetWhenDisabled: {
fill: this.getTheme().disabledColor
},
fillWhenDisabled: {
fill: this.getTheme().disabledColor
},
};
return styles;
},
render: function() {
var {
onCheck,
...other
} = this.props;
var styles = this.getStyles();
var onStyles =
this.mergeAndPrefix(
styles.target,
this.props.checked && styles.targetWhenChecked,
this.props.iconStyle,
this.props.disabled && styles.targetWhenDisabled);
var offStyles =
this.mergeAndPrefix(
styles.fill,
this.props.checked && styles.fillWhenChecked,
this.props.iconStyle,
this.props.disabled && styles.fillWhenDisabled);
var radioButtonElement = (
<div>
<RadioButtonOff style={onStyles} />
<RadioButtonOn style={offStyles} />
</div>
);
var rippleColor = this.props.checked ? this.getTheme().checkedColor : this.getTheme().borderColor;
var iconStyle = this.mergeAndPrefix(
styles.icon,
this.props.iconStyle
);
var enhancedSwitchProps = {
ref: "enhancedSwitch",
inputType: "radio",
switched: this.props.checked || false,
switchElement: radioButtonElement,
rippleColor: rippleColor,
iconStyle: iconStyle,
onSwitch: this._handleCheck,
onParentShouldUpdate: this._handleStateChange,
labelPosition: (this.props.labelPosition) ? this.props.labelPosition : "right"
};
return (
<EnhancedSwitch
{...other}
{...enhancedSwitchProps}/>
);
},
// Only called when selected, not when unselected.
_handleCheck: function(e) {
if (this.props.onCheck) this.props.onCheck(e, this.props.value);
},
_handleStateChange: function() {
},
isChecked: function() {
return this.refs.enhancedSwitch.isSwitched();
},
// Use RadioButtonGroup.setSelectedValue(newSelectionValue) to set a
// RadioButton's checked value.
setChecked: function(newCheckedValue) {
this.refs.enhancedSwitch.setSwitched(newCheckedValue);
},
getValue: function() {
return this.refs.enhancedSwitch.getValue();
}
});
module.exports = RadioButton;