Spinner and progress in React Progress button component

8 Dec 202314 minutes to read

Change spinner position

Spinner position can be changed by modifying the position property of spinSettingsModel. By default, the spinner is positioned at the left of the ProgressButton. You can position it at the left, right, top, bottom, or center of the text content.

Change spinner size

Spinner size can be changed by modifying the width property of spinSettingsModel. In this demo, the width is set to 20 to change the spinner size.

Spinner template

You can use custom spinner by specifying the template property of spinSettingsModel with custom styles.

The following sample demonstrates the above functionalities of the spinner.

import { ProgressButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
function App() {
    let spinSettings = { position: 'Right', width: 20, template: '<div class="template"></div>' };
    return (<ProgressButtonComponent content='Submit' spinSettings={spinSettings}/>);
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));
import { ProgressButtonComponent, SpinSettingsModel } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';

function App() {

  let spinSettings : SpinSettingsModel = { position: 'Right', width: 20, template: '<div class="template"></div>' };

  return (
    <ProgressButtonComponent content='Submit' spinSettings={spinSettings}/>
  );
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));

Progress

Content animation

The content of the ProgressButton can be animated during progress using the effect property of animationSettingsModel. You can also set custom duration and timing function using the duration and easing properties. The possible effect values are None, SlideLeft, SlideRight, SlideUp, SlideDown, ZoomIn, and ZoomOut.

import { ProgressButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
function App() {
    let animationSettings = { effect: 'SlideLeft', duration: 500, easing: 'linear' };
    let spinSettings = { position: 'Center' };
    return (<ProgressButtonComponent content='Slide Left' enableProgress={true} animationSettings={animationSettings} spinSettings={spinSettings}/>);
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));
import { AnimationSettingsModel, ProgressButtonComponent, SpinSettingsModel } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';

function App() {

  let animationSettings: AnimationSettingsModel = { effect: 'SlideLeft',  duration: 500, easing: 'linear' };
  let spinSettings : SpinSettingsModel = { position: 'Center' };

  return (
    <ProgressButtonComponent content='Slide Left' enableProgress = {true} animationSettings={animationSettings} spinSettings={spinSettings}/>
  );
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));

Change step of the ProgressButton

The progress can be visualized at the specified interval by changing the step property in the begin event of the ProgressButton. In this demo, the step property is set to 20 to show progress at every 20% increment.

import { ProgressButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
function App() {
    function begin(args) {
        args.step = 20;
    }
    return (<ProgressButtonComponent content='Progress Step' enableProgress={true} begin={begin} cssClass='e-hide-spinner'/>);
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));
import { ProgressButtonComponent, ProgressEventArgs } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';

function App() {

  function begin(args: ProgressEventArgs): void {
      args.step = 20;
  }

  return (
    <ProgressButtonComponent content='Progress Step' enableProgress = {true} begin={begin} cssClass='e-hide-spinner'/>
  );
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));

The class e-hide-spinner hides the spinner in the ProgressButton, For more information, see hide spinner section.

Change progress dynamically

The progress can be changed dynamically by modifying the percent property in the ProgressButton events. In this demo, on 40% completion of progress, the percent property is set to 90 to show dynamic change of the progress.

import { ProgressButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import { useState } from "react";
import * as React from 'react';
import * as ReactDom from 'react-dom';
function App() {
    const [state, setState] = useState({
        content: 'Progress'
    });
    return (<ProgressButtonComponent content={state.content} enableProgress={true} duration={15000} begin={begin} progress={progress} end={end} cssClass='e-hide-spinner'/>);
    function begin(args) {
        setState({ content: 'Progress ' + args.percent + '%' });
    }
    function progress(args) {
        setState({ content: 'Progress ' + args.percent + '%' });
        if (args.percent === 40) {
            args.percent = 90;
        }
    }
    function end(args) {
        setState({ content: 'Progress ' + args.percent + '%' });
    }
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));
import { ProgressButtonComponent, ProgressEventArgs } from '@syncfusion/ej2-react-splitbuttons';
import { useState } from "react";
import * as React from 'react';
import * as ReactDom from 'react-dom';

function App() {
  const [state, setState] = useState({
    content: 'Progress'
  });

    return (
      <ProgressButtonComponent content={state.content} enableProgress = {true} duration={15000} begin={begin} progress={progress} end={end} cssClass='e-hide-spinner'/>
    );

  function begin(args: ProgressEventArgs): void {
    setState({ content: 'Progress ' + args.percent + '%' });
  }

  function progress(args: ProgressEventArgs): void {
    setState({ content: 'Progress ' + args.percent + '%' });
    if (args.percent === 40) {
      args.percent = 90;
    }
  }

  function end(args: ProgressEventArgs): void {
    setState({ content: 'Progress ' + args.percent + '%' });
  }
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));

The method dataBind applies the property changes immediately to the component.

Start and stop methods

You can pause and resume the progress using the stop and start methods, respectively. In this demo, clicking the ProgressButton will pause and resume the progress.

import { ProgressButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { useState } from "react";
function App() {
    let progressBtn;
    const [state, setState] = useState({
        content: 'Download',
        iconCss: 'e-btn-sb-icon e-download'
    });
    return (<ProgressButtonComponent content={state.content} enableProgress={true} duration={4000} iconCss={state.iconCss} end={end} cssClass='e-hide-spinner' onClick={clickHandler} ref={(scope) => { progressBtn = scope; }}/>);
    function end() {
        setState({ content: 'Download', iconCss: 'e-btn-sb-icon e-download' });
    }
    function clickHandler() {
        if (state.content === 'Download') {
            setState({ content: 'Pause', iconCss: 'e-btn-sb-icon e-pause' });
        }
        else if (state.content === 'Pause') {
            setState({ content: 'Resume', iconCss: 'e-btn-sb-icon e-play' });
            progressBtn.stop();
        }
        else if (state.content === 'Resume') {
            setState({ content: 'Pause', iconCss: 'e-btn-sb-icon e-pause' });
            progressBtn.start();
        }
    }
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));
import { ProgressButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { useState } from "react";

function App() {
  let progressBtn: ProgressButtonComponent;
  const [state, setState] = useState({
    content: 'Download',
    iconCss: 'e-btn-sb-icon e-download'
  });

  return (
    <ProgressButtonComponent content={state.content} enableProgress = {true} duration={4000}
    iconCss={state.iconCss} end={end} cssClass='e-hide-spinner' onClick={clickHandler} ref={(scope)=>{progressBtn = scope as ProgressButtonComponent;}}/>
  );

  function end(): void {
    setState({ content: 'Download', iconCss: 'e-btn-sb-icon e-download' });
  }
  
  function clickHandler(): void {
    if (state.content === 'Download') {
      setState({ content: 'Pause', iconCss: 'e-btn-sb-icon e-pause' });
    }
    else if (state.content === 'Pause') {
      setState({ content: 'Resume', iconCss: 'e-btn-sb-icon e-play' });
      progressBtn.stop();
    }
    else if (state.content === 'Resume') {
      setState({ content: 'Pause', iconCss: 'e-btn-sb-icon e-pause' });
      progressBtn.start();
    }
  }
}
export default App;
ReactDom.render(<App />, document.getElementById('progress-button'));

See Also