UNPKG

3.84 kBJavaScriptView Raw
1/*
2 * Copyright 2017 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, __extends, __rest } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { iconNameToPathsRecordKey, IconSvgPaths16, IconSvgPaths20 } from "@blueprintjs/icons";
20import { AbstractPureComponent2, Classes, DISPLAYNAME_PREFIX } from "../../common";
21import { uniqueId } from "../../common/utils";
22export var IconSize;
23(function (IconSize) {
24 IconSize[IconSize["STANDARD"] = 16] = "STANDARD";
25 IconSize[IconSize["LARGE"] = 20] = "LARGE";
26})(IconSize || (IconSize = {}));
27/**
28 * Icon component.
29 *
30 * @see https://blueprintjs.com/docs/#core/components/icon
31 */
32var Icon = /** @class */ (function (_super) {
33 __extends(Icon, _super);
34 function Icon() {
35 return _super !== null && _super.apply(this, arguments) || this;
36 }
37 Icon.prototype.render = function () {
38 var icon = this.props.icon;
39 if (icon == null || typeof icon === "boolean") {
40 return null;
41 }
42 else if (typeof icon !== "string") {
43 return icon;
44 }
45 var _a = this.props, className = _a.className, color = _a.color, htmlTitle = _a.htmlTitle,
46 // eslint-disable-next-line deprecation/deprecation
47 iconSize = _a.iconSize, intent = _a.intent, _b = _a.size, size = _b === void 0 ? iconSize !== null && iconSize !== void 0 ? iconSize : IconSize.STANDARD : _b, title = _a.title, _c = _a.tagName, tagName = _c === void 0 ? "span" : _c, htmlprops = __rest(_a, ["className", "color", "htmlTitle", "iconSize", "intent", "size", "title", "tagName"]);
48 // choose which pixel grid is most appropriate for given icon size
49 var pixelGridSize = size >= IconSize.LARGE ? IconSize.LARGE : IconSize.STANDARD;
50 // render path elements, or nothing if icon name is unknown.
51 var paths = this.renderSvgPaths(pixelGridSize, icon);
52 var classes = classNames(Classes.ICON, Classes.iconClass(icon), Classes.intentClass(intent), className);
53 var viewBox = "0 0 ".concat(pixelGridSize, " ").concat(pixelGridSize);
54 var titleId = uniqueId("iconTitle");
55 return React.createElement(tagName, __assign(__assign({}, htmlprops), { "aria-hidden": title ? undefined : true, className: classes, title: htmlTitle }), React.createElement("svg", { fill: color, "data-icon": icon, width: size, height: size, viewBox: viewBox, "aria-labelledby": title ? titleId : undefined, role: "img" },
56 title && React.createElement("title", { id: titleId }, title),
57 paths));
58 };
59 /** Render `<path>` elements for the given icon name. Returns `null` if name is unknown. */
60 Icon.prototype.renderSvgPaths = function (pathsSize, iconName) {
61 var svgPathsRecord = pathsSize === IconSize.STANDARD ? IconSvgPaths16 : IconSvgPaths20;
62 var paths = svgPathsRecord[iconNameToPathsRecordKey(iconName)];
63 if (paths == null) {
64 return null;
65 }
66 return paths.map(function (path, i) { return React.createElement("path", { key: i, d: path, fillRule: "evenodd" }); });
67 };
68 Icon.displayName = "".concat(DISPLAYNAME_PREFIX, ".Icon");
69 return Icon;
70}(AbstractPureComponent2));
71export { Icon };
72//# sourceMappingURL=icon.js.map
\No newline at end of file