Visualizations
Progress Bar
Visual element to indicate progress, performance, or status represented in a linear way.
import { ProgressBar } from "@/components/ProgressBar"
export const ProgressBarHero = () => { return <ProgressBar value={62} className="mx-auto" />}
Installation
npm i tailwind-variants
- 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.
import { ProgressBar } from "@/components/ProgressBar"
export const ProgressBarExample = () => { return ( <div className="flex items-center justify-center gap-12"> <ProgressBar value={62} /> </div> )}
Example with variants
There are five variants.
import { ProgressBar } from "@/components/ProgressBar"
export const ProgressBarVariantExample = () => ( <div className="mx-auto max-w-sm space-y-4"> <div className="flex items-center justify-between space-x-3"> <ProgressBar variant="default" value={50} className="w-60" /> <span className="text-sm font-semibold text-gray-900 dark:text-gray-50"> Default </span> </div> <div className="flex items-center justify-between space-x-3"> <ProgressBar variant="neutral" value={40} className="w-60" /> <span className="text-sm font-semibold text-gray-900 dark:text-gray-50"> Neutral </span> </div> <div className="flex items-center justify-between space-x-3"> <ProgressBar variant="success" value={50} className="w-60" /> <span className="text-sm font-semibold text-gray-900 dark:text-gray-50"> Success </span> </div> <div className="flex items-center justify-between space-x-3"> <ProgressBar variant="warning" value={20} className="w-60" /> <span className="text-sm font-semibold text-gray-900 dark:text-gray-50"> Warning </span> </div> <div className="flex items-center justify-between space-x-3"> <ProgressBar variant="error" value={10} className="w-60" /> <span className="text-sm font-semibold text-gray-900 dark:text-gray-50"> Error </span> </div> </div>)
Example with label
75%
import { ProgressBar } from "@/components/ProgressBar"
export const ProgressBarLabelExample = () => { return ( <> <ProgressBar value={75} label="75%" /> </> )}
API Reference: ProgressBar
- value
- Sets the value of the progress indicator.
number
Default: 0
- variant
- Set a predefined look.
"default" | "neutral" | "warning" | "error" | "success"
Default: "default"
- showAnimation
- Sets an animation to the chart when value changes.
boolean
Default: true
- max
- Sets the upper boundary vale of the Progess Bar.
number
Default: 100