@blueprintjs/core
Version:
Core styles & components
71 lines • 3.24 kB
JavaScript
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the terms of the LICENSE file distributed with this project.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var classnames_1 = tslib_1.__importDefault(require("classnames"));
var React = tslib_1.__importStar(require("react"));
var Classes = tslib_1.__importStar(require("../../common/classes"));
var props_1 = require("../../common/props");
var icon_1 = require("../icon/icon");
var DEFAULT_RIGHT_ELEMENT_WIDTH = 10;
var InputGroup = /** @class */ (function (_super) {
tslib_1.__extends(InputGroup, _super);
function InputGroup() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
rightElementWidth: DEFAULT_RIGHT_ELEMENT_WIDTH,
};
_this.refHandlers = {
rightElement: function (ref) { return (_this.rightElement = ref); },
};
return _this;
}
InputGroup.prototype.render = function () {
var _a = this.props, className = _a.className, intent = _a.intent, large = _a.large, small = _a.small, leftIcon = _a.leftIcon, round = _a.round;
var classes = classnames_1.default(Classes.INPUT_GROUP, Classes.intentClass(intent), (_b = {},
_b[Classes.DISABLED] = this.props.disabled,
_b[Classes.LARGE] = large,
_b[Classes.SMALL] = small,
_b[Classes.ROUND] = round,
_b), className);
var style = tslib_1.__assign({}, this.props.style, { paddingRight: this.state.rightElementWidth });
return (React.createElement("div", { className: classes },
React.createElement(icon_1.Icon, { icon: leftIcon }),
React.createElement("input", tslib_1.__assign({ type: "text" }, props_1.removeNonHTMLProps(this.props), { className: Classes.INPUT, ref: this.props.inputRef, style: style })),
this.maybeRenderRightElement()));
var _b;
};
InputGroup.prototype.componentDidMount = function () {
this.updateInputWidth();
};
InputGroup.prototype.componentDidUpdate = function () {
this.updateInputWidth();
};
InputGroup.prototype.maybeRenderRightElement = function () {
var rightElement = this.props.rightElement;
if (rightElement == null) {
return undefined;
}
return (React.createElement("span", { className: Classes.INPUT_ACTION, ref: this.refHandlers.rightElement }, rightElement));
};
InputGroup.prototype.updateInputWidth = function () {
if (this.rightElement != null) {
var clientWidth = this.rightElement.clientWidth;
// small threshold to prevent infinite loops
if (Math.abs(clientWidth - this.state.rightElementWidth) > 2) {
this.setState({ rightElementWidth: clientWidth });
}
}
else {
this.setState({ rightElementWidth: DEFAULT_RIGHT_ELEMENT_WIDTH });
}
};
InputGroup.displayName = props_1.DISPLAYNAME_PREFIX + ".InputGroup";
return InputGroup;
}(React.PureComponent));
exports.InputGroup = InputGroup;
//# sourceMappingURL=inputGroup.js.map
;