Color PickernewNEW
A composable color picker component supporting multiple color models, alpha channel, and customizable UI.
Overview
The ColorPicker
component offers a flexible and composable solution for selecting colors in various formats, including HEX, RGB, and HSL. It supports optional alpha channel (transparency) and is designed for easy integration and customization within your application.
Getting Started
To use the ColorPicker
, import it from @raystack/apsara
and compose its subcomponents as needed. Below is a basic example:
ColorPicker Props
The ColorPicker
is composed of several subcomponents, each responsible for a specific aspect of color selection. The root component acts as a data provider for its children.
Prop | Type | Default |
---|---|---|
value | string | - |
defaultValue | string | '#ffffff' |
onValueChange | (value: string, mode: string) => void | - |
defaultMode | "hex" | "rgb" | "hsl" | 'hex' |
mode | "hex" | "rgb" | "hsl" | - |
onModeChange | (mode: string) => void | - |
ColorPicker.Area
Enables users to select a color from a palette. Typically used for choosing saturation and brightness.
ColorPicker.Hue
Provides a slider for selecting the hue value of the color.
ColorPicker.Alpha
Provides a slider for selecting the alpha value of the color.
ColorPicker.Mode
Lets users switch between different color models (e.g., HEX, RGB, HSL) via a dropdown menu.
Prop | Type | Default |
---|---|---|
options | ("hex" | "rgb" | "hsl")[] | ['hex', 'rgb', 'hsl'] |
ColorPicker.Input
Displays the current color value in the selected color model and allows direct text input.
Examples
Basic Usage
Popover Integration
The ColorPicker
can be embedded within a Popover
component to create a more interactive and space-efficient color selection experience.