Provides the behavior and accessibility implementation for a color slider component. Color sliders allow users to adjust an individual channel of a color value.
import {ColorSlider} from './ColorSlider';
<ColorSlider channel="hue" defaultValue="hsl(0, 100%, 50%)" />
API
<ColorSlider>
<Label />
<SliderOutput />
<SliderTrack>
<ColorThumb />
</SliderTrack>
</ColorSlider>
useColorSliderState (props: ColorSliderStateOptions ): ColorSliderStateuseColorSlider (props: AriaColorSliderOptions, state: ColorSliderState ): ColorSliderAriaColorSliderState
Properties
| Name | Type | |
|---|---|---|
value | Color | |
The current color value represented by the color slider. | ||
isDragging | boolean | |
Whether the color slider is currently being dragged. | ||
values | number | |
Values managed by the slider by thumb index. | ||
defaultValues | number | |
The default values for each thumb. | ||
focusedThumb | number | undefined | |
Currently-focused thumb index. | ||
pageSize | number | |
The page size for the slider, used to do a bigger step. | ||
orientation | Orientation | |
The orientation of the slider. | ||
isDisabled | boolean | |
Whether the slider is disabled. | ||
Methods
setValue | ||
| Sets the current color value. If a string is passed, it will be parsed to a Color. | ||
getDisplayColor | ||
Returns the color that should be displayed in the slider instead of value or the optional
parameter. | ||
getThumbValue | ||
| Get the value for the specified thumb. | ||
setThumbValue | ||
| Sets the value for the specified thumb. The actual value set will be clamped and rounded according to min/max/step. | ||
setThumbPercent | ||
| Sets value for the specified thumb by percent offset (between 0 and 1). | ||
isThumbDragging | ||
| Whether the specific thumb is being dragged. | ||
setThumbDragging | ||
| Set is dragging on the specified thumb. | ||
setFocusedThumb | ||
| Set focused true on specified thumb. This will remove focus from any thumb that had it before. | ||
getThumbPercent | ||
| Returns the specified thumb's value as a percentage from 0 to 1. | ||
getValuePercent | ||
| Returns the value as a percent between the min and max of the slider. | ||
getThumbValueLabel | ||
| Returns the string label for the specified thumb's value, per props.formatOptions. | ||
getFormattedValue | ||
| Returns the string label for the value, per props.formatOptions. | ||
getThumbMinValue | ||
| Returns the min allowed value for the specified thumb. | ||
getThumbMaxValue | ||
| Returns the max allowed value for the specified thumb. | ||
getPercentValue | ||
| Converts a percent along track (between 0 and 1) to the corresponding value. | ||
isThumbEditable | ||
| Returns if the specified thumb is editable. | ||
setThumbEditable | ||
| Set the specified thumb's editable state. | ||
incrementThumb | ||
| Increments the value of the thumb by the step or page amount. | ||
decrementThumb | ||
| Decrements the value of the thumb by the step or page amount. | ||
AriaColorSliderOptions
| Name | Type | Default |
|---|---|---|
trackRef | RefObject | Default: — |
A ref for the track element. | ||
inputRef | RefObject | Default: — |
A ref for the input element. | ||
colorSpace | ColorSpace | Default: — |
The color space that the slider operates in. The | ||
channel | ColorChannel | Default: — |
The color channel that the slider manipulates. | ||
orientation | Orientation | Default: 'horizontal'
|
The orientation of the Slider. | ||
isDisabled | boolean | Default: — |
Whether the whole Slider is disabled. | ||
value | T | Default: — |
The current value (controlled). | ||
defaultValue | T | Default: — |
The default value (uncontrolled). | ||
onChange | | Default: — |
Handler that is called when the value changes, as the user drags. | ||
onChangeEnd | | Default: — |
Handler that is called when the user stops dragging. | ||
ColorSliderAria
| Name | Type | |
|---|---|---|
labelProps | DOMAttributes | |
Props for the label element. | ||
trackProps | DOMAttributes | |
Props for the track element. | ||
thumbProps | DOMAttributes | |
Props for the thumb element. | ||
inputProps | InputHTMLAttributes | |
Props for the visually hidden range input element. | ||
outputProps | DOMAttributes | |
Props for the output element, displaying the value of the color slider. | ||