MCPcopy Create free account
hub / github.com/adobe/react-spectrum / ColorSlider

Function ColorSlider

starters/hooks/src/ColorSlider.tsx:16–69  ·  view source on GitHub ↗
({style, ...props}: ColorSliderProps)

Source from the content-addressed store, hash-verified

14}
15
16export function ColorSlider({style, ...props}: ColorSliderProps) {
17 let {locale} = useLocale();
18 // useColorSliderState manages the single channel value behind the gradient track.
19 let state = useColorSliderState({...props, locale});
20 let trackRef = useRef<HTMLDivElement>(null);
21 let inputRef = useRef<HTMLInputElement>(null);
22
23 // Default the label to the channel name in the current locale.
24 let label = props.label || state.value.getChannelName(props.channel, locale);
25 /*- begin highlight -*/
26 let {trackProps, thumbProps, inputProps, labelProps, outputProps} = useColorSlider(
27 {...props, label, trackRef, inputRef},
28 state
29 );
30 /*- end highlight -*/
31 let {focusProps, isFocusVisible} = useFocusRing();
32
33 return (
34 <div
35 className="react-aria-ColorSlider"
36 data-orientation={state.orientation}
37 data-disabled={state.isDisabled || undefined}
38 style={style}>
39 <label {...labelProps} className="react-aria-Label">
40 {label}
41 </label>
42 <output {...outputProps} className="react-aria-SliderOutput">
43 {state.value.formatChannelValue(props.channel, locale)}
44 </output>
45 <div
46 {...trackProps}
47 ref={trackRef}
48 className="react-aria-SliderTrack"
49 style={{
50 ...trackProps.style,
51 // Layer a checkerboard behind the gradient to communicate transparency.
52 background: `${trackProps.style?.background},
53 repeating-conic-gradient(#CCC 0% 25%, white 0% 50%) 50% / 16px 16px`
54 }}>
55 <div
56 {...thumbProps}
57 className="react-aria-ColorThumb"
58 data-focus-visible={isFocusVisible || undefined}
59 data-disabled={state.isDisabled || undefined}
60 style={{
61 ...thumbProps.style,
62 background: state.getDisplayColor().toString('css')
63 }}>
64 <input ref={inputRef} {...inputProps} {...focusProps} />
65 </div>
66 </div>
67 </div>
68 );
69}

Callers

nothing calls this directly

Calls 8

useLocaleFunction · 0.90
useColorSliderStateFunction · 0.90
useColorSliderFunction · 0.90
useFocusRingFunction · 0.90
getChannelNameMethod · 0.80
formatChannelValueMethod · 0.65
toStringMethod · 0.65
getDisplayColorMethod · 0.65

Tested by

no test coverage detected