1.3.0 • Published 2 years ago

react-multi-progress v1.3.0

Weekly downloads
7
License
ISC
Repository
github
Last release
2 years ago

react-multi-progress

alt text

A simple, typed react progress bar that allowes multiple layers in different colors. Demo

Installation

Install with npm:

  • npm install react-multi-progress --save

You can now import react-multi-progress as a normal package installed from npm like so:

import MultiProgress from 'react-multi-progress'
...

You can also import the type definitions if you're using TypeScript like so:

import MultiProgress, { IMultiProgressProps } from 'react-multi-progress'
...

Available props

AttributeTypeOptionalDefaultDescription
backgroundColorstringyes#ffffffBackground color of the progress bar
borderstringyesnoneset a border around the progress bar, e.g. 1px solid red
elementsProgressElement[]nononeSet the color and size of each element, see "ProgressElement" below.
heightnumberyes10Height of the progress bar in px
roundboolyestrueWheter the ends of the progress bar container should be rounded
roundLastElementboolyestrueWheter the last progress element should be rounded on the right end
transitionTimenumberyes0.6Transition time in seconds to animate when the value changes. Set to 0 for no animation.
classNamestringyesCSS className passed onto the ProgressBar Container
componentElementTypeyesdivCustom element used to render progress elements, either a HTML tag name or React component accepting className, children, and element props, with element being the ProgressElement passed in. Be sure to spread the remaining props (see example) as style information is provided in this way (a data attribute)
type generic (see example)Record<string, any>yesRecord<string, never>Additional props to add to the definition of elements, for use with custom components

ProgressElement

AttributeTypeOptionalDescription
valuenumbernoLength of the element in % (0-100)
colorstringnoColor of the element (any css compatible format)
showPercentageboolyesShow the percentage as text in the ProgressElement
textColorstringyesColor of the percentage text (any css compatible format)
fontSizenumberyesfont size of the percentage text (in px)
classNamestringyesCSS className passed onto the ProgressElement

Example

Basic

import MultiProgress from "react-multi-progress";

function Progress() {
	return (
		<MultiProgress
			elements={[
				{
					value: 35,
					color: "blue",
				},
			]}
		/>
	);
}

Advanced

import MultiProgress, { ProgressComponentProps } from "react-multi-progress";

// for non-TS projects, remove this and other types
type ExtraData = { isBold: boolean };

function CustomComponent({
	children,
	element,
	...rest
}: ProgressComponentProps<ExtraData>) {
	return (
		<div
			{...rest} // adds all styles for rendering the progress bar
			style={{
				fontWeight: element.isBold ? 900 : 300,
			}}
		>
			{children}
		</div>
	);
}

function Progress() {
	return (
		<MultiProgress<ExtraData>
			transitionTime={1.2}
			elements={[
				{
					value: 15,
					color: "blue",
					isBold: false,
				},
				{
					value: 35,
					color: "rgb(100,0,0)",
					showPercentage: true,
					fontSize: 12,
					textColor: "white",
					isBold: true,
				},
				{
					value: 25,
					color: "black",
					showPercentage: true,
					textColor: "white",
					fontSize: 12,
					isBold: false,
					className: "my-custom-css-class",
				},
			]}
			height={15}
			backgroundColor="gray"
			border="1px solid red"
			className="my-custom-css-class"
			component={CustomComponent}
		/>
	);
}
1.2.0

2 years ago

1.1.6

2 years ago

1.3.0

2 years ago

1.1.5

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago