react-circular-progressbar vs react-progressbar
React Progress Indicators Comparison
1 Year
react-circular-progressbarreact-progressbar
What's React Progress Indicators?

Progress indicators are essential UI components that visually represent the progress of a task or process. They enhance user experience by providing feedback on ongoing operations, such as loading data or completing a task. The two packages, 'react-circular-progressbar' and 'react-progressbar', offer different styles and functionalities for implementing progress indicators in React applications. While both serve the purpose of indicating progress, they differ in design, customization options, and use cases, making it crucial for developers to choose the right one based on their specific needs.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-circular-progressbar298,6491,10869.5 kB423 days agoMIT
react-progressbar4,25688-10-MIT
Feature Comparison: react-circular-progressbar vs react-progressbar

Design and Aesthetics

  • react-circular-progressbar:

    This package provides a circular progress bar that is visually striking and customizable. It allows developers to change the colors, stroke width, and even add text inside the circle, making it suitable for modern applications that require a polished look.

  • react-progressbar:

    This package offers a more traditional linear progress bar. While it is functional and straightforward, it may not provide the same level of visual customization as the circular variant. It is best suited for applications where a simple, no-frills progress indicator is sufficient.

Customization Options

  • react-circular-progressbar:

    Highly customizable, allowing for various styles, including different colors for the progress and background, as well as the ability to display percentage text within the circular bar. This flexibility makes it suitable for diverse branding requirements.

  • react-progressbar:

    Offers basic customization options such as color and height but lacks the extensive styling capabilities of the circular version. It is more limited in terms of visual flair but is easier to implement for straightforward use cases.

Use Cases

  • react-circular-progressbar:

    Best used in scenarios where visual appeal is crucial, such as dashboards, loading screens, or any application that benefits from a modern design. It can effectively convey progress in a more engaging way.

  • react-progressbar:

    Ideal for applications that require a simple and functional progress indicator without the need for elaborate design. It works well in forms, data uploads, or anywhere a linear representation of progress is sufficient.

Performance

  • react-circular-progressbar:

    Generally performs well, but rendering complex customizations may require more resources. It's important to optimize rendering when using it in large applications to maintain performance.

  • react-progressbar:

    Lightweight and performs efficiently, especially in scenarios where minimal visual complexity is needed. It is less resource-intensive compared to the circular variant.

Learning Curve

  • react-circular-progressbar:

    Easy to integrate for developers familiar with React. The API is straightforward, but understanding how to customize it effectively may require some exploration of its props.

  • react-progressbar:

    Also easy to use, with a simpler API that allows for quick implementation without much overhead. Ideal for developers looking for a quick solution without extensive customization.

How to Choose: react-circular-progressbar vs react-progressbar
  • react-circular-progressbar:

    Choose 'react-circular-progressbar' if you need a visually appealing circular progress indicator that can be easily customized with colors, stroke width, and text. It is ideal for applications where a modern and sleek design is a priority, and you want to display progress in a circular format.

README for react-circular-progressbar

React Circular Progressbar

npm version Bundle size

A circular progressbar component, built with SVG and extensively customizable. Try it out on CodeSandbox.

animated progressbar progressbar examples

Version 2.0.0 is out! 👋

New features:

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.

Installation

Install with yarn:

yarn add react-circular-progressbar

or npm:

npm install --save react-circular-progressbar

Usage

Import the component and default styles:

import { CircularProgressbar } from 'react-circular-progressbar';
import '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:

const percentage = 66;

<CircularProgressbar value={percentage} text={`${percentage}%`} />;

If your values are not in percentages, you can adjust minValue and maxValue to select the scale you want:

const value = 0.66;

<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:

<div style={{ width: 200, height: 200 }}>
  <CircularProgressbar value={66} />
</div>

This makes the progressbar work well with responsive designs and grid systems.

Props

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

Theming (customizing styles)

Use CSS or inline styles to customize the styling - the default CSS is a good starting point, but you can override it as needed.

Using the styles prop

You 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:

import { CircularProgressbar, buildStyles } from 'react-circular-progressbar';

const percentage = 66;

<CircularProgressbar
  value={percentage}
  text={`${percentage}%`}
  styles={buildStyles({
    // Rotation of path and trail, in number of turns (0-1)
    rotation: 0.25,

    // Whether to use rounded or flat corners on the ends - can use 'butt' or 'round'
    strokeLinecap: 'butt',

    // Text size
    textSize: '16px',

    // How long animation takes to go from one percentage to another, in seconds
    pathTransitionDuration: 0.5,

    // Can specify path transition in more detail, or remove it entirely
    // pathTransition: 'none',

    // Colors
    pathColor: `rgba(62, 152, 199, ${percentage / 100})`,
    textColor: '#f88',
    trailColor: '#d6d6d6',
    backgroundColor: '#3e98c7',
  })}
/>;

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:

<CircularProgressbar
  value={percentage}
  text={`${percentage}%`}
  styles={{
    // Customize the root svg element
    root: {},
    // Customize the path, i.e. the "completed progress"
    path: {
      // Path color
      stroke: `rgba(62, 152, 199, ${percentage / 100})`,
      // Whether to use rounded or flat corners on the ends - can use 'butt' or 'round'
      strokeLinecap: 'butt',
      // Customize transition animation
      transition: 'stroke-dashoffset 0.5s ease 0s',
      // Rotate the path
      transform: 'rotate(0.25turn)',
      transformOrigin: 'center center',
    },
    // Customize the circle behind the path, i.e. the "total progress"
    trail: {
      // Trail color
      stroke: '#d6d6d6',
      // Whether to use rounded or flat corners on the ends - can use 'butt' or 'round'
      strokeLinecap: 'butt',
      // Rotate the trail
      transform: 'rotate(0.25turn)',
      transformOrigin: 'center center',
    },
    // Customize the text
    text: {
      // Text color
      fill: '#f88',
      // Text size
      fontSize: '16px',
    },
    // Customize background - only used when the `background` prop is true
    background: {
      fill: '#3e98c7',
    },
  }}
/>

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.

Using CSS

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:

import 'react-circular-progressbar/dist/styles.css';
import './custom.css';
// custom.css
.CircularProgressbar-path {
  stroke: red;
}
.CircularProgressbar-trail {
  stroke: gray;
}
.CircularProgressbar-text {
  fill: yellow;
}
.CircularProgressbar-background {
  fill: green;
}

Adding arbitrary text or content inside the progressbar

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:

import { CircularProgressbarWithChildren } from 'react-circular-progressbar';

<CircularProgressbarWithChildren value={66}>
  {/* Put any JSX content in here that you'd like. It'll be vertically and horizonally centered. */}
  <img style={{ width: 40, marginTop: -5 }} src="https://i.imgur.com/b9NyUGm.png" alt="doge" />
  <div style={{ fontSize: 12, marginTop: -5 }}>
    <strong>66%</strong> mate
  </div>
</CircularProgressbarWithChildren>;
CircularProgressbarWithChildren example

CircularProgressbarWithChildren has all the same props as CircularProgressbar - you can use it the exact same way otherwise.

Animating text

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:

import { easeQuadInOut } from 'd3-ease';

<AnimatedProgressProvider
  valueStart={0}
  valueEnd={66}
  duration={1.4}
  easingFunction={easeQuadInOut}
>
  {(value) => {
    const roundedValue = Math.round(value);
    return (
      <CircularProgressbar
        value={value}
        text={`${roundedValue}%`}
        /* This is important to include, because if you're fully managing the
        animation yourself, you'll want to disable the CSS animation. */
        styles={buildStyles({ pathTransition: 'none' })}
      />
    );
  }}
</AnimatedProgressProvider>;

Animating progressbar upon component mount or upon visible

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:

<ProgressProvider valueStart={0} valueEnd={66}>
  {(value) => <CircularProgressbar value={value} />}
</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.

Fixing text centering in Internet Explorer (IE)

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:

// Use feature or browser detection to determine if IE
const needDominantBaselineFix = ...

<CircularProgressbar
  value={percentage}
  text={<tspan dy={needDominantBaselineFix ? -10 : 0}>{percentage}</tspan>}
/>

See this Codesandbox example to see this in action.

Advanced usage

Supported platforms

react-circular-progressbar does not work with React Native, because React Native does not support <svg> out of the box.

Contributing

Take a look at CONTRIBUTING.md to see how to help contribute to react-circular-progressbar.

License

MIT