UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

60 lines 3.17 kB
import * as tslib_1 from "tslib"; /* tslint:disable */ import * as React from 'react'; /* tslint:enable */ import { IconType } from './Icon.types'; import { Image } from '../Image/Image'; import { ImageLoadState } from '../Image/Image.types'; import { css, getNativeProps, htmlElementProperties, BaseComponent } from '../../Utilities'; import { getIcon } from '../../Styling'; import { getClassNames } from './Icon.classNames'; var Icon = /** @class */ (function (_super) { tslib_1.__extends(Icon, _super); function Icon(props) { var _this = _super.call(this, props) || this; _this.onImageLoadingStateChange = function (state) { if (_this.props.imageProps && _this.props.imageProps.onLoadingStateChange) { _this.props.imageProps.onLoadingStateChange(state); } if (state === ImageLoadState.error) { _this.setState({ imageLoadError: true }); } }; _this.state = { imageLoadError: false, }; return _this; } Icon.prototype.render = function () { var _a = this.props, ariaLabel = _a.ariaLabel, className = _a.className, styles = _a.styles, iconName = _a.iconName, imageErrorAs = _a.imageErrorAs; var classNames = getClassNames(styles); var containerProps = ariaLabel ? { 'aria-label': ariaLabel, 'data-icon-name': iconName, } : { role: 'presentation', 'aria-hidden': true, 'data-icon-name': iconName, }; if (this.props.iconType === IconType.image || this.props.iconType === IconType.Image) { var containerClassName = css('ms-Icon-imageContainer', classNames.root, classNames.imageContainer, className); var imageLoadError = this.state.imageLoadError; var imageProps = tslib_1.__assign({}, this.props.imageProps, { onLoadingStateChange: this.onImageLoadingStateChange }); var ImageType = imageLoadError && imageErrorAs || Image; return (React.createElement("div", tslib_1.__assign({}, containerProps, { className: css(containerClassName, classNames.root) }), React.createElement(ImageType, tslib_1.__assign({}, imageProps)))); } else if (typeof iconName === 'string' && iconName.length === 0) { return (React.createElement("i", tslib_1.__assign({}, containerProps, getNativeProps(this.props, htmlElementProperties), { className: css('ms-Icon-placeHolder', classNames.rootHasPlaceHolder, this.props.className) }))); } else { var iconDefinition = getIcon(iconName) || { subset: { className: undefined }, code: undefined }; return (React.createElement("i", tslib_1.__assign({}, containerProps, getNativeProps(this.props, htmlElementProperties), { className: css(iconDefinition.subset.className, classNames.root, this.props.className) }), iconDefinition.code)); } }; return Icon; }(BaseComponent)); export { Icon }; //# sourceMappingURL=Icon.js.map