1.0.34 • Published 2 years ago

progress-ring-component-react v1.0.34

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

progress-ring-component-react

npm version Built With Stencil

This is a React version of progress-ring-component, 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 and its React wrapper library.

Demo 1

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

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.

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%)).

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
colorsMap[[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.

Demo 3

Event NamePayloadDescription
prcProgress{ id: string, progress: number, percentage: number }Event to be emitted on every progress change (from 0 to 1)
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