UNPKG

3.87 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, __decorate, __extends, __rest } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20import { IconSvgPaths16, IconSvgPaths20 } from "@blueprintjs/icons";
21import { AbstractPureComponent2, Classes, DISPLAYNAME_PREFIX } from "../../common";
22export var IconSize;
23(function (IconSize) {
24 IconSize[IconSize["STANDARD"] = 16] = "STANDARD";
25 IconSize[IconSize["LARGE"] = 20] = "LARGE";
26})(IconSize || (IconSize = {}));
27var Icon = /** @class */ (function (_super) {
28 __extends(Icon, _super);
29 function Icon() {
30 return _super !== null && _super.apply(this, arguments) || this;
31 }
32 Icon.prototype.render = function () {
33 var icon = this.props.icon;
34 if (icon == null || typeof icon === "boolean") {
35 return null;
36 }
37 else if (typeof icon !== "string") {
38 return icon;
39 }
40 var _a = this.props, className = _a.className, color = _a.color, htmlTitle = _a.htmlTitle,
41 // eslint-disable-next-line deprecation/deprecation
42 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"]);
43 // choose which pixel grid is most appropriate for given icon size
44 var pixelGridSize = size >= IconSize.LARGE ? IconSize.LARGE : IconSize.STANDARD;
45 // render path elements, or nothing if icon name is unknown.
46 var paths = this.renderSvgPaths(pixelGridSize, icon);
47 // eslint-disable-next-line deprecation/deprecation
48 var classes = classNames(Classes.ICON, Classes.iconClass(icon), Classes.intentClass(intent), className);
49 var viewBox = "0 0 " + pixelGridSize + " " + pixelGridSize;
50 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 },
51 title && React.createElement("desc", null, title),
52 paths));
53 };
54 /** Render `<path>` elements for the given icon name. Returns `null` if name is unknown. */
55 Icon.prototype.renderSvgPaths = function (pathsSize, iconName) {
56 var svgPathsRecord = pathsSize === IconSize.STANDARD ? IconSvgPaths16 : IconSvgPaths20;
57 var pathStrings = svgPathsRecord[iconName];
58 if (pathStrings == null) {
59 return null;
60 }
61 return pathStrings.map(function (d, i) { return React.createElement("path", { key: i, d: d, fillRule: "evenodd" }); });
62 };
63 Icon.displayName = DISPLAYNAME_PREFIX + ".Icon";
64 /** @deprecated use IconSize.STANDARD */
65 Icon.SIZE_STANDARD = IconSize.STANDARD;
66 /** @deprecated use IconSize.LARGE */
67 Icon.SIZE_LARGE = IconSize.LARGE;
68 Icon = __decorate([
69 polyfill
70 ], Icon);
71 return Icon;
72}(AbstractPureComponent2));
73export { Icon };
74//# sourceMappingURL=icon.js.map
\No newline at end of file