• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

https://wangdahoo.github.io/vue-progress

vue-progress

Progressbar.js as a Vue Component

How to use

install

npm i vue-progress -S

import as a vue plugin

import VueProgress from 'vue-progress'
Vue.use(VueProgress)

hello <progress-bar>

<template>
  <progress-bar type="line" ref="line" :options="options"></progress-bar>

  <!-- or -->
  <!-- <progress-bar type="line" ref="line" color="#007AFF" strokeWidth="0.5"></progress-bar> -->
</template>

<script>
  export default {
    data: {
      options: {
        color: '#007AFF',
        strokeWidth: 0.5
      }
    },
    mounted: function () {
      this.$refs.line.animate(1.0)
    }
  }
</script>

<style>
  html, body {
    margin: 0;
    padding: 0;
  }
</style>

ProgressBar component attributes

type: type of path line, circle, custom

options: Options for path drawing.

{
  // Stroke color.
  // Default: '#555'
  color: '#3a3a3a',

  // Width of the stroke.
  // Unit is percentage of SVG canvas' size.
  // Default: 1.0
  // NOTE: In Line shape, you should control
  // the stroke width by setting container's height.
  // WARNING: IE doesn't support values over 6, see this bug:
  //          https://github.com/kimmobrunfeldt/progressbar.js/issues/79
  strokeWidth: 2.1,

  // If trail options are not defined, trail won't be drawn

  // Color for lighter trail stroke
  // underneath the actual progress path.
  // Default: '#eee'
  trailColor: '#f4f4f4',

  // Width of the trail stroke. Trail is always centered relative to
  // actual progress path.
  // Default: same as strokeWidth
  trailWidth: 0.8,

  // Inline CSS styles for the created SVG element
  // Set null to disable all default styles.
  // You can disable individual defaults by setting them to `null`
  // If you specify anything in this object, none of the default styles
  // apply
  svgStyle: {
    display: 'block',

    // Important: make sure that your container has same
    // aspect ratio as the SVG canvas. See SVG canvas sizes above.
    width: '100%'
  },

  // Text options. Text element is a <p> element appended to container
  // You can add CSS rules for the text element with the className
  // NOTE: When text is set, 'position: relative' will be set to the
  // container for centering. You can also prevent all default inline
  // styles with 'text.style: null'
  // Default: null
  text: {
    // Initial value for text.
    // Default: null
    value: 'Text',

    // Class name for text element.
    // Default: 'progressbar-text'
    className: 'progressbar__label',

    // Inline CSS styles for the text element.
    // If you want to modify all CSS your self, set null to disable
    // all default styles.
    // If the style option contains values, container is automatically
    // set to position: relative. You can disable behavior this with
    // autoStyleContainer: false
    // If you specify anything in this object, none of the default styles
    // apply
    // Default: object speficied below
    style: {
      // Text color.
      // Default: same as stroke color (options.color)
      color: '#f00',
      position: 'absolute',
      left: '50%',
      top: '50%',
      padding: 0,
      margin: 0,
      // You can specify styles which will be browser prefixed
      transform: {
          prefix: true,
          value: 'translate(-50%, -50%)'
      }
    },

    // Only effective if the text.style is not null
    // By default position: relative is applied to container if text
    // is set. Setting this to false disables that feature.
    autoStyleContainer: true,

    // Only effective if the shape is SemiCircle.
    // If true, baseline for text is aligned with bottom of
    // the SVG canvas. If false, bottom line of SVG canvas
    // is in the center of text.
    // Default: true
    alignToBottom: true
  },

  // Fill color for the shape. If null, no fill.
  // Default: null
  fill: 'rgba(0, 0, 0, 0.5)',

  // Duration for animation in milliseconds
  // Default: 800
  duration: 1200,

  // Easing for animation. See #easing section.
  // Default: 'linear'
  easing: 'easeOut',

  // See #custom-animations section
  // Built-in shape passes reference to itself and a custom attachment
  // object to step function
  from: { color: '#eee' },
  to: { color: '#000' },
  step: function(state, circle, attachment) {
    circle.path.setAttribute('stroke', state.color);
  },

  // If true, some useful console.warn calls will be done if it seems
  // that progressbar is used incorrectly
  // Default: false
  warnings: false
}

ProgressBar vm methods

svg()

Reference to SVG element where progress bar is drawn.

path()

Reference to SVG path which presents the actual progress bar.

trail()

Reference to SVG path which presents the trail of the progress bar. Returns null if trail is not defined.

text()

Reference to p element which presents the text label for progress bar. Returns null if text is not defined.

animate(progress, [options], [cb])

Animates drawing of a shape.

  • progress: progress from 0 to 1.
  • options: Animation options. These options override the defaults given in initialization.
{
  // Duration for animation in milliseconds
  // Default: 800
  duration: 1200,

  // Easing for animation. See #easing section.
  // Default: 'linear'
  easing: 'easeInOut',

  // See #custom-animations section
  // Built-in shape passes reference to itself and a custom attachment
  // object to step function
  from: { color: '#eee' },
  to: { color: '#000' },
  step: function(state, circle, attachment) {
      circle.path.setAttribute('stroke', state.color);
  }
}
  • cb: Callback function which is called after animation ends.

set(progress)

Sets progress instantly without animation. Clears all animations for path.

stop()

Stops animation to its current position.

value()

Returns current shown progress from 0 to 1. This value changes when animation is running.

setText(text)

Sets text to given a string. If you need to dynamically modify the text element, see .text attribute.

More Repositories

1

vonic

Mobile UI Components, based on Vue.js and ionic CSS. https://wangdahoo.github.io/vonic-documents
Vue
3,397
star
2

vue-scroller

Scroller Component for Vue.js
JavaScript
1,789
star
3

vue-animate-number

animate-number as a vue component.
HTML
107
star
4

vswipe

A Vue Swipe Component.
JavaScript
93
star
5

vonic-webpack-starter

A vonic starter with webpack template by vue-cli.
JavaScript
64
star
6

flask-element-starter

A python project starter equipped with flask and element-ui.
Vue
40
star
7

vue-scroller-demo

Vue
25
star
8

vonic-documents

vonic 2.0 documents site https://wangdahoo.github.io/vonic-documents
CSS
24
star
9

vonic-template

Webpack Template for Vonic.
JavaScript
13
star
10

simple-react-starter

CSS
11
star
11

JSBridge

Android WebView JavaScript Bridge. Inspired by marcuswestin's WebViewJavascriptBridge https://github.com/marcuswestin/WebViewJavascriptBridge
Java
11
star
12

virtual-dom

yet anthor virtual-dom.
JavaScript
5
star
13

map-state-vmodel

mapState for v-model
JavaScript
4
star
14

koa-rest-boilerplate

Koa restful boilerplate in typescript
TypeScript
4
star
15

list-diff

TypeScript
3
star
16

ionic-css

Ionic css components standalone.
CSS
3
star
17

redis-sharding

redis sharding via HashRing
JavaScript
3
star
18

gowork

Setup vscode golang development envionment quickly.
JavaScript
2
star
19

AbsoluteAdmin

HTML
2
star
20

vonic-webpack-code-splitting

vonic webpack code-splitting example
JavaScript
2
star
21

deque

double-ended queue.
JavaScript
1
star
22

wangdahoo.keys

1
star
23

von-app

Vue
1
star
24

script-error

JavaScript
1
star
25

create-element-app

1
star
26

vonic-doc

Deprecated. Please refer to https://github.com/wangdahoo/vonic-documents.
JavaScript
1
star
27

ngScroll

Scroller Component for Angular.js 1.x https://wangdahoo.github.io/ngScroll
JavaScript
1
star
28

ionic-sass

CSS
1
star
29

serve-https

JavaScript
1
star
30

swiper

JavaScript
1
star
31

zui

ZUI Framework
JavaScript
1
star
32

create-my-app

A simple project generator cli.
JavaScript
1
star
33

weui-less

CSS
1
star