UNPKG

ost-ui

Version:
60 lines (47 loc) 1.87 kB
import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import checkedSvg from './images/checked.svg'; import uncheckedSvg from './images/unchecked.svg'; var checkedImg = React.createElement('img', { src: checkedSvg }); var uncheckedImg = React.createElement('img', { src: uncheckedSvg }); var OstCheckbox = function (_Component) { _inherits(OstCheckbox, _Component); function OstCheckbox(props) { _classCallCheck(this, OstCheckbox); var _this = _possibleConstructorReturn(this, _Component.call(this, props)); _this.state = { checked: !!props.defaultChecked }; return _this; } OstCheckbox.prototype.render = function render() { var _this2 = this; var _props = this.props, onClick = _props.onClick, style = _props.style, disabled = _props.disabled, checked = _props.checked; return React.createElement( 'div', { className: classnames("ost-checkbox", { 'ost-checkbox-disabled': disabled }), style: style, onClick: checked ? onClick : function () { if (disabled) return; onClick && onClick({ 'checked': !_this2.state.checked }); _this2.setState({ checked: !_this2.state.checked }); } }, typeof checked === 'boolean' && (checked ? checkedImg : uncheckedImg), typeof checked !== 'boolean' && (this.state.checked ? checkedImg : uncheckedImg) ); }; return OstCheckbox; }(Component); export default OstCheckbox; OstCheckbox.propTypes = { onClick: PropTypes.func, style: PropTypes.object, defaultChecked: PropTypes.bool };