Progress

PreviousNext

Displays an indicator showing the completion progress of a task.

Docs
opticscomponent

Preview

Loading preview…
registry/optics/progress.jsx
"use client"

import { Progress as ProgressPrimitive } from "@base-ui/react/progress"

import { cn } from "@/lib/utils"

function Progress({
  className = "",
  children = null,
  value = 0,
  ...props
}) {
  return (
    <ProgressPrimitive.Root
      value={value}
      data-slot="progress"
      className={cn("flex flex-wrap gap-3", className)}
      {...props}>
      {children}
      <ProgressTrack>
        <ProgressIndicator />
      </ProgressTrack>
    </ProgressPrimitive.Root>
  );
}

function ProgressTrack({
  className = "",
  ...props
}) {
  return (
    <ProgressPrimitive.Track
      className={cn(
        "bg-muted h-1 rounded-md relative flex w-full items-center overflow-x-hidden",
        className
      )}
      data-slot="progress-track"
      {...props} />
  );
}

function ProgressIndicator({
  className = "",
  ...props
}) {
  return (
    <ProgressPrimitive.Indicator
      data-slot="progress-indicator"
      className={cn("bg-primary h-full transition-all", className)}
      {...props} />
  );
}

function ProgressLabel({
  className = "",
  ...props
}) {
  return (
    <ProgressPrimitive.Label
      className={cn("text-xs/relaxed font-medium", className)}
      data-slot="progress-label"
      {...props} />
  );
}

function ProgressValue({
  className = "",
  ...props
}) {
  return (
    <ProgressPrimitive.Value
      className={cn("text-muted-foreground ml-auto text-xs/relaxed tabular-nums", className)}
      data-slot="progress-value"
      {...props} />
  );
}

export {
  Progress,
  ProgressTrack,
  ProgressIndicator,
  ProgressLabel,
  ProgressValue,
}

Installation

npx shadcn@latest add @optics/progress

Usage

import { Progress } from "@/components/progress"
<Progress />