Installation:
composer require awcodes/palette
Ensure your Filament version matches the package compatibility table (e.g., 3.x for Filament 5.x).
Theme Integration: Add the package’s Blade views to your custom theme’s CSS file:
@source '../../../../vendor/awcodes/palette/resources/**/*.blade.php';
Note: Required for standalone Filament or if not using a custom theme.
First Use Case: Register the field in a Filament form:
use Awcodes\Palette\Fields\PaletteField;
PaletteField::make('color')
->presets(['#FF5733', '#33FF57', '#3357FF']) // Default presets
->default('#FFFFFF'); // Optional default
Dynamic Presets: Fetch presets from a database or API:
PaletteField::make('accent_color')
->presets(fn () => $this->getCustomPaletteColors())
->livewire(); // For real-time updates
Theming Integration: Extend Filament’s theme with palette-specific styles:
/* app/filament/resources/css/filament.css */
.palette-field .palette-swatch {
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
Validation & Rules: Combine with Filament’s validation:
PaletteField::make('primary_color')
->presets(['#1DA1F2', '#170939'])
->rules(['required', 'hex_color']);
Panel-Specific Configuration: Override presets per panel:
// In a custom Filament panel
PaletteField::make('theme_color')
->presets(['#000000', '#FFFFFF', '#FF4500']);
PaletteField::make('brand_color')
->presets([
'#FF0000' => __('Red'),
'#00FF00' => __('Green'),
]);
PaletteField::make('custom_palette')
->presets(fn () => $this->loadPaletteFromCache());
Theme Dependency:
@source in CSS causes blank fields.resources/css/filament.css or your custom theme file.Preset Overrides:
->livewire() or clear Filament’s cache:
php artisan filament:cache-clear
Hex Validation:
#F00).use Awcodes\Palette\Fields\PaletteField;
PaletteField::make('hex_color')
->rules(['hex_color', 'size:7']); // Enforce full #RRGGBB
Filament Version Mismatch:
ClassNotFound errors.dd($this->form->getField('palette_field')->getView());
// config/filament.php
'debug' => env('FILAMENT_DEBUG', false),
Custom Swatch Rendering: Override the swatch template:
<!-- resources/views/vendor/filament/forms/components/field.blade.php -->
@if($field instanceof \Awcodes\Palette\Fields\PaletteField)
<div class="custom-swatch">{{ $field->getColorPreview($state) }}</div>
@endif
Preset Management: Add a palette editor panel:
use Awcodes\Palette\Resources\PaletteResource;
PaletteResource::make()
->columns(['name', 'colors'])
->pages([]);
Dark Mode Support: Dynamically adjust swatch styles:
@media (prefers-color-scheme: dark) {
.palette-field .palette-swatch {
filter: brightness(0.9);
}
}
API Integration: Sync presets with an external service:
PaletteField::make('api_color')
->presets(fn () => $this->fetchFromApi('/palettes'))
->afterStateUpdated(fn ($state) => $this->syncToApi($state));
How can I help you explore Laravel packages today?