UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

61 lines 3.11 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { BaseComponent, classNamesFunction, DelayedRender, getNativeProps, divProperties } from '../../Utilities'; import { ShimmerElementsGroup } from './ShimmerElementsGroup/ShimmerElementsGroup'; var TRANSITION_ANIMATION_INTERVAL = 200; /* ms */ var getClassNames = classNamesFunction(); var ShimmerBase = /** @class */ (function (_super) { tslib_1.__extends(ShimmerBase, _super); function ShimmerBase(props) { var _this = _super.call(this, props) || this; _this.state = { contentLoaded: props.isDataLoaded }; return _this; } ShimmerBase.prototype.componentWillReceiveProps = function (nextProps) { var _this = this; var isDataLoaded = nextProps.isDataLoaded; if (this._lastTimeoutId !== undefined) { this._async.clearTimeout(this._lastTimeoutId); this._lastTimeoutId = undefined; } if (isDataLoaded) { this._lastTimeoutId = this._async.setTimeout(function () { _this.setState({ contentLoaded: isDataLoaded }); _this._lastTimeoutId = undefined; }, TRANSITION_ANIMATION_INTERVAL); } else { this.setState({ contentLoaded: isDataLoaded }); } }; ShimmerBase.prototype.render = function () { var _a = this.props, styles = _a.styles, shimmerElements = _a.shimmerElements, children = _a.children, isDataLoaded = _a.isDataLoaded, width = _a.width, className = _a.className, customElementsGroup = _a.customElementsGroup, theme = _a.theme, ariaLabel = _a.ariaLabel; var contentLoaded = this.state.contentLoaded; this._classNames = getClassNames(styles, { theme: theme, isDataLoaded: isDataLoaded, className: className, transitionAnimationInterval: TRANSITION_ANIMATION_INTERVAL }); var divProps = getNativeProps(this.props, divProperties); return (React.createElement("div", tslib_1.__assign({}, divProps, { className: this._classNames.root }), !contentLoaded && (React.createElement("div", { style: { width: width ? width : '100%' }, className: this._classNames.shimmerWrapper }, customElementsGroup ? customElementsGroup : React.createElement(ShimmerElementsGroup, { shimmerElements: shimmerElements }))), children && React.createElement("div", { className: this._classNames.dataWrapper }, children), ariaLabel && !isDataLoaded && (React.createElement("div", { role: "status", "aria-live": "polite" }, React.createElement(DelayedRender, null, React.createElement("div", { className: this._classNames.screenReaderText }, ariaLabel)))))); }; ShimmerBase.defaultProps = { isDataLoaded: false }; return ShimmerBase; }(BaseComponent)); export { ShimmerBase }; //# sourceMappingURL=Shimmer.base.js.map