A customizable and reusable circular progress tracker component for React.JS.
You can install the package via npm:
npm install react-circular-tracker
Or via yarn:
yarn add react-circular-tracker
Here's a basic example of how to use the CircularTracker
component in your React application:
import React from 'react';
import { CircularTracker } from 'react-circular-tracker';
const App = () => (
<div>
<CircularTracker progress={50} />
</div>
);
export default App;
The CircularTracker
component accepts the following props:
Prop | Type | Default | Description |
---|---|---|---|
progress |
number | null |
null |
The current progress value. Can be null to represent unknown progress. |
total |
number |
100 |
The total value for the progress (used in "X de Y" mode). |
isPercentage |
boolean |
true |
Whether to display progress as a percentage or in "X de Y" mode. |
strokeWidth |
number |
4 |
The width of the progress arc stroke. |
ballStrokeWidth |
number |
12 |
The width of the ball stroke at the end of the progress arc. |
transitionDuration |
number |
0.5 |
The duration of the transition animation in seconds. |
transitionTimingFunction |
string |
ease |
The timing function for the transition animation. |
hideValue |
boolean |
false |
Whether to hide the progress value text. |
gradient |
Array<{ stop: number; color: string }> |
[{ stop: 0, color: '#309E3A' }, { stop: 1, color: '#309E3A' }] |
The gradient colors for the progress arc. |
subtitle |
string |
undefined |
The subtitle text to display below the progress value. |
style |
React.CSSProperties |
{} |
Custom styles to apply to the component. |
className |
string |
undefined |
Custom class name to apply to the component. |
suffix |
string |
% |
The suffix to display after the progress value (e.g., % ). |
centerBackground |
string |
transparent |
The background color of the center circle. |
fontWeight |
string |
bold |
The font weight of the progress value text. |
fontSize |
string |
24px |
The font size of the progress value text. |
background |
string |
#eef2f5 |
The background color of the progress arc. |
hideBall |
boolean |
false |
Whether to hide the ball at the end of the progress arc. |
inverted |
boolean |
false |
Whether to invert the progress direction (anti-clockwise). |
textColor |
string |
#309E3A |
The color of the progress value text. |
Here's a more detailed example demonstrating various props:
<CircularTracker
progress={93}
isPercentage={true}
ballStrokeWidth={14}
fontSize="36"
fontWeight={"bold"}
className="default-tracker"
gradient={[
{ stop: 0, color: "#059669" }, // Emerald-600
{ stop: 1, color: "#047857" }, // Emerald-700
]}
centerBackground="rgba(16, 185, 129, 0.1)"
textColor="#059669"
/>
<CircularTracker
progress={-60}
total={100}
isPercentage={true}
strokeWidth={4}
ballStrokeWidth={12}
transitionDuration={0.5}
transitionTimingFunction="ease"
background="rgba(255, 87, 51, 0.2)"
hideBall={false}
hideValue={false}
gradient={[
{ stop: 0, color: "#E11D48" }, // Rose-600
{ stop: 1, color: "#BE123C" }, // Rose-700
]}
subtitle=""
className="inverted-tracker"
suffix="pts"
centerBackground="transparent"
fontWeight="bold"
fontSize="24px"
inverted={true}
textColor="#FF5733"
/>
<CircularTracker
progress={60}
total={100}
isPercentage={true}
strokeWidth={4}
ballStrokeWidth={12}
transitionDuration={0.5}
transitionTimingFunction="ease"
background="#eef2f5"
hideBall={false}
hideValue={false}
gradient={[
{ stop: 0, color: "#FBBF24" }, // Amber-400
{ stop: 1, color: "#F59E0B" }, // Amber-500
]}
subtitle="Loading..."
className="loading-tracker"
suffix="%"
centerBackground="transparent"
fontWeight="bold"
fontSize="24px"
textColor="#FFC300"
/>
<CircularTracker
progress={3}
total={5}
isPercentage={false}
strokeWidth={4}
ballStrokeWidth={12}
transitionDuration={0.5}
transitionTimingFunction="ease"
background="#eef2f5"
hideBall={false}
hideValue={false}
gradient={[
{ stop: 0, color: "#7C3AED" }, // Violet-600
{ stop: 1, color: "#6D28D9" }, // Violet-700
]}
subtitle="STEPS"
style={{}}
className="steps-tracker"
suffix=""
centerBackground="transparent"
fontWeight="bold"
fontSize="24px"
textColor="#8E44AD"
/>
You can view and interact with the CircularTracker
component in Storybook. To start Storybook, run the following command:
npm run storybook
This will start Storybook and open it in your default web browser. You can see different examples of the CircularTracker
component and interact with its props.
Contributions are welcome! Please follow these steps to contribute:
- Go to the Issues page.
- Click on the "New Issue" button.
- Provide a clear and descriptive title for the issue.
- Describe the issue in detail, including steps to reproduce, expected behavior, and any relevant screenshots or code snippets.
- Fork the repository by clicking the "Fork" button on the repository page.
- Clone your forked repository to your local machine:
git clone https://github.com/your-username/react_circular_tracker.git
- Create a new branch for your feature or bugfix:
git checkout -b feature-or-bugfix-name
- Make your changes and commit them with a clear and descriptive commit message:
git commit -m "Description of the changes"
- Push your changes to your forked repository:
git push origin feature-or-bugfix-name
- Open a pull request from your forked repository to the main repository. Provide a clear and descriptive title and description for your pull request.
- Clone the repository to your local machine:
git clone https://github.com/BinaryLeo/react_circular_tracker.git
- Navigate to the project directory:
cd react_circular_tracker
- Install the dependencies:
npm install
- Start the Storybook development server:
npm start
This project is licensed under the MIT License. See the LICENSE file for more details.
Leonardo Moura - binaryleo - 2024 Find me on LinkedIn
Thanks to all the contributors and the open-source community for their support.