({
label,
thumbLabels,
fillOffset,
formatOptions,
style,
...props
}: SliderProps)
| 33 | } |
| 34 | |
| 35 | export function Slider({ |
| 36 | label, |
| 37 | thumbLabels, |
| 38 | fillOffset, |
| 39 | formatOptions, |
| 40 | style, |
| 41 | ...props |
| 42 | }: SliderProps) { |
| 43 | let trackRef = useRef<HTMLDivElement>(null); |
| 44 | let numberFormatter = useNumberFormatter(formatOptions); |
| 45 | let state = useSliderState({...props, numberFormatter}); |
| 46 | /*- begin highlight -*/ |
| 47 | let {groupProps, trackProps, labelProps, outputProps} = useSlider(props, state, trackRef); |
| 48 | /*- end highlight -*/ |
| 49 | |
| 50 | // The fill spans from fillOffset (or the min) to the last thumb. |
| 51 | let start = |
| 52 | state.values.length > 1 |
| 53 | ? state.getThumbPercent(0) * 100 |
| 54 | : state.getValuePercent(fillOffset ?? state.getThumbMinValue(0)) * 100; |
| 55 | let end = state.getThumbPercent(state.values.length - 1) * 100; |
| 56 | let startPercent = Math.min(start, end); |
| 57 | let sizePercent = Math.max(0, Math.max(start, end) - startPercent); |
| 58 | |
| 59 | return ( |
| 60 | <div |
| 61 | {...groupProps} |
| 62 | className="react-aria-Slider" |
| 63 | data-orientation={state.orientation} |
| 64 | style={style}> |
| 65 | {label && ( |
| 66 | <label className="react-aria-Label" {...labelProps}> |
| 67 | {label} |
| 68 | </label> |
| 69 | )} |
| 70 | <output {...outputProps} className="react-aria-SliderOutput"> |
| 71 | {state.getFormattedValue()} |
| 72 | </output> |
| 73 | <div {...trackProps} ref={trackRef} className="react-aria-SliderTrack"> |
| 74 | <div className="track inset" data-disabled={state.isDisabled || undefined}> |
| 75 | <div |
| 76 | className="react-aria-SliderFill" |
| 77 | style={{ |
| 78 | position: 'absolute', |
| 79 | insetInlineStart: `${startPercent}%`, |
| 80 | width: `${sizePercent}%`, |
| 81 | height: '100%' |
| 82 | }} |
| 83 | /> |
| 84 | </div> |
| 85 | {state.values.map((_, i) => ( |
| 86 | <Thumb |
| 87 | key={i} |
| 88 | index={i} |
| 89 | state={state} |
| 90 | trackRef={trackRef} |
| 91 | aria-label={thumbLabels?.[i]} |
| 92 | /> |
nothing calls this directly
no test coverage detected