Color Picker

import ColorPicker from 'frui/field/Color;
Copy

Props

NameTypeRequiredNotes
valuestringNoCurrent color (hex, rgba). If undefined, component is uncontrolled.
defaultValuestringNoInitial color if `value` is undefined (uncontrolled).
onChangefunctionNoCallback `(color: string) => void` returning rgba string.
showAlphabooleanNo (true)Show alpha slider and input.
showInputsbooleanNo (true)Show RGBA input fields.
swatchesstring[]NoArray of hex/rgba colors for swatches.
pickerStyleCSS ObjectNoCustom CSS for the picker popover element.
pickerClassNamestringNoCustom class name for the picker popover element.
classNamestringNoClass names for the main wrapper div.
styleCSS ObjectNoInline styles for the main wrapper div.
boxbooleanNo (true)Show color preview box in display.
textbooleanNo (true)Show color text value in display.
lgbooleanNoUse large size for display.
mdbooleanNoUse medium size for display.
smbooleanNoUse small size for display.

Basic Usage (Controlled)

Provide value and onChange props for a controlled component. The component expects hex or rgba strings as input and outputs an rgba string.

Selected: rgba(74, 144, 226, 1)
<ColorPicker
  value={color}
  onChange={newRgbaColor => setColor(newRgbaColor)}
/>
Copy

Uncontrolled Usage

Omit the value prop to use the component in uncontrolled mode. You can set an initial color with defaultValue. Use a ref or form submission to get the final value if needed, or use onChange just to react to changes.

Default: rgba(245, 166, 35, 1)
<ColorPicker
  defaultValue="rgba(245, 166, 35, 1)"
  onChange={newColor => console.log(newColor)}
/>
Copy

Customization

Customize the picker's features like alpha, inputs, and swatches.

No Alpha
No Inputs
Custom Swatches
Default Swatches
<ColorPicker value={color} onChange={setColor} showAlpha={false} />

<ColorPicker value={color} onChange={setColor} showInputs={false} />

<ColorPicker
  value={color}
  onChange={setColor}
  swatches={['#FF6B6B', '#4ECDC4', 'rgba(69, 183, 209, 0.7)', '#F7B801', '#5F4B8B']}
/>

const defaultSwatches = ['#D0021B'];
<ColorPicker value={color} onChange={setColor} swatches={defaultSwatches} />
Copy

Layout & Style

Adjust the trigger display using sm, md, lg, box={false}, or text={false}. Use className or style for the wrapper, and pickerClassName, or pickerStyle for the popover.

Large / No Text
Small / No Box
Custom Popover Class
Custom Popover Style
<ColorPicker value={color} onChange={setColor} lg text={false} />

<ColorPicker value={color} onChange={setColor} sm box={false} />

<ColorPicker value={color} onChange={setColor} pickerClassName="custom-popover" />

<ColorPicker
  value={color}
  onChange={setColor}
  pickerStyle={{ background: '#f0f0f0', width: '280px' }}
/>
Copy