refactor: update Slider component to allow custom track class name

This commit is contained in:
Danny Avila 2024-09-03 15:29:20 -04:00
parent 52fd59de0e
commit 3d50a4f6f8
No known key found for this signature in database
GPG key ID: 2DD9CC89B9B50364
2 changed files with 10 additions and 3 deletions

View file

@ -141,6 +141,7 @@ function DynamicSlider({
max={max}
min={range ? range.min : 0}
step={range ? range.step ?? 1 : 1}
trackClassName="bg-surface-hover"
className="flex h-4 w-full"
/>
)}

View file

@ -2,20 +2,26 @@ import * as React from 'react';
import * as SliderPrimitive from '@radix-ui/react-slider';
import { useDoubleClick } from '@zattoo/use-double-click';
import type { clickEvent } from '@zattoo/use-double-click';
import { cn } from '../../utils';
import { cn } from '~/utils';
interface SliderProps extends React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root> {
doubleClickHandler?: clickEvent;
trackClassName?: string;
}
const Slider = React.forwardRef<React.ElementRef<typeof SliderPrimitive.Root>, SliderProps>(
({ className, doubleClickHandler, ...props }, ref) => (
(
{ className, trackClassName = 'bg-gray-200 dark:bg-gray-850', doubleClickHandler, ...props },
ref,
) => (
<SliderPrimitive.Root
ref={ref}
className={cn('relative flex w-full touch-none select-none items-center', className ?? '')}
{...props}
>
<SliderPrimitive.Track className="relative h-1 w-full grow overflow-hidden rounded-full bg-gray-200 dark:bg-gray-850">
<SliderPrimitive.Track
className={cn('relative h-1 w-full grow overflow-hidden rounded-full', trackClassName)}
>
<SliderPrimitive.Range className="absolute h-full bg-gray-850 dark:bg-white" />
</SliderPrimitive.Track>
<SliderPrimitive.Thumb