You can install the package via composer:
composer require yepsua/filament-rating-field
Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-rating-field-views"
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
...
];
}
...
By default the range values goes from 1 to 5 and the icon displayed is heroicon-o-star
The rating fields provides several option to customize its behavior. Next some of the more used for:
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->disabled()
...
];
}
...
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->min(5)
->max(10)
...
];
}
...
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->icons('heroicon-o-moon', 'heroicon-s-sun')
->color('orange')
...
];
}
...
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->size(10)
...
];
}
...
Disable the mouseenter and mouseleave animation.
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->effects(false)
...
];
}
...
Allow the user to clear the rating selection.
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->clearable()
->clearIconColor('red')
->clearIconTooltip('Clear')
...
];
}
...
The value of the cursor is based on the Tailwind cursor. The prefix cursor-
its not required in the value.
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->cursor('default')
->clearIconTooltip('none')
...
];
}
...
use Yepsua\Filament\Forms\Components\Rating
...
protected function getFormSchema(): array
{
return [
...
Rating::make('rating')
->options([
'Acceptable',
'Good',
'Very Good',
'Excellent',
])
...
];
}
...
- ->color(): Set the icon colors for the rating field.
- ->disabledColor(): Set the icon color when the field is disabled.
- ->clearIconColor(): Set the color for the clear icon.
- ->icon(): Set the icon for the default items.
- ->selectedIcon(): Set the solid icon for the selected items.
- ->clearIcon(): Set the icon for the clear action.
- ->min(): Set the min value for the rating field. Default: 1
- ->max(): Set the max value for the rating field. Default: 5
- ->width(): Set the width value for each item in the field: Default: 6
- ->height(): Set the height value for each item in the field: Default: 6
- ->size(): Set the same value for the width and height properties.
- ->effects(): Enable\Disable the mouseenter and mouseleave effects. Default: true (enabled)
- ->clearable(): Add a extra icon at the end of the rating icons. Default: false
- ->cursor(): Set the default cursor
- ->disabledCursor(): Set the cursor to be displayed when the field is disabled
- ->clearIconTooltip(): Set the tooltip for the clear icon.
You can review the default value for the options above and others in the class App\Forms\Components\Rating
use Yepsua\Filament\Tables\Components\RatingColumn;
// ...
protected function getTableColumns(): array
{
return [
// ..
RatingColumn::make('rating'),
// ..
];
}
...
RatingColumn::make('rating')->color()
Set the icon colors for the rating field.RatingColumn::make('rating')->icon()
Set the icon for the default items.RatingColumn::make('rating')->selectedIcon()
Set the solid icon for the selected items.RatingColumn::make('rating')->icons()
Set the icons for the default items and for selected items.RatingColumn::make('rating')->minValue()
Set the min value for the rating field. Default: 1RatingColumn::make('rating')->maxValue()
Set the max value for the rating field. Default: 5RatingColumn::make('rating')->width()
Set the width value for each item in the field: Default: 6RatingColumn::make('rating')->height()
Set the height value for each item in the field: Default: 6RatingColumn::make('rating')->size()
Set the same value for the width and height properties.RatingColumn::make('rating')->options()
set tooltip
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.