import * as React from 'react'; import * as SliderPrimitive from '@radix-ui/react-slider'; import { useControllableState } from '@radix-ui/react-use-controllable-state'; import { cn } from '../../utils/cn'; import { Tooltip, TooltipProvider } from '../tooltip'; export interface SliderProps extends React.ComponentPropsWithoutRef { withLabel?: boolean; withTooltip?: boolean; formatLabel?: (value: number) => string; } const Slider = React.forwardRef, SliderProps>( ( { className, withLabel, withTooltip, orientation = 'horizontal', onValueChange, min, max, formatLabel = (v) => `${v}%`, defaultValue, value: valueProp, ...props }, ref ) => { const [value, setValue] = useControllableState({ defaultProp: defaultValue, prop: valueProp, onChange: onValueChange, }); return ( {value?.map((v, i) => ( {formatLabel(v ?? 0)}} >
{formatLabel(v ?? 0)}
))}
); } ); Slider.displayName = SliderPrimitive.Root.displayName; export { Slider };