HextaUI

Progress: Segments

Pass segments to split the fill into parts, such as passed, failed and skipped tests. Each part eases on its own and pushes the parts after it, and their labels are read out with the value.

Running tests
x
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  Progress,
  ProgressLabel,
  ProgressValue,
} from "@/components/ui/progress"

const total = 48

export function ProgressSegments() {
  const [counts, setCounts] = React.useState({ passed: 29, failed: 2, skipped: 1 })
  const done = counts.passed + counts.failed + counts.skipped

  return (
    <div className="flex w-full max-w-sm flex-col items-center gap-6">
      <Progress
        max={total}
        segments={[
          { value: counts.passed, variant: "success", label: "passed" },
          { value: counts.failed, variant: "destructive", label: "failed" },
          { value: counts.skipped, variant: "warning", label: "skipped" },
        ]}
      >
        <ProgressLabel>Running tests</ProgressLabel>
        <ProgressValue>{() => `${done} of ${total}`}</ProgressValue>
      </Progress>
      <div className="flex flex-wrap justify-center gap-2">
        <Button
          variant="outline"
          size="sm"
          disabled={done >= total}
          onClick={() =>
            setCounts((current) => ({ ...current, passed: current.passed + 1 }))
          }
        >
          Pass one
        </Button>
        <Button
          variant="outline"
          size="sm"
          disabled={done >= total}
          onClick={() =>
            setCounts((current) => ({ ...current, failed: current.failed + 1 }))
          }
        >
          Fail one
        </Button>
        <Button
          variant="ghost"
          size="sm"
          onClick={() => setCounts({ passed: 0, failed: 0, skipped: 0 })}
        >
          Reset
        </Button>
      </div>
    </div>
  )
}

This adds the example as components/examples/progress/segments.tsx, together with the Progress component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/progress-segments.json

To add only the component, follow the Progress installation.

Props in this example

The Progress props this example sets, from the API reference.

PropTypeDefault
max
number100
segmentsSplits the fill into parts. Their sum becomes the value.
{ value: number; variant?: ProgressVariant; label?: string }[]–

Every prop is in the Progress API reference.

See them all, with keyboard support and accessibility notes, on the Progress page.