An HEX value color picker.

Usage

The color picker primarily takes a CSS HEX string representing any color. Users can adjust the color by changing the saturation, value, or hue of the HEX value.

Inside the component, colors are represented in the HSV color space, as HEX color codes are lossy when it comes to, specifically, hue.

At this time, users can't directly input hue, saturation, value, or alpha values.

<ColorPicker color='#005719' onColorChange={(color) => console.log(color)} />

Clearing the color

By default, the color cannot be null and users can't clear the color value. When it makes sense, the color picker can allow the color to be cleared (with an x button in the HEX input) and set to null. To allow null and allow the color to be cleared in the HEX input, set isClearable to true.

import { ColorPicker } from '@customerio/pluma-components/react';
import { useState } from 'react';

export default function Example() {
  const [color, setColor] = useState('#005719');

  return (
    <ColorPicker
      color={color}
      onColorChange={(color) => {
        console.log(color);
        setColor(color);
      }}
      isClearable={true}
    />
  )
}

Disabling changes

When the color picker shouldn't accept any changes by the user, set isDisabled to true. Users will still be able to open the color picker, but won't be able to change the hue, saturation/value, or HEX values.

<ColorPicker
  color='#005719'
  onColorChange={(color) => console.log(color)}
  isDisabled={true}
/>

API

Default:125

The duration (in ms) for the popover animation.

The currently selected color. This component does not manage this state for you and you must manage the selected color yourself.

It should be a CSS HEX color value without an alpha channel.

Whether the popover should be open initially

Default:['content']

The order in which focus should be moved when navigating through the popover. See Floating UI for more details.

Default:0

Which element to initially focus when the popover is opened. Can be a number (a tabbable index as specified by focusOrder) or an HTMLElement. See Floating UI for more details.

Default:false

Whether to allow the user to clear the color or not. Defaults to false.

Default:false

Whether the color picker should be disabled. Defaults to false.

Default:false

Whether the popover should be draggable.

Default:false

Whether the focus manager (for the opened popover) should be disabled entirely. See Floating UI for more details.

Whether the popover should be open. Only use this along with onOpenChange if you want to control the state of the popover

middlewareOptions  { arrow?: Partial<{ padding?: Padding | undefined; element: Element; }> | ((state: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; }) => Partial<{ padding?: Padding | undefined; element: Element; }>) | undefined; offset?: Partial<{ mainAxis: number; crossAxis: number; alignmentAxis: number | null; }> | ((state: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; }) => Partial<{ mainAxis: number; crossAxis: number; alignmentAxis: number | null; }>) | undefined; flip?: { padding?: Padding | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; mainAxis?: boolean | undefined; crossAxis?: boolean | undefined; fallbackPlacements?: Placement[] | undefined; fallbackStrategy?: "initialPlacement" | "bestFit" | undefined; fallbackAxisSideDirection?: "none" | "end" | "start" | undefined; flipAlignment?: boolean | undefined; boundary?: Boundary | undefined; } | ((state: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; }) => { padding?: Padding | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; mainAxis?: boolean | undefined; crossAxis?: boolean | undefined; fallbackPlacements?: Placement[] | undefined; fallbackStrategy?: "initialPlacement" | "bestFit" | undefined; fallbackAxisSideDirection?: "none" | "end" | "start" | undefined; flipAlignment?: boolean | undefined; boundary?: Boundary | undefined; }) | undefined; shift?: { padding?: Padding | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; mainAxis?: boolean | undefined; crossAxis?: boolean | undefined; limiter?: { fn: (state: MiddlewareState) => Coords; options?: any; } | undefined; boundary?: Boundary | undefined; } | ((state: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; }) => { padding?: Padding | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; mainAxis?: boolean | undefined; crossAxis?: boolean | undefined; limiter?: { fn: (state: MiddlewareState) => Coords; options?: any; } | undefined; boundary?: Boundary | undefined; }) | undefined; hide?: { padding?: Padding | undefined; strategy?: "referenceHidden" | "escaped" | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; boundary?: Boundary | undefined; } | ((state: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; }) => { padding?: Padding | undefined; strategy?: "referenceHidden" | "escaped" | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; boundary?: Boundary | undefined; }) | undefined; size?: { padding?: Padding | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; boundary?: Boundary | undefined; apply?: ((args: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; } & { availableWidth: number; availableHeight: number; }) => Promisable<void>) | undefined; } | ((state: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; }) => { padding?: Padding | undefined; rootBoundary?: RootBoundary | undefined; elementContext?: ElementContext | undefined; altBoundary?: boolean | undefined; boundary?: Boundary | undefined; apply?: ((args: { x: number; y: number; placement: Placement; strategy: Strategy; initialPlacement: Placement; middlewareData: MiddlewareData; rects: ElementRects; platform: Platform; elements: Elements; } & { availableWidth: number; availableHeight: number; }) => Promisable<void>) | undefined; }) | undefined; } | undefined

Additional options to pass into Floating UI middleware

The function called when the user changes the color. Use this to update the current color state. If isClearable is set to true, the color passed into the function can be null

Where the popover should be placed in relation to the trigger

Default:true

Whether focusout event listeners are attached to the trigger and popover, to close the popover when focus moves outside of it. See Floating UI for more details.

Default:false

Whether the popover should navigate through a list of items when the arrow keys are pressed. See Floating UI for more details.

Default:true

Whether the focus guards are rendered by the focus manager. See Floating UI for more details.

Default:true

Whether the popover content's max width and/or max height should be restricted using the Floating UI size middleware.

By default, this is enabled, to prevent popovers from growing larger than the available viewport size.

Default:true

Whether focus should be returned to the trigger when the popover is closed. See Floating UI for more details.

Default:false

Whether visually hidden close buttons are rendered before and after the popover. See Floating UI for more details.

Default:false

If the popover contains interactive elements, the dialog pattern should be applied. Enable shouldTrapFocus to ensure focus is kept within the popover while it's open. See Floating UI for more details.

Default:true

Whether the popover should open when the trigger is clicked. This is the recommended default.

Default:false

Whether the popover should open when the trigger is focused. Defaults to true when shouldTriggerOnHover is true.

Default:false

Whether the popover should open when the trigger is hovered. Only use if absolutely necessary, as Popovers are meant to be triggered by clicks.

The position CSS property to use on the floating element

Additional classes to apply on the popover component (the floating element, not the trigger). Should only be used as a last resort

Additional classes to apply on the popover content component. Should only be used as a last resort

Additional inline styles to apply on the popover component (the floating element, not the trigger). Should only be used as a last resort

An internal function to pass the Floating UI nodeId up to a parent if necessary.

Default:false

Whether "typeahead" functionality should be enabled, which focuses items while typing. See Floating UI for more details. Enabled by default when shouldNavigateList is true.

On this page