Synertech Web/ui v0.57.5 Site Storybook

Documentation / Display & media

ProgressBar

Server-compatible@synertech/uiOpen in Storybook

A horizontal progress bar for a task whose progress is known (value, from 0 to 100, clamped to that range) or not (indeterminate). Five sizes, six colours and three styles: solid, striped (striped) or gradient (gradient).

The track carries role="progressbar" with aria-valuenow (absent in indeterminate mode); label serves as both the visible title and the accessible name: give it one, or name the bar with aria-labelledby / aria-label when the page already shows its label — they go to the track, not to the wrapper. showValue shows the percentage, which valueFormat can replace. progressColor and trackColor replace the colours of the fill and of the track. No hooks, server-compatible.

Examples

Basic usage

A value, a label and the percentage shown on the right.

Open in a tab
import { ProgressBar } from "@synertech/ui";

export function Basic() {
  return <ProgressBar value={64} label="Import des contacts" showValue />;
}

Sizes and colours

size sets the track thickness, color the fill hue.

Open in a tab
import { ProgressBar } from "@synertech/ui";

export function SizesAndColors() {
  return (
    <div className="space-y-4">
      <ProgressBar value={30} size="xs" color="default" label="Très fine" />
      <ProgressBar value={50} size="sm" color="info" label="Fine" />
      <ProgressBar value={70} size="lg" color="success" label="Épaisse" />
      <ProgressBar value={90} size="xl" color="warning" label="Très épaisse" />
    </div>
  );
}

Styles

striped adds stripes, gradient replaces the flat fill with a gradient.

Open in a tab
import { ProgressBar } from "@synertech/ui";

export function Variants() {
  return (
    <div className="space-y-4">
      <ProgressBar value={55} size="lg" variant="striped" label="Hachurée" />
      <ProgressBar value={55} size="lg" variant="gradient" label="Dégradé" />
    </div>
  );
}

Unknown duration

indeterminate runs a segment with no value, and hides the percentage.

Open in a tab
import { ProgressBar } from "@synertech/ui";

export function Indeterminate() {
  return <ProgressBar indeterminate label="Connexion au serveur…" />;
}

Value format

valueFormat receives the clamped value and returns the text to display.

Open in a tab
import { useEffect, useState } from "react";
import { ProgressBar } from "@synertech/ui";

export function CustomFormat() {
  const [value, setValue] = useState(0);

  useEffect(() => {
    const timer = setInterval(
      () => setValue((current) => (current >= 100 ? 0 : current + 10)),
      600
    );
    return () => clearInterval(timer);
  }, []);

  return (
    <ProgressBar
      value={value}
      label="Envoi des fichiers"
      showValue
      valueFormat={(v) => `${Math.round((v / 100) * 24)} / 24 fichiers`}
    />
  );
}

Brand colour and a label of the page

progressColor and trackColor replace the colours of color; aria-labelledby names the bar with a text the page already shows, without repeating it.

Open in a tab
import { ProgressBar } from "@synertech/ui";

export function BrandColor() {
  return (
    <div className="max-w-md space-y-2">
      <p id="generation-progress" className="text-sm font-medium">
        Génération : 3 documents sur 10 (30 %)
      </p>
      <ProgressBar
        value={30}
        aria-labelledby="generation-progress"
        progressColor="bg-orange-600 dark:bg-orange-500"
        trackColor="bg-orange-100 dark:bg-orange-950"
      />
    </div>
  );
}

Subscription quotas

The colour follows the threshold: the label stays readable, the hue is only reinforcement.

Open in a tab
import { ProgressBar } from "@synertech/ui";

const quotas = [
  { label: "Stockage", used: 42 },
  { label: "Utilisateurs", used: 78 },
  { label: "Appels API", used: 96 },
];

export function Quotas() {
  return (
    <div className="max-w-md space-y-4">
      {quotas.map((quota) => (
        <ProgressBar
          key={quota.label}
          value={quota.used}
          label={quota.label}
          showValue
          color={quota.used >= 90 ? "error" : quota.used >= 75 ? "warning" : "primary"}
        />
      ))}
    </div>
  );
}

API reference

Components

ProgressBar

ComponentServer-compatible
import { ProgressBar } from "@synertech/ui";

Props — ProgressBarProps

PropTypeDefaultDescription
animated boolean true
aria-describedby string —

Id of the element that describes the bar. Goes to the element that holds the progressbar role.

aria-label string —

Accessible name of the bar. Goes to the element that holds the progressbar role, not to the wrapper, and wins over label.

aria-labelledby string —

Id of the element that names the bar: a label the page already shows. Goes to the element that holds the progressbar role.

aria-valuetext string —

The value as a reader should hear it, when a percentage is not it: "3 of 10 files". Goes to the element that holds the progressbar role.

color ProgressBarColor "primary"
indeterminate boolean false
label string —

Text shown above the bar, which also names it. A page that already shows a label of its own names the bar with aria-labelledby or aria-label instead.

progressColor string —

Classes that colour the fill, in place of the ones color and variant pick: "bg-orange-600", or a gradient. The same prop as on CircularProgress.

showValue boolean false
size ProgressBarSize "md"
trackColor string —

Classes that colour the track behind the fill, in place of the grey one.

value number 0
valueFormat (value: number) => string —
variant ProgressBarVariant "default"

+ 273 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

Types

type ProgressBarColor = "default" | "primary" | "success" | "warning" | "error" | "info"
type ProgressBarSize = "xs" | "sm" | "md" | "lg" | "xl"
type ProgressBarVariant = "default" | "striped" | "gradient"