Files
SnowLuma/packages/ui/src/components/progress.tsx
T
DrSmoothl b3e37e2f7c feat(ui): add indeterminate mode to Progress
Desktop's core-download dialog needs to show progress while the server
returns no Content-Length (some mirrors omit it; the SnowLuma core
release artifact does have it but GitHub's CDN sometimes strips it on
redirects). Hard-coded 50% was a placeholder.

Add an `indeterminate` boolean prop: when true, render a marquee bar
that animates left-to-right indefinitely. When false, render the
familiar bytes-done / bytes-total fill at `value%`. Hooked up via a new
`@keyframes progress-marquee` in theme.css.

Also dropped the bar's CSS transition from 500ms → 200ms so live
download updates feel responsive instead of laggy.
2026-05-17 16:31:30 +08:00

55 lines
1.6 KiB
TypeScript

import * as React from 'react';
import { cn } from '../lib/cn';
interface ProgressProps extends React.HTMLAttributes<HTMLDivElement> {
value?: number;
indicatorClassName?: string;
/**
* When true, the bar shows an animated marquee instead of a fixed
* width — useful when we know a job is running but don't yet know
* the total size (e.g. a download whose Content-Length is unknown).
*/
indeterminate?: boolean;
}
const Progress = React.forwardRef<HTMLDivElement, ProgressProps>(
({ className, value = 0, indicatorClassName, indeterminate = false, ...props }, ref) => {
const clamped = Math.max(0, Math.min(100, value));
return (
<div
ref={ref}
role="progressbar"
aria-valuenow={indeterminate ? undefined : clamped}
aria-valuemin={0}
aria-valuemax={100}
className={cn(
'relative h-2 w-full overflow-hidden rounded-full bg-muted',
className,
)}
{...props}
>
{indeterminate ? (
<div
className={cn(
'absolute inset-y-0 left-0 w-1/3 rounded-full bg-primary',
'animate-[progress-marquee_1.4s_ease-in-out_infinite]',
indicatorClassName,
)}
/>
) : (
<div
className={cn(
'h-full rounded-full bg-primary transition-[width] duration-200 ease-out',
indicatorClassName,
)}
style={{ width: `${clamped}%` }}
/>
)}
</div>
);
},
);
Progress.displayName = 'Progress';
export { Progress };