Search for a command to run...
Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.
npx shadcn@latest add @zaidan/progresspnpx shadcn add @zaidan/progressyarn dlx shadcn@latest add @zaidan/progressbunx shadcn@latest add @zaidan/progressCopy and paste the following code into your project.
1import type { PolymorphicProps } from "@kobalte/core/polymorphic";2import {3 Fill,4 Label,5 type ProgressFillProps,6 type ProgressLabelProps,7 type ProgressRootProps,8 type ProgressTrackProps,9 type ProgressValueLabelProps,10 Root,11 Track,12 ValueLabel,13} from "@kobalte/core/progress";14import { type ComponentProps, splitProps, type ValidComponent } from "solid-js";15import { cn } from "~/lib/utils";16
17type ProgressProps<T extends ValidComponent = "div"> = PolymorphicProps<T, ProgressRootProps<T>> &18 Pick<ComponentProps<T>, "class" | "children">;19
20const Progress = <T extends ValidComponent = "div">(props: ProgressProps<T>) => {21 const [local, others] = splitProps(props as ProgressProps, ["class", "children"]);22 return (23 <Root24 data-slot="progress"25 class={cn("z-progress-root flex flex-wrap gap-3", local.class)}26 {...others}27 >28 {local.children}29 <ProgressTrack>30 <ProgressIndicator />31 </ProgressTrack>32 </Root>33 );34};35
36type ProgressTrackComponentProps<T extends ValidComponent = "div"> = PolymorphicProps<37 T,38 ProgressTrackProps<T>39> &40 Pick<ComponentProps<T>, "class">;41
42const ProgressTrack = <T extends ValidComponent = "div">(props: ProgressTrackComponentProps<T>) => {43 const [local, others] = splitProps(props as ProgressTrackComponentProps, ["class"]);44 return (45 <Track46 data-slot="progress-track"47 class={cn(48 "relative z-progress-track flex w-full items-center overflow-x-hidden",49 local.class,50 )}51 {...others}52 />53 );54};55
56type ProgressIndicatorProps<T extends ValidComponent = "div"> = PolymorphicProps<57 T,58 ProgressFillProps<T>59> &60 Pick<ComponentProps<T>, "class">;61
62const ProgressIndicator = <T extends ValidComponent = "div">(props: ProgressIndicatorProps<T>) => {63 const [local, others] = splitProps(props as ProgressIndicatorProps, ["class"]);64 return (65 <Fill66 data-slot="progress-indicator"67 class={cn(68 "z-progress-indicator h-full w-(--kb-progress-fill-width) transition-all",69 local.class,70 )}71 {...others}72 />73 );74};75
76type ProgressLabelComponentProps<T extends ValidComponent = "span"> = PolymorphicProps<77 T,78 ProgressLabelProps<T>79> &80 Pick<ComponentProps<T>, "class">;81
82const ProgressLabel = <T extends ValidComponent = "span">(83 props: ProgressLabelComponentProps<T>,84) => {85 const [local, others] = splitProps(props as ProgressLabelComponentProps, ["class"]);86 return (87 <Label data-slot="progress-label" class={cn("z-progress-label", local.class)} {...others} />88 );89};90
91type ProgressValueProps<T extends ValidComponent = "div"> = PolymorphicProps<92 T,93 ProgressValueLabelProps<T>94> &95 Pick<ComponentProps<T>, "class">;96
97const ProgressValue = <T extends ValidComponent = "div">(props: ProgressValueProps<T>) => {98 const [local, others] = splitProps(props as ProgressValueProps, ["class"]);99 return (100 <ValueLabel101 data-slot="progress-value"102 class={cn("z-progress-value", local.class)}103 {...others}104 />105 );106};107
108export { Progress, ProgressTrack, ProgressIndicator, ProgressLabel, ProgressValue };import { Progress, ProgressLabel, ProgressValue,} from "~/components/ui/progress";1<Progress value={75}>2 <div class="flex w-full justify-between">3 <ProgressLabel>Loading...</ProgressLabel>4 <ProgressValue />5 </div>6</Progress>Use the indeterminate prop to show an indeterminate progress state.
1<Progress indeterminate>2 <ProgressLabel>Processing...</ProgressLabel>3</Progress>Use minValue and maxValue to set custom value ranges.
1<Progress value={5} minValue={0} maxValue={10}>2 <div class="flex w-full justify-between">3 <ProgressLabel>5 of 10 tasks completed</ProgressLabel>4 <ProgressValue />5 </div>6</Progress>Here are the source code of all the examples from the preview page:
import { Progress } from "~/components/ui/progress";function ProgressValues() { return ( <Example title="Progress Bar"> <div class="flex w-full flex-col gap-4"> <Progress value={0} /> <Progress value={25} class="w-full" /> <Progress value={50} /> <Progress value={75} /> <Progress value={100} /> </div> </Example> );}import { Progress, ProgressLabel, ProgressValue } from "~/components/ui/progress";function ProgressWithLabel() { return ( <Example title="With Label"> <Progress value={56}> <ProgressLabel>Upload progress</ProgressLabel> <ProgressValue /> </Progress> </Example> );}import { createSignal } from "solid-js";import { Progress } from "~/components/ui/progress";import { Slider } from "~/components/ui/slider";function ProgressControlled() { const [value, setValue] = createSignal(50);
return ( <Example title="Controlled"> <div class="flex w-full flex-col gap-4"> <Progress value={value()} class="w-full" /> <Slider value={[value()]} onChange={(values) => setValue(values[0])} minValue={0} maxValue={100} step={1} /> </div> </Example> );}import { FileIcon } from "lucide-solid";import { For } from "solid-js";import { Item, ItemActions, ItemContent, ItemGroup, ItemMedia, ItemTitle,} from "~/components/ui/item";import { Progress } from "~/components/ui/progress";function FileUploadList() { const files = [ { id: "1", name: "document.pdf", progress: 45, timeRemaining: "2m 30s", }, { id: "2", name: "presentation.pptx", progress: 78, timeRemaining: "45s", }, { id: "3", name: "spreadsheet.xlsx", progress: 12, timeRemaining: "5m 12s", }, { id: "4", name: "image.jpg", progress: 100, timeRemaining: "Complete", }, ];
return ( <Example title="File Upload List"> <ItemGroup> <For each={files}> {(file) => ( <Item size="xs" class="px-0"> <ItemMedia variant="icon"> <FileIcon class="size-5" /> </ItemMedia> <ItemContent class="inline-block truncate"> <ItemTitle class="inline">{file.name}</ItemTitle> </ItemContent> <ItemContent> <Progress value={file.progress} class="w-32" /> </ItemContent> <ItemActions class="w-16 justify-end"> <span class="text-muted-foreground text-sm">{file.timeRemaining}</span> </ItemActions> </Item> )} </For> </ItemGroup> </Example> );}