UNPKG

ldx-widgets

Version:

widgets

78 lines (70 loc) 2.29 kB
(function() { var CheckboxInput, PropTypes, 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; CheckboxInput = createClass({ displayName: 'CheckboxInput', propTypes: { name: PropTypes.string, className: PropTypes.string, wrapperLabel: PropTypes.string, disabled: PropTypes.bool, onChange: PropTypes.func, tabIndex: PropTypes.number, id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) }, getDefaultProps: function() { return { className: 'checkbox-input', disabled: false, wrapperLabel: null, name: null }; }, render: function() { var checked, className, disabled, id, inputProps, name, onChange, ref1, tabIndex, 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; inputProps = { key: 'input', ref: 'input', name: name, type: 'checkbox', 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: 'checkbox-input-label', htmlFor: id }, [ input(inputProps), span({ key: 'label' }, wrapperLabel) ]); } else { return input(inputProps); } }, getValue: function() { return this.refs.input.checked; }, handleChange: function(e) { var jsonPath, onChange, ref1; ref1 = this.props, onChange = ref1.onChange, jsonPath = ref1.jsonPath; return typeof onChange === "function" ? onChange(e.target.checked, jsonPath) : void 0; } }); module.exports = CheckboxInput; }).call(this);