Visualizations

Progress Bar

Visual element to indicate progress, performance, or status represented in a linear way.

Installation

  1. 1

    Install dependencies:

    npm i tailwind-variants
  2. 2

    Add component:

    Copy and paste the code into your project’s component directory. Do not forget to update the import paths.
    // Tremor ProgressBar [v0.0.3]
    import React from "react"import { tv, type VariantProps } from "tailwind-variants"
    import { cx } from "@/lib/utils"
    const progressBarVariants = tv({  slots: {    background: "",    bar: "",  },  variants: {    variant: {      default: {        background: "bg-blue-200 dark:bg-blue-500/30",        bar: "bg-blue-500 dark:bg-blue-500",      },      neutral: {        background: "bg-gray-200 dark:bg-gray-500/40",        bar: "bg-gray-500 dark:bg-gray-500",      },      warning: {        background: "bg-yellow-200 dark:bg-yellow-500/30",        bar: "bg-yellow-500 dark:bg-yellow-500",      },      error: {        background: "bg-red-200 dark:bg-red-500/30",        bar: "bg-red-500 dark:bg-red-500",      },      success: {        background: "bg-emerald-200 dark:bg-emerald-500/30",        bar: "bg-emerald-500 dark:bg-emerald-500",      },    },  },  defaultVariants: {    variant: "default",  },})
    interface ProgressBarProps  extends React.HTMLProps<HTMLDivElement>,    VariantProps<typeof progressBarVariants> {  value?: number  max?: number  showAnimation?: boolean  label?: string}
    const ProgressBar = React.forwardRef<HTMLDivElement, ProgressBarProps>(  (    {      value = 0,      max = 100,      label,      showAnimation = false,      variant,      className,      ...props    }: ProgressBarProps,    forwardedRef,  ) => {    const safeValue = Math.min(max, Math.max(value, 0))    const { background, bar } = progressBarVariants({ variant })    return (      <div        ref={forwardedRef}        className={cx("flex w-full items-center", className)}        role="progressbar"        aria-label="Progress bar"        aria-valuenow={value}        aria-valuemax={max}        tremor-id="tremor-raw"        {...props}      >        <div          className={cx(            "relative flex h-2 w-full items-center rounded-full",            background(),          )}        >          <div            className={cx(              "h-full flex-col rounded-full",              bar(),              showAnimation &&                "transform-gpu transition-all duration-300 ease-in-out",            )}            style={{              width: max ? `${(safeValue / max) * 100}%` : `${safeValue}%`,            }}          />        </div>        {label ? (          <span            className={cx(              // base              "ml-2 whitespace-nowrap text-sm font-medium leading-none",              // text color              "text-gray-900 dark:text-gray-50",            )}          >            {label}          </span>        ) : null}      </div>    )  },)
    ProgressBar.displayName = "ProgressBar"
    export { ProgressBar, progressBarVariants, type ProgressBarProps }
    

Example

The ProgressBar accepts input values ranging from 0 to 100, where 100 represents 100 percent. If no data is available or if value is equal to zero, the indicator is not displayed, leaving only the background.

Example with variants

There are five variants.

Default
Neutral
Success
Warning
Error

Example with label

75%

API Reference: ProgressBar

value
number
Sets the value of the progress indicator.

Default: 0

variant
"default" | "neutral" | "warning" | "error" | "success"
Set a predefined look.

Default: "default"

showAnimation
boolean
Sets an animation to the chart when value changes.

Default: true

max
number
Sets the upper boundary vale of the Progess Bar.

Default: 100