useColorAreaState
Provides state management for a color area component. Color area allows users to adjust two channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.
| install | yarn add react-stately |
|---|---|
| version | 3.47.0 |
| usage | import {useColorAreaState} from 'react-stately' |
API#
useColorAreaState(
(props: ColorAreaProps
)): ColorAreaState
Interface#
Properties
| Name | Type | Description |
value | Color | The current color value displayed by the color area. |
defaultValue | Color | The default value of the color area. |
xValue | number | The current value of the horizontal axis channel displayed by the color area. |
yValue | number | The current value of the vertical axis channel displayed by the color area. |
isDragging | boolean | Whether the color area is currently being dragged. |
channels | {} | Returns the xChannel, yChannel and zChannel names based on the color value. |
xChannelStep | number | The step value of the xChannel, used when incrementing and decrementing. |
yChannelStep | number | The step value of the yChannel, used when incrementing and decrementing. |
xChannelPageStep | number | The page step value of the xChannel, used when incrementing and decrementing. |
yChannelPageStep | number | The page step value of the yChannel, used when incrementing and decrementing. |
Methods
| Method | Description |
setValue(
(value: string
| | Color
)): void | Sets the current color value. If a string is passed, it will be parsed to a Color. |
setXValue(
(value: number
)): void | Sets the value for the horizontal axis channel displayed by the color area, and triggers
|
setYValue(
(value: number
)): void | Sets the value for the vertical axis channel displayed by the color area, and triggers
|
setColorFromPoint(
(x: number,
, y: number
)): void | Sets the x and y channels of the current color value based on a percentage of the width and
height of the color area, and triggers |
getThumbPosition(): {} | Returns the coordinates of the thumb relative to the upper left corner of the color area as a percentage. |
incrementX(
(stepSize?: number
)): void | Increments the value of the horizontal axis channel by the channel step or page amount. |
decrementX(
(stepSize?: number
)): void | Decrements the value of the horizontal axis channel by the channel step or page amount. |
incrementY(
(stepSize?: number
)): void | Increments the value of the vertical axis channel by the channel step or page amount. |
decrementY(
(stepSize?: number
)): void | Decrements the value of the vertical axis channel by the channel step or page amount. |
setDragging(
(value: boolean
)): void | Sets whether the color area is being dragged. |
getDisplayColor(): Color | Returns the color that should be displayed in the color area thumb instead of value. |
Example#
See the docs for useColorArea in react-aria for an example of useColorAreaState.