import React, { useLayoutEffect } from 'react'; import { FloatingPortal, useMergeRefs } from '@floating-ui/react'; import * as ProgressPrimitive from '@radix-ui/react-progress'; import { usePopover } from '../../hooks'; import { type ElementProps } from '../../types'; import { cn } from '../../utils/cn'; import { tooltipContentVariants } from '../tooltip/tooltip'; export interface ProgressProps extends ElementProps { labelType?: 'none' | 'text' | 'floating'; placement?: 'right' | 'bottom' | 'top'; } interface ProgressIndicatorProps extends ElementProps { value?: number | null; } const ProgressIndicator = React.forwardRef< React.ElementRef, ProgressIndicatorProps >(({ className, value, ...props }, ref) => { return ( ); }); interface FloatingProgressIndicatorProps { value?: number | null; placement?: 'right' | 'bottom' | 'top'; className?: string; } const FloatingProgressIndicator = React.forwardRef< React.ElementRef, FloatingProgressIndicatorProps >(({ className, value, placement = 'right', ...props }, indicatorRef) => { const { update, floatingStyles, refs } = usePopover({ open: true, placement: placement === 'top' ? 'top-end' : 'bottom-end', }); useLayoutEffect(() => { update(); }); const ref = useMergeRefs([indicatorRef, refs.setReference]); return ( <>
{value}%
); }); const Progress = React.forwardRef, ProgressProps>( ({ className, value, labelType = 'none', placement = 'right', ...props }, ref) => { return (
{labelType === 'floating' ? ( ) : ( <> )} {labelType === 'text' ? (
{value}%
) : null}
); } ); Progress.displayName = ProgressPrimitive.Root.displayName; export { Progress };