- How do I install Wire Elements Spotlight in a Laravel Livewire project?
- Run `composer require wire-elements/spotlight` and add `@livewire('livewire-ui-spotlight')` to your Blade layout. For Livewire v2, include Alpine.js via CDN or bundle. No migrations or complex setup are required.
- Does Spotlight work with Livewire v3?
- Yes, Spotlight is fully compatible with Livewire v3. Alpine.js is no longer required since Livewire v3 includes it natively. Just install the package and use the `@livewire` directive as usual.
- Can I customize the keyboard shortcuts for Spotlight?
- Yes, you can configure the keybindings in the package’s config file. Defaults include CMD/CTRL+K and CMD/CTRL+/, but you can override them to match your app’s workflow.
- How do I programmatically trigger Spotlight from a Livewire component?
- Use `$this->dispatchBrowserEvent('toggle-spotlight')` in Livewire v2 or `$this->dispatch('toggle-spotlight')` in Livewire v3. You can also trigger it via JavaScript using `window.Livewire.dispatch('toggle-spotlight')`.
- Is Spotlight compatible with Laravel 8+ and Livewire v2?
- Yes, Spotlight supports Laravel 8+ and Livewire v2, but Livewire v3 is recommended. For Livewire v2, ensure Alpine.js is included, either via CDN or your asset pipeline.
- How can I add custom commands to Spotlight?
- Extend the `SpotlightCommand` class and register your custom commands in the `SpotlightServiceProvider`. Override methods like `shouldBeShown()` for role-based visibility or `handle()` for custom logic.
- Will Spotlight work with non-TailwindCSS Laravel apps?
- Yes, Spotlight is Tailwind-centric by default but can be customized. Set `include_css: true` in the config or publish the views to override the default styles with your own CSS.
- Are there performance concerns with Spotlight in large applications?
- Spotlight is lightweight, but heavy command lists may impact performance. Optimize by lazy-loading commands or paginating search results. Test frequently toggled scenarios to ensure smooth UI responsiveness.
- Can I restrict Spotlight commands based on user roles?
- Yes, use the `shouldBeShown()` method in your custom commands to check Laravel’s Gates, Policies, or user roles. This dynamically hides/shows commands based on authentication and authorization.
- What happens if a Spotlight command fails (e.g., validation errors)?
- Failed commands can be handled by overriding the `handle()` method in your custom command class. Use Laravel’s validation or exception handling to provide feedback, like showing toast notifications or error messages.