'use client' import { Slider as GuiSlider, Text, View, XStack, YStack } from '@hanzo/gui'; import * as React from 'react'; export interface SliderProps { readonly marks?: Array; readonly label?: React.ReactNode; readonly showValue?: boolean; readonly value?: Array; readonly defaultValue?: Array; readonly min?: number; readonly max?: number; readonly step?: number; readonly disabled?: boolean; readonly orientation?: 'horizontal' | 'vertical'; readonly id?: string; readonly name?: string; readonly onValueChange?: (value: Array) => void; readonly onValueCommit?: (value: Array) => void; readonly className?: string; } const MUTED = 'var(--color-text-secondary)' as never; const TRACK = 'var(--color-border-divider)' as never; const ACTIVE = 'var(--color-link-primary)' as never; const ACTIVE_HOVER = 'var(--color-link-primary-hover)' as never; const WHITE = 'var(--color-white)' as never; // gui's Slider: pointer, touch and keyboard from one implementation, with the // drag handled as a pan gesture by the engine rather than by mouse events — so it // works under a finger, not only under a cursor. `role=slider` and the arrow-key // contract come from the primitive. export const Slider = React.forwardRef( function Slider(props, ref) { const { marks: marksProp, label, showValue, value, defaultValue, min = 0, max = 100, step, disabled, orientation = 'horizontal', name, onValueChange, onValueCommit, className, } = props; const resolvedValue = defaultValue ?? value; const marks = marksProp?.map((mark) => { if (typeof mark === 'number') return { value: mark, label: undefined }; return mark; }); const hasMarkLabel = Boolean(marks?.some((mark) => mark.label)); // gui signals the end of a drag without echoing the value, so keep the last // one to satisfy the Chakra-shaped `onValueCommit(value)` contract. const latest = React.useRef>(value ?? defaultValue ?? []); const handleValueChange = React.useCallback((next: Array) => { latest.current = next; onValueChange?.(next); }, [ onValueChange ]); const handleSlideEnd = React.useCallback(() => { onValueCommit?.(latest.current); }, [ onValueCommit ]); return ( { label && !showValue && ( { label } ) } { label && showValue && ( { label } { (value ?? defaultValue ?? [])?.join(', ') } ) } { resolvedValue?.map((_, index) => ( )) } ); }, ); interface SliderMarksProps { readonly marks?: Array<{ readonly value: number; readonly label?: React.ReactNode }>; readonly min: number; readonly max: number; } function SliderMarks(props: SliderMarksProps): React.ReactNode { const { marks, min, max } = props; if (!marks?.length) return null; const range = max - min; return ( { marks.map((mark, index) => { const percent = ((mark.value - min) / range) * 100; return ( { mark.label != null && ( { mark.label } ) } ); }) } ); }