progress.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use client';
  2. import { Progress as ProgressPrimitive } from '@base-ui/react/progress';
  3. import { cn } from '@/lib/utils';
  4. function Progress({
  5. className,
  6. children,
  7. value,
  8. ...props
  9. }: ProgressPrimitive.Root.Props) {
  10. return (
  11. <ProgressPrimitive.Root
  12. value={value}
  13. data-slot="progress"
  14. className={cn('flex flex-wrap gap-3', className)}
  15. {...props}
  16. >
  17. {children}
  18. <ProgressTrack>
  19. <ProgressIndicator />
  20. </ProgressTrack>
  21. </ProgressPrimitive.Root>
  22. );
  23. }
  24. function ProgressTrack({ className, ...props }: ProgressPrimitive.Track.Props) {
  25. return (
  26. <ProgressPrimitive.Track
  27. className={cn(
  28. 'bg-muted h-1 rounded-full relative flex w-full items-center overflow-x-hidden',
  29. className,
  30. )}
  31. data-slot="progress-track"
  32. {...props}
  33. />
  34. );
  35. }
  36. function ProgressIndicator({
  37. className,
  38. ...props
  39. }: ProgressPrimitive.Indicator.Props) {
  40. return (
  41. <ProgressPrimitive.Indicator
  42. data-slot="progress-indicator"
  43. className={cn('bg-primary h-full transition-all', className)}
  44. {...props}
  45. />
  46. );
  47. }
  48. function ProgressLabel({ className, ...props }: ProgressPrimitive.Label.Props) {
  49. return (
  50. <ProgressPrimitive.Label
  51. className={cn('text-sm font-medium', className)}
  52. data-slot="progress-label"
  53. {...props}
  54. />
  55. );
  56. }
  57. function ProgressValue({ className, ...props }: ProgressPrimitive.Value.Props) {
  58. return (
  59. <ProgressPrimitive.Value
  60. className={cn(
  61. 'text-muted-foreground ml-auto text-sm tabular-nums',
  62. className,
  63. )}
  64. data-slot="progress-value"
  65. {...props}
  66. />
  67. );
  68. }
  69. export {
  70. Progress,
  71. ProgressTrack,
  72. ProgressIndicator,
  73. ProgressLabel,
  74. ProgressValue,
  75. };