UNPKG

modo-mobile

Version:

A mobile UI toolkit, based on React

83 lines (72 loc) 2.78 kB
import _defineProperty from 'babel-runtime/helpers/defineProperty'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _createClass from 'babel-runtime/helpers/createClass'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import classnames from 'classnames'; import * as React from 'react'; import Icon from '../icon'; var Agree = function (_React$PureComponent) { _inherits(Agree, _React$PureComponent); function Agree(props) { _classCallCheck(this, Agree); var _this = _possibleConstructorReturn(this, (Agree.__proto__ || Object.getPrototypeOf(Agree)).call(this, props)); _this.handleClick = function () { var _this$props = _this.props, onChange = _this$props.onChange, disabled = _this$props.disabled; if (!disabled) { _this.setState({ value: !_this.state.value }); if (onChange) { onChange(!_this.state.value); } } }; _this.state = { value: props.value || props.defaultValue }; return _this; } _createClass(Agree, [{ key: 'render', value: function render() { var _classnames; var value = this.state.value; var _props = this.props, prefixCls = _props.prefixCls, children = _props.children, disabled = _props.disabled, className = _props.className; var wrapCls = classnames(prefixCls, className, (_classnames = {}, _defineProperty(_classnames, prefixCls + '-disabled', disabled), _defineProperty(_classnames, prefixCls + '-checked', value), _classnames)); return React.createElement( 'div', { className: wrapCls }, React.createElement( 'div', { className: prefixCls + '-icon', onClick: this.handleClick }, React.createElement(Icon, { type: 'check-circle' }) ), React.createElement( 'div', { className: prefixCls + '-content' }, children ) ); } }], [{ key: 'getDerivedStateFromProps', value: function getDerivedStateFromProps(nextProps) { if ('value' in nextProps) { return { value: nextProps.value }; } } }]); return Agree; }(React.PureComponent); export default Agree; Agree.defaultProps = { disabled: false, prefixCls: 'm-agree' };