Spinner and progress in Vue Progress button component

16 Feb 202412 minutes to read

Change spinner position

Spinner position can be changed by modifying the position property ofspinSettingsModel. 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.

<template>
 <ejs-progressbutton content="Submit"  :spinSettings="spinSettings" ></ejs-progressbutton>
</template>

<script>
import Vue from 'vue';
import { ProgressButtonPlugin } from "@syncfusion/ej2-vue-splitbuttons";
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ProgressButtonPlugin);

export default {
    data () {
        return {
            spinSettings: { position: 'Right', width: 20, template: '<div class="template"></div>' }
        };
    }
}
</script>

<style>
  @import '../node_modules/@syncfusion/ej2-base/styles/material.css';
  @import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
  @import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
  @import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
  @keyframes custom-rolling {
    0% {
      -webkit-transform: rotate(0deg);
      transform: rotate(0deg);
    }
    100% {
      -webkit-transform: rotate(360deg);
      transform: rotate(360deg);
    }
  }
  .template {
    border: 2px solid green;
    border-style: dotted;
    border-radius: 50%;
    border-top-color: transparent;
    border-bottom-color: transparent;
    height: 16px;
    width: 16px;
  }
  .template {
    -webkit-animation: custom-rolling 1.3s linear infinite;
    animation: custom-rolling 1.3s linear infinite;
  }
</style>

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.

<template>
 <ejs-progressbutton content="Slide Left" :enableProgress="true"  :animationSettings="animationSettings" :spinSettings="spinSettings"></ejs-progressbutton>
</template>

<script>
import Vue from 'vue';
import { ProgressButtonPlugin } from "@syncfusion/ej2-vue-splitbuttons";
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ProgressButtonPlugin);

export default {
    data () {
        return {
            animationSettings: { effect:'SlideLeft', duration: 500, easing: 'linear' },
            spinSettings: { position: 'Center' }
        };
    }
}
</script>

<style>
  @import '../node_modules/@syncfusion/ej2-base/styles/material.css';
  @import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
  @import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
  @import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
</style>

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.

<template>
 <ejs-progressbutton content='Progress Step' :enableProgress="true" cssClass="e-hide-spinner" :begin="begin"></ejs-progressbutton>
</template>

<script>
import Vue from 'vue';
import { ProgressButtonPlugin} from "@syncfusion/ej2-vue-splitbuttons";
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ProgressButtonPlugin);

export default {
    methods: {
    begin: function(args) {
        args.step = 20;
    }
  }
}
</script>

<style>
  @import '../node_modules/@syncfusion/ej2-base/styles/material.css';
  @import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
  @import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
  @import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
</style>

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.

<template>
<ejs-progressbutton :content="content" ref="progressbutton" :enableProgress="true" duration=15000 :begin="begin" :end="end" :progress="progress" cssClass="cssClass"></ejs-progressbutton>
</template>

<script>
import Vue from 'vue';
import { ProgressButtonPlugin } from "@syncfusion/ej2-vue-splitbuttons";
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ProgressButtonPlugin);

 export default {
    methods: {
    begin: function(args) {
        this.$refs.progressbutton.content = 'Progress ' + args.percent + '%';
    },
    progress: function(args) {
       this.$refs.progressbutton.content = 'Progress ' + args.percent + '%';
       if(args.percent === 40) {
            args.percent = 90
        }
    },
    end: function(args) {
        this.$refs.progressbutton.content = 'Progress ' + args.percent + '%';
    }
  },
  data () {
        return {
           content: "Progress Step",
           cssClass:   "e-hide-spinner"
    };
  }
}
</script>

<style>
  @import '../node_modules/@syncfusion/ej2-base/styles/material.css';
  @import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
  @import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
  @import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
</style>

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.

<template>
<ejs-progressbutton  ref="progressBtn" :content="content" :iconCss="iconCss" :enableProgress="true" :cssClass="cssClass" v-on:click.native="clickHanlder" :end="end"></ejs-progressbutton>
</template>

<script>
import Vue from 'vue';
import { ProgressButtonPlugin } from "@syncfusion/ej2-vue-splitbuttons";
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);
Vue.use(ProgressButtonPlugin);

var vue = export default {
 methods: {
    clickHanlder: function(event) {
        if(vue.content === 'Download') {
            vue.content = 'Pause';
            vue.iconCss = 'e-btn-sb-icon e-pause';
        }
        // clicking on ProgressButton will stop the progress when the text content is 'Pause'
        else if(vue.content === 'Pause') {
            vue.content = 'Resume';
            vue.iconCss = 'e-btn-sb-icon e-play';
            this.$refs.progressBtn.stop();
        }
        // clicking on ProgressButton will start the progress when the text content is 'Resume'
        else if(vue.content === 'Resume') {
            vue.content = 'Pause';
            vue.iconCss = 'e-btn-sb-icon e-pause';
            this.$refs.progressBtn.start();
        }
    },
    end: function(args) {
      vue.content = 'Download';
      vue.iconCss = 'e-btn-sb-icon e-download';
    }
  },
   data () {
        return {
           content: "Download",
           cssClass: "e-hide-spinner",
           iconCss: "e-btn-sb-icon e-download"
    };
  }
}
</script>

<style>
  @import '../node_modules/@syncfusion/ej2-base/styles/material.css';
  @import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
  @import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
  @import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
  @font-face {
    font-family: 'btn-icon';
    src:
    url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj1tSfgAAAEoAAAAVmNtYXDnH+dzAAABoAAAAEJnbHlm1v48pAAAAfgAAAQYaGVhZBOPfZcAAADQAAAANmhoZWEIUQQJAAAArAAAACRobXR4IAAAAAAAAYAAAAAgbG9jYQN6ApQAAAHkAAAAEm1heHABFQCqAAABCAAAACBuYW1l07lFxAAABhAAAAIxcG9zdK9uovoAAAhEAAAAgAABAAAEAAAAAFwEAAAAAAAD9AABAAAAAAAAAAAAAAAAAAAACAABAAAAAQAAJ1LUzF8PPPUACwQAAAAAANg+nFMAAAAA2D6cUwAAAAAD9AP0AAAACAACAAAAAAAAAAEAAAAIAJ4AAwAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQQAAZAABQAAAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wDnBgQAAAAAXAQAAAAAAAABAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAAAAACAAAAAwAAABQAAwABAAAAFAAEAC4AAAAEAAQAAQAA5wb//wAA5wD//wAAAAEABAAAAAEAAgADAAQABQAGAAcAAAAAAAAADgAkADIAhAEuAewCDAAAAAEAAAAAA2ED9AACAAA3CQGeAsT9PAwB9AH0AAACAAAAAAPHA/QAAwAHAAAlIREhASERIQJpAV7+ov3QAV7+ogwD6PwYA+gAAAEAAAAAA4sD9AACAAATARF0AxgCAP4MA+gAAAABAAAAAAP0A/QAQwAAExEfDyE/Dx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AA) format('truetype');
    font-weight: normal;
    font-style: normal;
  }

  .e-btn-sb-icon {
    font-family: 'btn-icon' !important;
    speak: none;
    font-size: 55px;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

.e-download::before {
  content: '\e706';
}

.e-play::before {
  content: '\e700';
}

.e-pause::before {
  content: '\e701';
}
</style>

See Also