Introducing PrimeReact v11-alpha 🎉Discover Now

InputColor

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

preview

Usage#

import { InputColor } from '@primereact/ui/inputcolor';
<InputColor.Root>
    <InputColor.Area>
        <InputColor.AreaBackground />
        <InputColor.AreaThumb />
    </InputColor.Area>
    <InputColor.Slider>
        <InputColor.TransparencyGrid />
        <InputColor.SliderTrack />
        <InputColor.SliderThumb />
    </InputColor.Slider>
    <InputColor.Swatch>
        <InputColor.TransparencyGrid />
        <InputColor.SwatchBackground />
    </InputColor.Swatch>
    <InputColor.EyeDropper>
        <EyeDropperIcon />
    </InputColor.EyeDropper>
    <InputColor.Input />
</InputColor.Root>

Examples#

Basic#

Select a color via a visual picker interface.

basic-demo

With Popover#

Use the InputColor inside a Popover to put the InputColor to the top of the component.

popover-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.

API#

Sub-Components#

See Primitive API for sub-component props, state, exposes, and data attributes.

Hooks#

See Headless API for the useInputColor hook interface.

Accessibility#

See InputColor Primitive for WAI-ARIA compliance details and keyboard support.