gboquizo/filament-rating-field

此包已被弃用且不再维护。未建议替代包。

用于 Filament 表单的评分字段

1.0.0 2023-11-15 23:20 UTC

This package is auto-updated.

Last update: 2024-01-30 19:12:29 UTC


README

Rating

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

安装

您可以通过 composer 安装此包

composer require gboquizo/filament-rating-field

可选地,您可以使用以下方法发布视图

php artisan vendor:publish --tag="filament-rating-field-views"

使用方法

表单字段

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
            ...
        ];
    }
...
Rating

默认情况下,范围值从 1 到 5,显示的图标为 heroicon-o-star

评分字段提供了多种选项来自定义其行为。以下是一些常用的选项:

禁用

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->disabled()
            ...
        ];
    }
...
Rating

最小值和最大值

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->min(5)
                ->max(10)
            ...
        ];
    }
...
Rating

自定义图标和颜色

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->icons('heroicon-o-moon', 'heroicon-s-sun')
                ->color('orange')
            ...
        ];
    }
...
Rating

自定义大小

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->size(10)
            ...
        ];
    }
...
Rating

无鼠标效果

禁用鼠标进入和离开的动画。

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->effects(false)
            ...
        ];
    }
...

可清除

允许用户清除评分选择。

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->clearable()
                ->clearIconColor('red')
                ->clearIconTooltip('Clear')
            ...
        ];
    }
...
Rating

光标

光标值基于 Tailwind 光标。前缀 cursor- 在值中不是必需的。

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->cursor('default')
                ->clearIconTooltip('none')
            ...
        ];
    }
...

工具提示

use Boquizo\Filament\Forms\Components\Rating

...
    protected function getFormSchema(): array
    {
        return [
            ...
            Rating::make('rating')
                ->options([
                    'Acceptable',
                    'Good',
                    'Very Good',
                    'Excellent',
                ])
            ...
        ];
    }
...
Rating

字段选项。

  • ->color(): 设置评分字段的图标颜色。
  • ->disabledColor(): 设置字段禁用时的图标颜色。
  • ->clearIconColor(): 设置清除图标的颜色。
  • ->icon(): 设置默认项的图标。
  • ->selectedIcon(): 设置选中项的实心图标。
  • ->clearIcon(): 设置清除操作的图标。
  • ->min(): 设置评分字段的最小值。默认:1
  • ->max(): 设置评分字段的最高值。默认:5
  • ->width(): 设置字段中每个项目的宽度值:默认:6
  • ->height(): 设置字段中每个项目的高度值:默认:6
  • ->size(): 设置宽度和高度属性相同的值。
  • ->effects(): 启用/禁用鼠标进入和离开的效果。默认:true (启用)
  • ->clearable(): 在评分图标末尾添加一个额外的图标。默认:false
  • ->cursor(): 设置默认光标
  • ->disabledCursor(): 设置字段禁用时显示的光标
  • ->clearIconTooltip(): 设置清除图标的工具提示。

您可以在类 App\Forms\Components\Rating 中查看上述选项和其他选项的默认值。

表格列

use Boquizo\Filament\Tables\Components\RatingColumn;

// ...
protected function getTableColumns(): array 
{
    return [
        // ..
        RatingColumn::make('rating'),
        // ..
    ];
}
...

评分列选项。

  • RatingColumn::make('rating')->color() 设置评分字段的图标颜色。
  • RatingColumn::make('rating')->icon() 设置默认项的图标。
  • RatingColumn::make('rating')->selectedIcon() 设置选中项的实心图标。
  • RatingColumn::make('rating')->icons() 设置默认项和选中项的图标。
  • RatingColumn::make('rating')->minValue() 设置评分字段的最低值。默认:1
  • RatingColumn::make('rating')->maxValue() 设置评分字段的最高值。默认:5
  • RatingColumn::make('rating')->size() 设置字段中每个项的宽度:默认:6
  • RatingColumn::make('rating')->height() 设置字段中每个项的高度:默认:6
  • RatingColumn::make('rating')->size() 设置宽度和高度属性相同的值。
  • RatingColumn::make('rating')->options() 设置工具提示

filament-page-with-sidebar

测试

composer test

更新日志

请参阅更新日志了解最近的变化。

贡献

请参阅贡献指南获取详细信息。

安全漏洞

请查看我们的安全策略了解如何报告安全漏洞。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件获取更多信息。