/*
* Copyright 2017 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import classNames from "classnames";
import * as React from "react";
import { Classes } from '@blueprintjs/core';
import IconSvgPaths from "static/json/icons";
import PropTypes from 'prop-types';
export default class Icon extends React.Component{
static displayName = `af.Icon`;
static SIZE_STANDARD = 16;
static SIZE_LARGE = 20;
render() {
const { icon } = this.props;
if (icon == null || typeof icon === "boolean") {
return null;
} else if (typeof icon !== "string") {
return icon;
}
const {
className,
color,
htmlTitle,
iconSize = Icon.SIZE_STANDARD,
height,
width,
intent,
title = icon,
tagName = "span",
...htmlprops
} = this.props;
// choose which pixel grid is most appropriate for given icon size
const pixelGridSize = iconSize >= Icon.SIZE_LARGE ? Icon.SIZE_LARGE : Icon.SIZE_STANDARD;
const iconPath = this.getSvgPath(icon);
if (!iconPath){ return null; }
// render path elements, or nothing if icon name is unknown.
const paths = this.renderSvgPaths(iconPath.path);
const classes = classNames(Classes.ICON, Classes.iconClass(icon), Classes.intentClass(intent), className);
const viewBox = iconPath.viewBox;
const computedHeight = height || iconSize;
const computedWidth = width || iconSize;
return React.createElement(
tagName,
{
...htmlprops,
className: classes,
title: htmlTitle,
},
,
);
}
getSvgPath(iconName) {
const svgPathsRecord = IconSvgPaths;
const pathStrings = svgPathsRecord[iconName];
return pathStrings;
}
/** Render `` elements for the given icon name. Returns `null` if name is unknown. */
renderSvgPaths(pathStrings) {
if (pathStrings == null) {
return null;
}
return pathStrings.map((d, i) => );
}
}
Icon.propTypes = {
/**
* Color of icon. This is used as the `fill` attribute on the `