Skip to content
2k
On This Page

Progress

Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.

import { Progress } from "~/components/ui/progress"

export default function ProgressDemo() {
  return (
    <div class="grid w-full max-w-sm gap-4">
      <Progress value={25} />
      <Progress value={50} />
      <Progress value={80} />
    </div>
  )
}

Installation

pnpm dlx solidui-cli@latest add progress

Install the following dependencies:

pnpm add @ui-sdk/solid @ui-sdk/core

Copy and paste the following code into your project.

components/ui/progress.tsx
import { type ComponentProps } from "@solidjs/web"
import {
  Progress as SdkProgress,
  ProgressTrack as SdkProgressTrack,
  ProgressIndicator as SdkProgressIndicator,
  ProgressLabel as SdkProgressLabel,
  ProgressValue as SdkProgressValue
} from "@ui-sdk/solid/progress"
import { omit } from "solid-js"

import { cn } from "~/lib/utils"
type ProgressProps = Omit<ComponentProps<typeof SdkProgress>, "class"> & {
  class?: string
}
const Progress = (props: ProgressProps) => {
  const others = omit(props, "class", "children")
  return (
    <SdkProgress class={cn("w-full", props.class)} {...others}>
      {props.children}
      <SdkProgressTrack
        class={cn("h-1 rounded-full bg-muted h-1 rounded-full bg-muted relative overflow-hidden")}
      >
        <SdkProgressIndicator
          class={cn(
            "bg-primary h-full w-(--progress-value) transition-all"
          )}
        />
      </SdkProgressTrack>
    </SdkProgress>
  )
}
type ProgressLabelProps = Omit<
  ComponentProps<typeof SdkProgressLabel>,
  "class"
> & {
  class?: string
}
const ProgressLabel = (props: ProgressLabelProps) => (
  <SdkProgressLabel {...props} class={cn("text-sm font-medium", props.class)} />
)
type ProgressValueProps = Omit<
  ComponentProps<typeof SdkProgressValue>,
  "class"
> & {
  class?: string
}
const ProgressValue = (props: ProgressValueProps) => (
  <SdkProgressValue {...props} class={cn("ml-auto text-sm text-muted-foreground tabular-nums", props.class)} />
)
export {
  Progress,
  ProgressLabel,
  ProgressValue,
  type ProgressLabelProps,
  type ProgressProps,
  type ProgressValueProps
}

Update the import paths to match your project setup.

Usage

import { Progress } from "~/components/ui/progress"
<Progress value={65} />

Label

Use a Field component to add a label to the progress bar.

import { Field, FieldLabel } from "~/components/ui/field"
import { Progress } from "~/components/ui/progress"

export default function ProgressWithLabel() {
  return (
    <Field class="w-full max-w-sm">
      <FieldLabel for="progress-upload">
        <span>Upload progress</span>
        <span class="ml-auto">66%</span>
      </FieldLabel>
      <Progress value={66} id="progress-upload" />
    </Field>
  )
}

Controlled

A progress bar that can be controlled by a slider.

import { createSignal } from "solid-js"

import { Progress } from "~/components/ui/progress"
import { Slider } from "~/components/ui/slider"

export default function ProgressControlled() {
  const [value, setValue] = createSignal([50])

  return (
    <div class="flex w-full max-w-sm flex-col gap-4">
      <Progress value={value()[0] ?? 0} class="w-full" />
      <Slider
        max={100}
        min={0}
        onValueChange={setValue}
        step={1}
        value={value()}
      />
    </div>
  )
}

API Reference

PartDescription
ProgressRoot container that manages progress state and ARIA attributes.
ProgressLabelAccessible text label associated with the progress bar.
ProgressValueFormatted value label generated from progress state.

Progress renders the track and indicator internally.

See the UI SDK documentation for more information.