UNPKG

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