Gathering detailed insights and metrics for react-circular-progressbar
Gathering detailed insights and metrics for react-circular-progressbar
Gathering detailed insights and metrics for react-circular-progressbar
Gathering detailed insights and metrics for react-circular-progressbar
A circular progressbar component, built with SVG and extensively customizable
npm install react-circular-progressbar
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,094 Stars
343 Commits
133 Forks
9 Watching
5 Branches
10 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
TypeScript (91.59%)
CSS (6.27%)
JavaScript (2.14%)
Cumulative downloads
Total Downloads
Last day
-4.1%
54,733
Compared to previous day
Last week
4%
305,184
Compared to previous week
Last month
2.3%
1,285,322
Compared to previous month
Last year
9%
14,048,948
Compared to previous year
A circular progressbar component, built with SVG and extensively customizable. Try it out on CodeSandbox.
New features:
import { CircularProgressbarWithChildren }
in order to put arbitrary JSX inside the component.import { buildStyles }
to make it easier to customize styles.props.minValue
and props.maxValue
to specify a range other than 0-100.Breaking changes: if you're upgrading from an older version, take a look at UPGRADING.md for instructions on how to migrate.
Documentation for v1.x.x will still be available at README_v1.md.
Install with yarn:
1yarn add react-circular-progressbar
or npm:
1npm install --save react-circular-progressbar
Import the component and default styles:
1import { CircularProgressbar } from 'react-circular-progressbar'; 2import 'react-circular-progressbar/dist/styles.css';
Note: Importing CSS requires a CSS loader (if you're using create-react-app, this is already set up for you). If you don't have a CSS loader, you can copy styles.css into your project instead.
Now you can use the component:
1const percentage = 66; 2 3<CircularProgressbar value={percentage} text={`${percentage}%`} />;
If your values are not in percentages, you can adjust minValue
and maxValue
to select the scale you want:
1const value = 0.66; 2 3<CircularProgressbar value={value} maxValue={1} text={`${value * 100}%`} />;
The progressbar is designed to fill the width of its container. You can size the progressbar by sizing its container:
1<div style={{ width: 200, height: 200 }}> 2 <CircularProgressbar value={66} /> 3</div>
This makes the progressbar work well with responsive designs and grid systems.
Take a look at the CodeSandbox for interactive examples on how to use these props.
ℹ️ Version 1.0.0 removed the classForPercentage
and textForPercentage
props in favor of className
and text
props. Version 2.0.0 replaces percentage
with value
and removes the initialAnimation
prop. Take a look at UPGRADING.md for instructions on how to migrate.
Name | Description |
---|---|
value | Completion value of the progressbar, from minValue to maxValue . Required. |
minValue | Minimum value of the progressbar. Default: 0 . |
maxValue | Maximum value of the progressbar. Default: 100 . |
className | Classes to apply to the svg element. Default: '' . |
text | Text to display inside progressbar. Default: '' . |
strokeWidth | Width of circular line relative to total width of component, a value from 0-100. Default: 8 . |
background | Whether to display background color. Default: false . |
backgroundPadding | Padding between background circle and path/trail relative to total width of component. Only used if background is true . Default: 0 . |
counterClockwise | Whether to rotate progressbar in counterclockwise direction. Default: false . |
circleRatio | Number from 0-1 representing ratio of the full circle diameter the progressbar should use. Default: 1 . |
classes | Object allowing overrides of classNames of each svg subcomponent (root, trail, path, text, background). Enables styling with react-jss. See this PR for more detail. |
styles | Object allowing customization of styles of each svg subcomponent (root, trail, path, text, background). |
Use CSS or inline styles to customize the styling - the default CSS is a good starting point, but you can override it as needed.
styles
propYou can use the styles
prop to customize each part of the progressbar (the root svg, path, trail, text, and background). This uses the native style
prop for each subcomponent, so you can use any CSS properties here, not just the ones mentioned below.
As a convenience, you can use buildStyles
to configure the most common style changes:
1import { CircularProgressbar, buildStyles } from 'react-circular-progressbar'; 2 3const percentage = 66; 4 5<CircularProgressbar 6 value={percentage} 7 text={`${percentage}%`} 8 styles={buildStyles({ 9 // Rotation of path and trail, in number of turns (0-1) 10 rotation: 0.25, 11 12 // Whether to use rounded or flat corners on the ends - can use 'butt' or 'round' 13 strokeLinecap: 'butt', 14 15 // Text size 16 textSize: '16px', 17 18 // How long animation takes to go from one percentage to another, in seconds 19 pathTransitionDuration: 0.5, 20 21 // Can specify path transition in more detail, or remove it entirely 22 // pathTransition: 'none', 23 24 // Colors 25 pathColor: `rgba(62, 152, 199, ${percentage / 100})`, 26 textColor: '#f88', 27 trailColor: '#d6d6d6', 28 backgroundColor: '#3e98c7', 29 })} 30/>;
buildStyles
is a shorthand, but you can also build the styles
object yourself. It's an object with root
, path
, trail
, text
, and background
properties, which are each a set of inline styles to apply to the relevant SVG subcomponent. Here's the equivalent set of styles as above, without using buildStyles
:
1<CircularProgressbar 2 value={percentage} 3 text={`${percentage}%`} 4 styles={{ 5 // Customize the root svg element 6 root: {}, 7 // Customize the path, i.e. the "completed progress" 8 path: { 9 // Path color 10 stroke: `rgba(62, 152, 199, ${percentage / 100})`, 11 // Whether to use rounded or flat corners on the ends - can use 'butt' or 'round' 12 strokeLinecap: 'butt', 13 // Customize transition animation 14 transition: 'stroke-dashoffset 0.5s ease 0s', 15 // Rotate the path 16 transform: 'rotate(0.25turn)', 17 transformOrigin: 'center center', 18 }, 19 // Customize the circle behind the path, i.e. the "total progress" 20 trail: { 21 // Trail color 22 stroke: '#d6d6d6', 23 // Whether to use rounded or flat corners on the ends - can use 'butt' or 'round' 24 strokeLinecap: 'butt', 25 // Rotate the trail 26 transform: 'rotate(0.25turn)', 27 transformOrigin: 'center center', 28 }, 29 // Customize the text 30 text: { 31 // Text color 32 fill: '#f88', 33 // Text size 34 fontSize: '16px', 35 }, 36 // Customize background - only used when the `background` prop is true 37 background: { 38 fill: '#3e98c7', 39 }, 40 }} 41/>
However, you're not limited to the CSS properties shown above—you have the full set of SVG CSS properties available to you when you use prop.styles
.
See the CodeSandbox examples for a live example on how to customize styles.
You can also customize styles with CSS. There are equivalent CSS hooks for the root, path, trail, text, and background of the progressbar.
If you're importing the default styles, you can override the defaults like this:
1import 'react-circular-progressbar/dist/styles.css'; 2import './custom.css';
1// custom.css 2.CircularProgressbar-path { 3 stroke: red; 4} 5.CircularProgressbar-trail { 6 stroke: gray; 7} 8.CircularProgressbar-text { 9 fill: yellow; 10} 11.CircularProgressbar-background { 12 fill: green; 13}
If you want to add multiple lines of text or images within the progressbar, you can overlay it on top of a regular <CircularProgressbar />
using absolute positioning. react-circular-progressbar
ships with a CircularProgressbarWithChildren
component which makes it easy to do that by using JSX children:
1import { CircularProgressbarWithChildren } from 'react-circular-progressbar'; 2 3<CircularProgressbarWithChildren value={66}> 4 {/* Put any JSX content in here that you'd like. It'll be vertically and horizonally centered. */} 5 <img style={{ width: 40, marginTop: -5 }} src="https://i.imgur.com/b9NyUGm.png" alt="doge" /> 6 <div style={{ fontSize: 12, marginTop: -5 }}> 7 <strong>66%</strong> mate 8 </div> 9</CircularProgressbarWithChildren>;
CircularProgressbarWithChildren
has all the same props as CircularProgressbar
- you can use it the exact same way otherwise.
If you want to animate the text as well as the path, you'll need to transition the value
prop from one value to another using a third-party animation library like react-move
and an easing library like d3-ease
.
You can use a render prop wrapper like AnimatedProgressProvider.js inside this Codesandbox to help manage the transitioning value, and use it like this:
1import { easeQuadInOut } from 'd3-ease'; 2 3<AnimatedProgressProvider 4 valueStart={0} 5 valueEnd={66} 6 duration={1.4} 7 easingFunction={easeQuadInOut} 8> 9 {(value) => { 10 const roundedValue = Math.round(value); 11 return ( 12 <CircularProgressbar 13 value={value} 14 text={`${roundedValue}%`} 15 /* This is important to include, because if you're fully managing the 16 animation yourself, you'll want to disable the CSS animation. */ 17 styles={buildStyles({ pathTransition: 'none' })} 18 /> 19 ); 20 }} 21</AnimatedProgressProvider>;
Upon component mount
In order to trigger the default CSS animation on mount, you'll need to change props.value
from 0 to your desired value with a setTimeout
in componentDidMount
. You can use a wrapper component to help manage this like ProgressProvider.js in this Codesandbox. Then you can do:
1<ProgressProvider valueStart={0} valueEnd={66}> 2 {(value) => <CircularProgressbar value={value} />} 3</ProgressProvider>
Upon visible
To animate the progressbar only when it becomes visible (e.g. if it's below the fold), you can use something like react-visibility-sensor
which detects whether the component is visible or not. Here's a Codesandbox example.
Because the dominant-baseline
CSS property does not work in IE, the text may not be centered in IE.
The recommended way to fix this is to instead of using props.text
, use CircularProgressbarWithChildren
and put your text in props.children
, as described here.
However, you can also work around this by setting the text
prop to be a <tspan>
element and then adjusting the dy
vertical offset, like so:
1// Use feature or browser detection to determine if IE 2const needDominantBaselineFix = ... 3 4<CircularProgressbar 5 value={percentage} 6 text={<tspan dy={needDominantBaselineFix ? -10 : 0}>{percentage}</tspan>} 7/>
See this Codesandbox example to see this in action.
react-circular-progressbar does not work with React Native, because React Native does not support <svg>
out of the box.
Take a look at CONTRIBUTING.md to see how to help contribute to react-circular-progressbar.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
65 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More