UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

1 lines 2.21 kB
import"../../CommonImports";import"../../Core/core.css";import"./ProgressBar.css";import*as React from"react";import{ObservableLike}from"../../Core/Observable";import{TimerManagement}from"../../Core/TimerManagement";import{Observer}from"../../Observer";import{css}from"../../Util";class IndeterminateProgressBar extends React.PureComponent{constructor(t){super(t),this.timerManagement=new TimerManagement,this.transitionDurations=350,this.randomize25=t=>.25*(Math.random()*t*2+(1-t)),this.randomize75=t=>.75*(Math.random()*t*2+(1-t)),this.asymptoticApproach=t=>1-1/Math.sqrt(t+1),this.done=()=>{this.state.progress!==1/0&&this.setState({progress:1/0})},this.increment=()=>{this.state.progress!==1/0&&this.setState({progress:this.state.progress+this.randomize25(1)})},this.reset=()=>{0!==this.state.progress&&this.setState({progress:0})},this.shouldRun=()=>null!=this.props.loading,this.updateProgress=t=>{t?this.reset():this.done()},this.state={progress:0}}get transitionDuration(){return this.state.progress?this.transitionDurations:0}render(){return React.createElement(Observer,{loading:{observableValue:this.props.loading,filter:this.updateProgress}},()=>React.createElement("span",{className:css(this.props.className,"bolt-progress-bar-container flex-row flex-noshrink flex-grow scroll-hidden")},React.createElement("span",{className:css(this.props.progressBarClassName,"bolt-progress-bar-bar",this.state.progress===1/0&&"complete"),style:{transform:`scaleX(${this.asymptoticApproach(this.state.progress)})`}})))}componentDidMount(){this.shouldRun()&&this.scheduleUpdate(this.increment,0,!1)}componentDidUpdate(t){this.shouldRun()&&(this.state.progress==1/0?this.props.loadingAnimationComplete&&this.timerManagement.setTimeout(()=>{this.props.loadingAnimationComplete&&this.props.loadingAnimationComplete()},this.transitionDuration):this.scheduleUpdate(this.increment,this.transitionDuration,!1)),void 0===this.props.loading?this.reset():void 0!==t.loading&&!ObservableLike.getValue(t.loading)||ObservableLike.getValue(this.props.loading)||this.done()}componentWillUnmount(){this.timerManagement.dispose()}scheduleUpdate(t,e,s){this.timerManagement.setTimeout(()=>{t()},e)}}export{IndeterminateProgressBar};