ldx-widgets
Version:
widgets
86 lines (78 loc) • 2.56 kB
JavaScript
(function() {
var PropTypes, RadioInput, React, createClass, input, label, ref, span;
React = require('react');
createClass = require('create-react-class');
PropTypes = require('prop-types');
ref = require('react-dom-factories'), input = ref.input, label = ref.label, span = ref.span;
RadioInput = createClass({
displayName: 'RadioInput',
propTypes: {
name: PropTypes.string,
value: PropTypes.string,
className: PropTypes.string,
wrapperLabel: PropTypes.string,
disabled: PropTypes.bool,
onChange: PropTypes.func,
tabIndex: PropTypes.number,
title: PropTypes.string,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
},
getDefaultProps: function() {
return {
className: 'radio-input',
disabled: false,
wrapperLabel: null,
name: null
};
},
render: function() {
var checked, className, disabled, id, inputProps, name, onChange, ref1, tabIndex, title, value, wrapperLabel;
ref1 = this.props, className = ref1.className, onChange = ref1.onChange, wrapperLabel = ref1.wrapperLabel, checked = ref1.checked, disabled = ref1.disabled, id = ref1.id, name = ref1.name, tabIndex = ref1.tabIndex, title = ref1.title, value = ref1.value;
inputProps = {
key: 'input',
ref: 'input',
name: name,
value: value,
type: 'radio',
onChange: this.handleChange,
checked: checked,
disabled: disabled
};
if (tabIndex != null) {
inputProps.tabIndex = tabIndex;
}
if (id != null) {
inputProps.id = id;
}
if (className != null) {
inputProps.className = className;
}
if (wrapperLabel != null) {
return label({
className: "radio-input-label" + (disabled ? ' disabled' : ''),
htmlFor: id,
title: title
}, [
input(inputProps), span({
key: 'label'
}, wrapperLabel)
]);
} else {
inputProps.title = title;
return input(inputProps);
}
},
getValue: function() {
return this.refs.input.value;
},
handleChange: function(e) {
var jsonPath, onChange, ref1;
ref1 = this.props, onChange = ref1.onChange, jsonPath = ref1.jsonPath;
return typeof onChange === "function" ? onChange(e.target.value, jsonPath) : void 0;
},
isChecked: function() {
return this.refs.input.checked;
}
});
module.exports = RadioInput;
}).call(this);