UNPKG

@uifabric/experiments

Version:

Experimental React components for building experiences for Office 365.

78 lines 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var Utilities_1 = require("../../Utilities"); var ShimmerElementsGroup_1 = require("./ShimmerElementsGroup/ShimmerElementsGroup"); var TRANSITION_ANIMATION_INTERVAL = 200; /* ms */ var getClassNames = Utilities_1.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 }; _this._warnDeprecations({ isBaseStyle: 'customElementsGroup', width: 'widthInPercentage or widthInPixel', lineElements: 'shimmerElements' }); _this._warnMutuallyExclusive({ lineElements: 'shimmerElements', customElementsGroup: 'lineElements' }); 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, width = _a.width, lineElements = _a.lineElements, shimmerElements = _a.shimmerElements, children = _a.children, isDataLoaded = _a.isDataLoaded, isBaseStyle = _a.isBaseStyle, widthInPercentage = _a.widthInPercentage, widthInPixel = _a.widthInPixel, className = _a.className, customElementsGroup = _a.customElementsGroup, theme = _a.theme, ariaLabel = _a.ariaLabel; var contentLoaded = this.state.contentLoaded; // lineElements is a deprecated prop so need to check which one was used. var elements = shimmerElements || lineElements; this._classNames = getClassNames(styles, { theme: theme, width: width, isDataLoaded: isDataLoaded, widthInPercentage: widthInPercentage, widthInPixel: widthInPixel, className: className, transitionAnimationInterval: TRANSITION_ANIMATION_INTERVAL }); return (React.createElement("div", { className: this._classNames.root }, !contentLoaded && (React.createElement("div", { className: this._classNames.shimmerWrapper }, isBaseStyle ? (children // isBaseStyle prop is deprecated and this check needs to be removed in the future ) : customElementsGroup ? (customElementsGroup) : (React.createElement(ShimmerElementsGroup_1.ShimmerElementsGroup, { shimmerElements: elements })))), !isBaseStyle && children && React.createElement("div", { className: this._classNames.dataWrapper }, children), ariaLabel && !isDataLoaded && (React.createElement("div", { role: "status", "aria-live": "polite" }, React.createElement(Utilities_1.DelayedRender, null, React.createElement("div", { className: this._classNames.screenReaderText }, ariaLabel)))))); }; ShimmerBase.defaultProps = { isDataLoaded: false, isBaseStyle: false }; return ShimmerBase; }(Utilities_1.BaseComponent)); exports.ShimmerBase = ShimmerBase; //# sourceMappingURL=Shimmer.base.js.map