UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

197 lines (166 loc) 9.13 kB
'use strict'; var _textareaItem = require('antd-mobile/lib/textarea-item'); var _textareaItem2 = _interopRequireDefault(_textareaItem); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); require('antd-mobile/lib/textarea-item/style/css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _FunctionUtil = require('../../utils/FunctionUtil'); var _YYIcon = require('../icon/YYIcon'); var _YYIcon2 = _interopRequireDefault(_YYIcon); require('./YYTextareaItem.less'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var YYTextareaItem = function (_React$Component) { _inherits(YYTextareaItem, _React$Component); function YYTextareaItem() { var _ref; var _temp, _this, _ret; _classCallCheck(this, YYTextareaItem); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYTextareaItem.__proto__ || Object.getPrototypeOf(YYTextareaItem)).call.apply(_ref, [this].concat(args))), _this), _this.onChange = function (value) { var fields = {}; fields[_this.props.field] = { dirty: true, errors: undefined, name: _this.props.field, touched: true, validating: true, value: value }; _this.props.form.setFields(fields); if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) _this.props.onChange(value); }, _this.onBlur = function (value) { if ((0, _FunctionUtil.isFunction)(_this.props.onBlur)) _this.props.onBlur(value); }, _this.onFocus = function (value) { if ((0, _FunctionUtil.isFunction)(_this.props.onBlur)) _this.props.onFocus(value); }, _this.onErrorClick = function () { if ((0, _FunctionUtil.isFunction)(_this.props.onErrorClick)) _this.props.onErrorClick(); }, _this.validateCallBack = function (rule, value, callback) { if ((0, _FunctionUtil.isFunction)(_this.props.validateCallBack)) { _this.props.validateCallBack(rule, value, callback); callback(); } else { callback(); } }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(YYTextareaItem, [{ key: 'render', value: function render() { var getFieldProps = this.props.form.getFieldProps; var _props = this.props, iconColor = _props.iconColor, icon = _props.icon, showIcon = _props.showIcon, field = _props.field, value = _props.value, required = _props.required, trigger = _props.trigger, label = _props.label, direction = _props.direction, placeholder = _props.placeholder, editable = _props.editable, disabled = _props.disabled, clear = _props.clear, rows = _props.rows, count = _props.count, hasError = _props.hasError, autoHeight = _props.autoHeight, labelNumber = _props.labelNumber, visible = _props.visible, validateCallBack = _props.validateCallBack, findUI = _props.findUI, offline = _props.offline, parentType = _props.parentType, uiorigin = _props.uiorigin, RunInDesign = _props.RunInDesign, uititle = _props.uititle, uitype = _props.uitype, uikey = _props.uikey, nid = _props.nid, control_event = _props.control_event, restProps = _objectWithoutProperties(_props, ['iconColor', 'icon', 'showIcon', 'field', 'value', 'required', 'trigger', 'label', 'direction', 'placeholder', 'editable', 'disabled', 'clear', 'rows', 'count', 'hasError', 'autoHeight', 'labelNumber', 'visible', 'validateCallBack', 'findUI', 'offline', 'parentType', 'uiorigin', 'RunInDesign', 'uititle', 'uitype', 'uikey', 'nid', 'control_event']); var wrapClz = (0, _classnames2.default)('yy-textarea-item', !visible && 'hidden', this.props.className); var requiredMsg = '必填项' + label + '未填写'; var classz = (0, _classnames2.default)(direction, !visible && 'hidden', this.props.className); var labelCl = (0, _classnames2.default)('label', required && 'yy-label-required'); return _react2.default.createElement( 'div', { className: classz }, showIcon && direction === 'outside' && _react2.default.createElement(_YYIcon2.default, { type: icon, color: iconColor, style: { float: 'left', padding: '10px 0 8px 12px', marginRight: '3px' }, size: 'xs' }), direction === 'outside' && _react2.default.createElement( 'div', { className: labelCl }, label ), _react2.default.createElement(_textareaItem2.default, _extends({}, restProps, { className: wrapClz }, (0, _FunctionUtil.isFunction)(getFieldProps) ? getFieldProps(field, { initialValue: value, rules: [{ required: required, message: requiredMsg }, { validator: this.validateCallBack }], trigger: trigger, valuePropName: 'value' }) : null, { placeholder: placeholder, editable: editable, disabled: disabled, clear: clear, rows: rows, count: count, onChange: this.onChange, onBlur: this.onBlur, onFocus: this.onFocus, error: hasError, onErrorClick: this.onErrorClick, autoHeight: autoHeight, labelNumber: labelNumber, title: direction === 'inside' && label, name: field })) ); } }]); return YYTextareaItem; }(_react2.default.Component); YYTextareaItem.defaultProps = { field: "default", value: null, required: false, trigger: "onChange", placeholder: '', editable: true, disabled: false, clear: true, rows: 1, count: 0, hasError: false, autoHeight: false, labelNumber: 5, label: "", visible: true, direction: 'inside', showIcon: false, icon: "Home", iconColor: "red", findUI: '', offline: false, parentType: '', uiorigin: '', RunInDesign: false, uititle: '', uitype: '', uikey: '', nid: '', control_event: {}, validateCallBack: '' }; module.exports = YYTextareaItem;