Allows users to select from a pallete 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.

customAttributesobject

Custom attributes for the component.

customClassesstring | Array | object

Custom classes for the component.

i18nobject

Translated strings for the UI.

idstring

The ID for the component.

labelAttributesobject

Custom attributes to apply to the label for each swatch.

namestring

The name of the component.

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' ] } />
);

Methods

(inner) handleColorChange(event) → {void}

Handler for the color change event.

Parameters:
NameTypeDescription
eventobject

Event object.

Since
  • 1.1.15
Returns:
Type: 
void

(inner) handlePickerCancel() → {void}

Handler for the cancel event on the swatch.

Since
  • 1.1.15
Returns:
Type: 
void

(inner) handlePickerDelete(index) → {void}

Handler for the delete event on the swatch.

Parameters:
NameTypeDescription
indexnumber

Index of the swatch palette.

Since
  • 1.1.15
Returns:
Type: 
void

(inner) handlePickerSave(swatch) → {void}

Handler for the save event on the swatch.

Parameters:
NameTypeDescription
swatchstring

The swatch value.

Since
  • 1.1.15
Returns:
Type: 
void

(inner) renderAddNewSwatchOption() → {JSX.Element}

Render the add new swatch option.

Since
  • 1.1.15
Returns:

The add new swatch option.

Type: 
JSX.Element

(inner) renderSwatchOption(swatch, index, isCustom) → {JSX.Element}

Render the swatch option.

Parameters:
NameTypeDescription
swatchstring

The swatch value.

indexnumber

The index of the swatch palette.

isCustomboolean

Whether the swatch is custom or not.

Since
  • 1.1.15
Returns:

The swatch option.

Type: 
JSX.Element