To customize the styles of your Filament form to use DaisyUI classes instead of the default Filament/Tailwind classes, you can indeed use the extraInputAttributes method to add your custom classes. However, if you find that the default Filament classes are still being applied and are clashing with your custom styles, you may need to take additional steps to ensure your styles take precedence.
Here's a step-by-step solution to ensure your custom styles are applied:
-
Override Filament Styles: You can create a custom CSS file where you override the default Filament styles with your DaisyUI styles. Include this CSS file in your Livewire component's view.
-
Publish Filament Views: If you need more control over the markup, you can publish the Filament views to your resources folder and edit them directly. Run the following command to publish the views:
php artisan vendor:publish --tag=filament-views
After publishing, you can find the views in the resources/views/vendor/filament directory. You can then modify the Blade files to use your custom classes.
-
Use
extraInputAttributes: Continue using theextraInputAttributesmethod to add or override classes for individual form components. -
Remove Default Filament Classes: If you want to completely remove the default classes that Filament applies, you can extend the Filament form components and override the
getDefaultClassesmethod to return an empty array or your custom classes.
Here's an example of how you might extend a Filament form component:
namespace App\Filament\Forms\Components;
use Filament\Forms\Components\TextInput as FilamentTextInput;
class TextInput extends FilamentTextInput
{
protected function getDefaultClasses(): array
{
// Return an empty array to remove all default classes
// or return an array with your custom classes
return [];
}
}
Then, in your Livewire component, use your custom TextInput component instead of the one provided by Filament:
use App\Filament\Forms\Components\TextInput;
// ...
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('email')
->email()
->required()
->extraInputAttributes(['class' => 'input input-bordered']),
])
->columns(2)
->statePath('data');
}
- Customize the Livewire View: In your Livewire component's view, make sure to include your custom CSS file that contains the DaisyUI styles and any overrides for Filament's default styles.
{{-- livewire.form-test.blade.php --}}
@push('styles')
<link href="{{ asset('css/custom-filament-styles.css') }}" rel="stylesheet">
@endpush
<div>
{{ $this->form }}
</div>
By following these steps, you should be able to fully customize the styles of your Filament form within a Livewire component to match the rest of your application's DaisyUI styling.