Introducing PrimeReact v11-alpha 🎉Discover Now

InputColor

InputColor is a component that allows the user to select a color.

preview

Installation#

npx shadcn@latest add @primereact/inputcolor

Usage#

import { InputColor, InputColorArea, InputColorEyeDropper, InputColorInput, InputColorSlider, InputColorSwatch } from '@/components/ui/inputcolor';
<InputColor>
    <InputColorArea />
    <InputColorSlider />
    <InputColorSlider channel="alpha" />
    <InputColorSwatch />
    <InputColorInput channel="hex" />
    <InputColorEyeDropper />
</InputColor>

Examples#

Basic#

Use the format prop to change the color space. The channel prop of InputColor.Slider and InputColor.Input can be used to select the channel to control.

basic-demo

Vertical Slider#

Use the orientation prop to change the orientation of the slider.

vertical-slider-demo

Controlled#

Use the value and onColorChange props to control the color.

onValueChange: #000000
onValueChangeEnd: #000000
controlled-demo

Advanced#

CSS
advanced-demo

colorManager#

Color class#

The Color class is the base class for all color classes. It provides the basic functionality for all color classes.

  • clone(): Clones the color.
  • toString(format): Converts the color to a string.
  • toFormat(format): Converts the color to a specific format.
  • toJSON(): Converts the color to a JSON object.
  • getChannelRange(channel): Returns the range of the channel.
  • getFormat(): Returns the format of the color.
  • getChannels(): Returns the channels of the color.
  • getChannelValue(channel): Returns the value of the channel.
  • getColorAxes(xyChannels): Returns the axes of the color.
  • incChannelValue(channel, step): Increments the value of the channel by the step.
  • decChannelValue(channel, step): Decrements the value of the channel by the step.
  • withChannelValue(channel, value): Returns a new color with the value of the channel changed.

Accessibility#

InputColorArea#

Screen Reader Support#

aria-label is used to describe the component. aria-roledescription is used to describe the role of the component. aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext are used to describe the value of the component.

Keyboard Support#

KeyFunction
tabMoves focus to the area thumb.
right arrowMoves the area thumb to the right.
left arrowMoves the area thumb to the left.
up arrowMoves the area thumb to the up.
down arrowMoves the area thumb to the down.

InputColorSlider#

Screen Reader Support#

aria-label is used to describe the component. aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext are used to describe the value of the component.

Keyboard Support#

KeyFunction
tabMoves focus to the slider thumb.
up arrow || left arrowDecrements the slider thumb.
down arrow || right arrowIncrements the slider thumb.