@sishuguojixuefu/react-native-form
Version:
51 lines • 2.71 kB
JavaScript
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const antd_mobile_rn_1 = require("@sishuguojixuefu/antd-mobile-rn");
const string_width_1 = __importDefault(require("string-width"));
const lodash_omit_1 = __importDefault(require("lodash.omit"));
const getFieldDecorator_1 = __importDefault(require("../utils/getFieldDecorator"));
const Label_1 = __importDefault(require("./helper/Label"));
const ErrorTip_1 = __importDefault(require("./helper/ErrorTip"));
class Input extends react_1.Component {
constructor() {
super(...arguments);
this._onChange = (value) => {
const { onChange } = this.props;
onChange && onChange(value);
};
}
componentWillMount() {
const { form, id, initialValue, rules } = this.props;
const defaultStrValue = initialValue && initialValue.toString();
this.fieldDecorator = getFieldDecorator_1.default(form, id, defaultStrValue, rules);
}
render() {
const { icon, placeholder, label, required, form, id, textAlign, maxLength, last, multiline, height } = this.props;
const omitProps = lodash_omit_1.default(this.props, ['error', 'labelNumber']);
return (react_1.default.createElement(ErrorTip_1.default, { error: form.getFieldError(id), last: last }, this.fieldDecorator(react_1.default.createElement(antd_mobile_rn_1.InputItem, Object.assign({ multiline: multiline }, omitProps, { last: true, clear: true, style: height
? { height, marginLeft: 5, fontSize: 16, color: '#6c6c6c' }
: { marginLeft: 5, fontSize: 16, color: '#6c6c6c' }, itemStyle: height ? { height, marginLeft: 0 } : { marginLeft: 0 }, textAlign: textAlign, onChange: this._onChange, labelNumber: label ? string_width_1.default(label) / 2 + 1 : 0, placeholder: placeholder, maxLength: maxLength && maxLength > 0 ? maxLength : undefined }),
react_1.default.createElement(Label_1.default, { label: label, icon: icon, required: required })))));
}
}
exports.default = Input;
Input.defaultProps = {
required: false,
placeholder: '请输入',
textAlign: 'right',
maxLength: 0,
last: false,
multiline: false,
};
//# sourceMappingURL=Input.js.map