amis
Version:
一种MIS页面生成工具
88 lines (87 loc) • 4.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputBox = void 0;
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importDefault(require("react"));
var theme_1 = require("../theme");
var Input_1 = tslib_1.__importDefault(require("./Input"));
var helper_1 = require("../utils/helper");
var icons_1 = require("./icons");
var InputBox = /** @class */ (function (_super) {
tslib_1.__extends(InputBox, _super);
function InputBox() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
isFocused: false
};
return _this;
}
InputBox.prototype.clearValue = function (e) {
e.preventDefault();
var onClear = this.props.onChange;
var onChange = this.props.onChange;
onClear === null || onClear === void 0 ? void 0 : onClear(e);
onChange === null || onChange === void 0 ? void 0 : onChange('');
};
InputBox.prototype.handleChange = function (e) {
var onChange = this.props.onChange;
onChange && onChange(e.currentTarget.value);
};
InputBox.prototype.handleFocus = function (e) {
var onFocus = this.props.onFocus;
onFocus && onFocus(e);
this.setState({
isFocused: true
});
};
InputBox.prototype.handleBlur = function (e) {
var onBlur = this.props.onBlur;
onBlur && onBlur(e);
this.setState({
isFocused: false
});
};
InputBox.prototype.render = function () {
var _a = this.props, className = _a.className, cx = _a.classnames, classPrefix = _a.classPrefix, clearable = _a.clearable, disabled = _a.disabled, hasError = _a.hasError, value = _a.value, placeholder = _a.placeholder, result = _a.prefix, children = _a.children, rest = tslib_1.__rest(_a, ["className", "classnames", "classPrefix", "clearable", "disabled", "hasError", "value", "placeholder", "prefix", "children"]);
var isFocused = this.state.isFocused;
return (react_1.default.createElement("div", { className: cx('InputBox', className, isFocused ? 'is-focused' : '', disabled ? 'is-disabled' : '', hasError ? 'is-error' : '', rest.onClick ? 'is-clickable' : '') },
result,
react_1.default.createElement(Input_1.default, tslib_1.__assign({}, rest, { value: value || '', onChange: this.handleChange, placeholder: placeholder, onFocus: this.handleFocus, onBlur: this.handleBlur, size: 12 })),
children,
clearable && !disabled && value ? (react_1.default.createElement("a", { onClick: this.clearValue, className: cx('InputBox-clear') },
react_1.default.createElement(icons_1.Icon, { icon: "close", className: "icon" }))) : null));
};
var _a;
InputBox.defaultProps = {
clearable: true,
placeholder: ''
};
tslib_1.__decorate([
helper_1.autobind,
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", void 0)
], InputBox.prototype, "clearValue", null);
tslib_1.__decorate([
helper_1.autobind,
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [typeof (_a = typeof react_1.default !== "undefined" && react_1.default.ChangeEvent) === "function" ? _a : Object]),
tslib_1.__metadata("design:returntype", void 0)
], InputBox.prototype, "handleChange", null);
tslib_1.__decorate([
helper_1.autobind,
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", void 0)
], InputBox.prototype, "handleFocus", null);
tslib_1.__decorate([
helper_1.autobind,
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", void 0)
], InputBox.prototype, "handleBlur", null);
return InputBox;
}(react_1.default.Component));
exports.InputBox = InputBox;
exports.default = theme_1.themeable(InputBox);
//# sourceMappingURL=./components/InputBox.js.map