Skip to main content
ColorSwatchField ← Back to Table of Contents

Summary

Preset color picker: horizontal swatch pills with optional section header and tooltips.
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\ColorSwatchField
State typestring|null — selected color key (not hex)
FieldTypecolor_presets

Basic usage

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\ColorSwatchField;

ColorSwatchField::make('theme_color')
    ->colors([
        'indigo' => '#6366f1',
        'rose' => '#f43f5e',
        'emerald' => '#10b981',
    ])
    ->sectionLabel('Brand colors')
    ->tooltips(true);

ColorSwatchField::make('accent')
    ->colors(['primary' => '#3b82f6', 'white' => '#ffffff'])
    ->tooltips([
        'primary' => 'Primary blue',
        'white' => 'White',
    ])
    ->size('lg');

State format

Stores the array key from colors(), e.g. 'indigo', not #6366f1.

Validation

RuleDetail
nullableNo selection allowed
Rule::in(...)Key must exist in colors()

Configuration API

colors(array|Closure $colors)

Map of key => hex (or CSS color). Required for meaningful UI.
ColorSwatchField::make('field_name')
    ->colors(['value1', 'value2']);

sectionLabel(string|Closure|null $label)

Optional heading above swatches.
ColorSwatchField::make('field_name')
    ->sectionLabel('value');

sectionIcon(string|BackedEnum|Htmlable|Closure|null $icon)

Icon next to section label. When label is set and icon omitted, uses config color_swatch_section_icon or GravityIcon::Palette.
ColorSwatchField::make('field_name')
    ->sectionIcon('value');

tooltips(bool|array|Closure $tooltips = true)

true = auto labels from keys; false = no tooltips; array = per-key labels.
ColorSwatchField::make('field_name')
    ->tooltips(true);

size(string|ControlSize|Closure $size)

sm, md, lg. Default: md.
ColorSwatchField::make('field_name')
    ->size('md');

Public helper methods

MethodReturnsDescription
getColors()array<string, string>Key → color map
getSectionLabel()string|nullHeader text
getSectionIcon()string|BackedEnum|Htmlable|nullHeader icon
getDefaultSectionIcon()string|BackedEnum|HtmlableFallback icon
hasTooltips()boolTooltips enabled
getColorLabel(string $key)stringTooltip for key
isLightSwatch(string $hex)boolLight swatch (border adjustment)

FlexField schema config

Config keyMaps to
colorscolors()
section_labelsectionLabel()
section_iconsectionIcon()
sizesize()
tooltipstooltips()

CSS classes

ClassRole
fff-color-swatchRoot wrapper
fff-color-swatch--{sm|md|lg}Size modifier
fff-color-swatch__pillSwatch button
fff-color-swatch__pill--lightLight color border
fff-color-swatch__pill.is-selectedSelected state

Implementation notes

  • Keys are persisted; map to hex in your application layer or accessor.
  • isLightSwatch() detects white swatches for contrast borders.