React Aria and React Spectrum have a new home!
useColorWheelState
Provides state management for a color wheel component. Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.
| install | yarn add react-stately |
|---|---|
| version | 3.42.0 |
| usage | import {useColorSliderState} from 'react-stately' |
API#
useColorWheelState(
(props: ColorWheelProps
)): ColorWheelState
Interface#
Properties
| Name | Type | Description |
value | Color | The current color value represented by the color wheel. |
defaultValue | Color | The default color value. |
hue | number | The current value of the hue channel displayed by the color wheel. |
isDragging | boolean | Whether the color wheel is currently being dragged. |
step | number | The step value of the hue channel, used when incrementing and decrementing. |
pageStep | number | The page step value of the hue channel, used when incrementing and decrementing. |
isDisabled | boolean | Whether the color wheel is disabled. |
Methods
| Method | Description |
setValue(
(value: string
| | Color
)): void | Sets the color value represented by the color wheel, and triggers onChange. |
setHue(
(value: number
)): void | Sets the hue channel of the current color value and triggers onChange. |
setHueFromPoint(
x: number,
y: number,
radius: number
): void | Sets the hue channel of the current color value based on the given coordinates and radius of the color wheel, and triggers onChange. |
getThumbPosition(
(radius: number
)): {} | Returns the coordinates of the thumb relative to the center point of the color wheel. |
increment(
(stepSize?: number
)): void | Increments the hue by the given amount (defaults to 1). |
decrement(
(stepSize?: number
)): void | Decrements the hue by the given amount (defaults to 1). |
setDragging(
(value: boolean
)): void | Sets whether the color wheel is being dragged. |
getDisplayColor(): Color | Returns the color that should be displayed in the color wheel instead of value. |
Example#
See the docs for useColorWheel in react-aria for an example of useColorWheelState.