'use client'; import * as React from 'react'; import { cn } from '@/lib/utils/cn'; export interface SliderProps extends Omit, 'onChange' | 'value' | 'onValueChange'> { value?: number | number[]; onChange?: (value: number) => void; onValueChange?: (value: number[]) => void; min?: number; max?: number; step?: number; label?: string; showValue?: boolean; onTouchStart?: () => void; onTouchEnd?: () => void; } const Slider = React.forwardRef( ( { className, value = 0, onChange, onValueChange, min = 0, max = 100, step = 1, label, showValue = false, disabled, onTouchStart, onTouchEnd, ...props }, ref ) => { // Support both value formats (number or number[]) const currentValue = Array.isArray(value) ? value[0] : value; const handleChange = (e: React.ChangeEvent) => { const numValue = parseFloat(e.target.value); onChange?.(numValue); onValueChange?.([numValue]); }; const handleMouseDown = () => { onTouchStart?.(); }; const handleMouseUp = () => { onTouchEnd?.(); }; React.useEffect(() => { if (onTouchEnd) { window.addEventListener('mouseup', handleMouseUp); return () => window.removeEventListener('mouseup', handleMouseUp); } }, [onTouchEnd]); return (
{(label || showValue) && (
{label && ( )} {showValue && ( {currentValue} )}
)}
); } ); Slider.displayName = 'Slider'; export { Slider };