UNPKG

3.64 kBJavaScriptView Raw
1/*
2 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { __assign, __decorate, __extends, __rest } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20import { AbstractPureComponent2, Classes, DISPLAYNAME_PREFIX, Utils, } from "../../common";
21import { isReactNodeEmpty } from "../../common/utils";
22import { Icon, IconSize } from "../icon/icon";
23import { Text } from "../text/text";
24var Tag = /** @class */ (function (_super) {
25 __extends(Tag, _super);
26 function Tag() {
27 var _this = _super !== null && _super.apply(this, arguments) || this;
28 _this.onRemoveClick = function (e) {
29 var _a, _b;
30 (_b = (_a = _this.props).onRemove) === null || _b === void 0 ? void 0 : _b.call(_a, e, _this.props);
31 };
32 return _this;
33 }
34 Tag.prototype.render = function () {
35 var _a;
36 var _b = this.props, active = _b.active, children = _b.children, className = _b.className, fill = _b.fill, icon = _b.icon, intent = _b.intent, interactive = _b.interactive, large = _b.large, minimal = _b.minimal, multiline = _b.multiline, onRemove = _b.onRemove, rightIcon = _b.rightIcon, round = _b.round, _c = _b.tabIndex, tabIndex = _c === void 0 ? 0 : _c, htmlTitle = _b.htmlTitle, elementRef = _b.elementRef, htmlProps = __rest(_b, ["active", "children", "className", "fill", "icon", "intent", "interactive", "large", "minimal", "multiline", "onRemove", "rightIcon", "round", "tabIndex", "htmlTitle", "elementRef"]);
37 var isRemovable = Utils.isFunction(onRemove);
38 var tagClasses = classNames(Classes.TAG, Classes.intentClass(intent), (_a = {},
39 _a[Classes.ACTIVE] = active,
40 _a[Classes.FILL] = fill,
41 _a[Classes.INTERACTIVE] = interactive,
42 _a[Classes.LARGE] = large,
43 _a[Classes.MINIMAL] = minimal,
44 _a[Classes.ROUND] = round,
45 _a), className);
46 var isLarge = large || tagClasses.indexOf(Classes.LARGE) >= 0;
47 var removeButton = isRemovable ? (React.createElement("button", { "aria-label": "Remove", type: "button", className: Classes.TAG_REMOVE, onClick: this.onRemoveClick, tabIndex: interactive ? tabIndex : undefined },
48 React.createElement(Icon, { icon: "small-cross", size: isLarge ? IconSize.LARGE : IconSize.STANDARD }))) : null;
49 return (React.createElement("span", __assign({}, htmlProps, { className: tagClasses, tabIndex: interactive ? tabIndex : undefined, ref: elementRef }),
50 React.createElement(Icon, { icon: icon }),
51 !isReactNodeEmpty(children) && (React.createElement(Text, { className: Classes.FILL, ellipsize: !multiline, tagName: "span", title: htmlTitle }, children)),
52 React.createElement(Icon, { icon: rightIcon }),
53 removeButton));
54 };
55 Tag.displayName = DISPLAYNAME_PREFIX + ".Tag";
56 Tag = __decorate([
57 polyfill
58 ], Tag);
59 return Tag;
60}(AbstractPureComponent2));
61export { Tag };
62//# sourceMappingURL=tag.js.map
\No newline at end of file