1.0.34 • Published 2 years ago

progress-ring-component v1.0.34

Weekly downloads
35
License
MIT
Repository
github
Last release
2 years ago

Progress Ring Component

test npm version Published on webcomponents.org Built With Stencil

This is an animated web component showing progress in percentage. It internally uses easing-animation-frames library to create CPU-friendly easing animations and compiled with Stencil.

  1. Demo 1
  2. Demo 2
  3. Demo 3

For React projects, please use progress-ring-component-react, which is a React version of the component, built with Stencil's React wrapper.

How to use

Demo 1

<progress-ring percentage="30"></progress-ring>
<progress-ring percentage="60" round-linecap="true"></progress-ring>
<progress-ring percentage="90" disable-digits="true">
  <p class="completed-count">9/10<br />Complete</p>
</progress-ring>

There is only one mandatory property, percentage, which declares the ending percentage in animation. You can also use radius prop to change the size of the ring, and storkeWidth to change the thickness of the ring. The full list of properties can be found below.

You can also place custom HTML elements within the component's <progress-ring></<progress-ring> tag as HTMLSlotElement, which you have full control on for styling.

This component works reactively in a unidirectional fashion. When the percentage changes, it stops the current animation and resumes it with new percentage. There is pre-defined color scheme (red (< 25%) -> yellow (< 50%) -> blue (< 75%) -> green (>= 75%)).

Demo 2

<progress-ring percentage="10"></progress-ring>

<div class="buttons">
  <button id="buttonOne">30%</button>
  <button id="buttonTwo">60%</button>
  <button id="buttonThree">90%</button>
</div>

<script>
  const ring = document.querySelector("progress-ring");
  const buttonOne = document.querySelector("#buttonOne");
  const buttonTwo = document.querySelector("#buttonTwo");
  const buttonThree = document.querySelector("#buttonThree");

  buttonOne.addEventListener("click", () => {
    ring.setAttribute("percentage", 30);
  });
  buttonTwo.addEventListener("click", () => {
    ring.setAttribute("percentage", 60);
  });
  buttonThree.addEventListener("click", () => {
    ring.setAttribute("percentage", 90);
  });
</script>

Properties

PropertyTypeDefaultDescription
percentagenumber0Percentage value (mandatory)
radiusnumber80Radius of the ring
stroke-widthnumber10Thickness of the ring
round-linecapbooleanfalseAddes rounded linecap to the ring
durationnumber4000Animation duration in miliseconds
easing-typestring"quartInOut"Easing animation function name
int-sizenumber30Font size of integer
decimal-sizenumberintSize * 0.7Font size of decimals
disable-digitsbooleanfalseHides digits
disable-decimalsbooleanfalseHides decimal places
colorsstring'[[0,"#ff4f40"],[25, "#ffcd40"],[50, "#66a0ff"],[75, "#30bf7a"]]'Color steps with percentage and color code
invert-colorsbooleanfalseInverts the color scheme
event-idstringundefinedEvent Id to be used for animation callbacks

Easing Types

backInOut, backIn, backOut, bounceInOut, bounceIn, bounceOut, circInOut, circIn, circOut, cubicInOut, cubicIn, cubicOut, elasticInOut, elasticIn, elasticOut, expoInOut, expoIn, expoOut, linear, quadInOut, quadIn, quadOut, quartInOut, quartIn, quartOut, quintInOut, quintIn, quintOut, sineInOut, sineIn, sineOut

Advanced usage with animation events

By passing even-id as a prop, you can listen to events emitted by with the animation, and register callback functions for them. Please see Demo 3.

Demo 3

Event NamePayloadDescription
prcProgress{ id: string, progress: number, percentage: number }Event to be emitted on every progress change (from 0 to 1)
prcColor{ id: string, color: string }Event to be emitted for the color value
prcStart{ id: string }Event to be emitted when the animation starts
prcComplete{ id: string }Event to be emitted when the animation is completed
prcStop{ id: string }Event to be emitted when the animation is stopped
prcResume{ id: string }Event to be emitted when the animation is resumed
prcRestart{ id: string }Event to be emitted when the animation is restarted

You can either directly import the component in script tag or integrate it into the framework you're using for the project.

How to use in your project

Place a script tag <script type="module" src="https://unpkg.com/progress-ring-component/dist/progressring/progressring.esm.js"></script> in the head of your index.html.

<!DOCTYPE html>
<html>
  <head>
    <script
      type="module"
      src="https://unpkg.com/progress-ring-component@1.0.34/dist/progressring/progressring.esm.js"
    ></script>
  </head>
  <body>
    <progress-ring percentage="50"></progress-ring>
  </body>
</html>
1.0.25

2 years ago

1.0.24

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.34

2 years ago

1.0.22

2 years ago

1.0.23

2 years ago

1.0.19

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago