visualbuilder/filament-lottie
Add Lottie animations to Filament 5 panels via a schema component and a Blade component. Bundles @lottiefiles/dotlottie-wc, auto-registers assets (optional), supports defaults via config/plugin, and offers autoplay/loop/speed/size/triggers and reduced-motion support.
Installation:
composer require visualbuilder/filament-lottie
This auto-registers the package’s JS/CSS assets globally. Disable via config('lottie.auto_register_assets', false) if needed.
First Use Case:
use Visualbuilder\Lottie\Components\Lottie;
Lottie::make('welcome')
->src('lottie/welcome.lottie') // Path to your Lottie JSON file
->size('100px');
<x-lottie src="lottie/welcome.lottie" size="100px" />
Asset Placement:
public/lottie/ (or a subdirectory like public/animations/).lottie/welcome.lottie).Dynamic Animations in Forms/Resources:
Lottie in schema() for visual feedback (e.g., success/error states):
Lottie::make('success')
->src('lottie/success.lottie')
->trigger('visible') // Play when element enters viewport
->onComplete('event:animation-finished');
->trigger('event:custom-event-name'); // Triggers on Livewire event dispatch
Panel-Level Defaults:
->plugins([
LottiePlugin::make()
->defaultSize('60px')
->defaultLoop(true),
]);
Blade Integration:
<x-lottie
src="lottie/loading.lottie"
autoplay
loop
size="80px"
trigger="click"
/>
Conditional Rendering:
Lottie::make('conditional-animation')
->src(fn ($record) => $record->is_active ? 'lottie/active.lottie' : 'lottie/inactive.lottie')
->visible(fn ($record) => $record->has_animation);
app.blade.php:
@if(config('lottie.auto_register_assets'))
@preload('lottie/welcome.lottie')
@endif
resources/css/filament/lottie.css:
.lottie-container {
filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.3));
}
->autoplay(false)
->trigger('visible');
respectReducedMotion() to comply with user preferences.Asset Paths:
src() paths are relative to the root of the public folder.
Fix: Use absolute paths (e.g., lottie/animations/welcome.lottie) or ensure files are in public/lottie/..lottie files.Trigger Timing:
trigger('mount') may not work in nested Livewire components.
Fix: Use trigger('visible') or trigger('event:custom-event') with explicit dispatches.Reduced Motion:
respectReducedMotion(true).
Fix: Test with prefers-reduced-motion: reduce in browser dev tools or use ->respectReducedMotion(false) for testing.Livewire Events:
onComplete events may not fire if the component unmounts.
Fix: Use wire:ignore on the container or handle cleanup in mount()/updated().Console Logs:
config/lottie.php:
'debug' => env('APP_DEBUG', false),
Failed to load Lottie file.Common Errors:
Uncaught ReferenceError: DotLottiePlayer is not defined:
Ensure assets are registered (check resources/dist/lottie.js exists).autoplay and trigger settings. Test with trigger('click') manually.Custom Triggers:
trigger method by publishing the config and adding new trigger handlers in resources/js/lottie.js:
DotLottiePlayer.registerTrigger('custom', (player) => {
// Custom logic (e.g., listen to a Livewire event)
});
Dynamic Sources:
src getter in a custom component:
class DynamicLottie extends Lottie {
public function src(): string {
return "lottie/{$this->getKey()}.lottie";
}
}
Server-Side Rendering (SSR):
if (!app()->environment('ssr')) {
Lottie::make('animation')->src('...');
}
Local Development:
ln -s /path/to/local/lottie.json public/lottie/
How can I help you explore Laravel packages today?