Renders a swatch component with id wrapper, allows users to select from a palette of swatches, or add their own using a color picker.

Parameters:
NameTypeDescription
propsobject

Component props.

Properties
NameTypeDescription
allowNewboolean

Whether to display an icon to add new swatches to the palette.

colorPickerAttributesobject

Custom attributes for the color picker.

colorPickerClassesstring | Array | object

Custom classes for the color picker.

controlledboolean

Whether the component is controlled or not.

customAttributesobject

Custom attributes for the component.

customClassesstring | Array | object

Custom classes for the component.

i18nobject

Translated strings for the UI.

iconPrefixstring

The prefix for which icon kit to use.

idstring

The ID for the component.

namestring

The name of the component.

onChangefunction

Callback function when the swatch value changes.

paletteArray

An array of hex color values to display as default palette options.

paletteCustomArray

An array of hex color values to display as custom/editable palette options.

spacingstring | number | Array | object

The spacing for the component, as a string, number, array, or object.

valuestring

The initial hex value to select.

refobject | null

Ref to the component.

Since
  • 1.1.15
Returns:

The Swatch component.

Type: 
JSX.Element
Example
import Swatch from '@gravityforms/components/react/admin/modules/Swatch';

return (
    <Swatch customClasses={ [ 'example-class' ] } palette={ [ '#000', '#111' ] } />
);