Languages

Version

Theme

信息列表

Icon entry

简介

图标条目(IconEntry)用于渲染表示该 Entry 状态的图标

use Filament\Infolists\Components\IconEntry;
use Filament\Support\Icons\Heroicon;

IconEntry::make('status')
    ->icon(fn (string $state): string => match ($state) {
        'draft' => Heroicon::OutlinedPencil,
        'reviewing' => Heroicon::OutlinedClock,
        'published' => Heroicon::OutlinedCheckCircle,
    })
icon() 方法可以将多个 utility 作为参数注入到该函数中。 Learn more about utility injection.
Utility Type Parameter Description
Entry Filament\Infolists\Components\Entry $component The current entry component instance.
Get function Filament\Schemas\Components\Utilities\Get $get A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current schema.
Operation string $operation The current operation being performed by the schema. Usually create, edit, or view.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current schema.
State mixed $state The current value of the entry.
Icon entry

自定义颜色

使用 color() 方法,你可以修改图标的颜色

use Filament\Infolists\Components\IconEntry;

IconEntry::make('status')
    ->color('success')

通过传入函数到 color(),你可以基于 Entry 状态自定义颜色:

use Filament\Infolists\Components\IconEntry;

IconEntry::make('status')
    ->color(fn (string $state): string => match ($state) {
        'draft' => 'info',
        'reviewing' => 'warning',
        'published' => 'success',
        default => 'gray',
    })
color() 方法可以将多个 utility 作为参数注入到该函数中。 Learn more about utility injection.
Utility Type Parameter Description
Entry Filament\Infolists\Components\Entry $component The current entry component instance.
Get function Filament\Schemas\Components\Utilities\Get $get A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current schema.
Operation string $operation The current operation being performed by the schema. Usually create, edit, or view.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current schema.
State mixed $state The current value of the entry.
Icon entry with color

Customizing the size

The default icon size is IconSize::Large, but you may customize the size to be either IconSize::ExtraSmall, IconSize::Small, IconSize::Medium, IconSize::ExtraLarge or IconSize::TwoExtraLarge:

use Filament\Infolists\Components\IconEntry;
use Filament\Support\Enums\IconSize;

IconEntry::make('status')
    ->size(IconSize::Medium)
除了允许静态值之外,size() 方法也接受一个函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。 Learn more about utility injection.
Utility Type Parameter Description
Entry Filament\Infolists\Components\Entry $component The current entry component instance.
Get function Filament\Schemas\Components\Utilities\Get $get A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current schema.
Operation string $operation The current operation being performed by the schema. Usually create, edit, or view.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current schema.
State mixed $state The current value of the entry.
Medium-sized icon entry

处理布尔值

使用 boolean() 方法,图标条目可以基于 Entry 状态的 true 或者 false 显示打勾或者 “X” 图标:

use Filament\Infolists\Components\IconEntry;

IconEntry::make('is_featured')
    ->boolean()

如果模型类中的该属性已经强制转换成 bool 或者 boolean,Filament 可以检测到,你不用手动使用 boolean()

Icon entry to display a boolean

Optionally, you may pass a boolean value to control if the icon should be boolean or not:

use Filament\Infolists\Components\IconEntry;

IconEntry::make('is_featured')
    ->boolean(FeatureFlag::active())
除了允许静态值之外,boolean() 方法也接受一个函数来动态计算其值。你可以将多个 utility 作为参数注入到该函数中。 Learn more about utility injection.
Utility Type Parameter Description
Entry Filament\Infolists\Components\Entry $component The current entry component instance.
Get function Filament\Schemas\Components\Utilities\Get $get A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current schema.
Operation string $operation The current operation being performed by the schema. Usually create, edit, or view.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current schema.
State mixed $state The current value of the entry.

自定义布尔值图标

你可以自定义表示每个状态的图标

use Filament\Infolists\Components\IconEntry;
use Filament\Support\Icons\Heroicon;

IconEntry::make('is_featured')
    ->boolean()
    ->trueIcon(Heroicon::OutlinedCheckBadge)
    ->falseIcon(Heroicon::OutlinedXMark)
除了允许静态值之外,trueIcon()falseIcon() 方法也接受通过函数来动态计算它们的值。你可以将多个 utility 作为参数注入到这些函数中。 Learn more about utility injection.
Utility Type Parameter Description
Entry Filament\Infolists\Components\Entry $component The current entry component instance.
Get function Filament\Schemas\Components\Utilities\Get $get A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current schema.
Operation string $operation The current operation being performed by the schema. Usually create, edit, or view.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current schema.
State mixed $state The current value of the entry.
Icon entry to display a boolean with custom icons

自定义布尔值颜色

你可以自定义表示每个状态的图标颜色

use Filament\Infolists\Components\IconEntry;

IconEntry::make('is_featured')
    ->boolean()
    ->trueColor('info')
    ->falseColor('warning')
除了允许静态值之外,trueColor()falseColor() 方法也接受函数以动态计算它们的值。你可以将多个 utility 作为参数注入到这些函数中。 Learn more about utility injection.
Utility Type Parameter Description
Entry Filament\Infolists\Components\Entry $component The current entry component instance.
Get function Filament\Schemas\Components\Utilities\Get $get A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current schema.
Operation string $operation The current operation being performed by the schema. Usually create, edit, or view.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current schema.
State mixed $state The current value of the entry.
Icon entry to display a boolean with custom colors
Edit on GitHub

Still need help? Join our Discord community or open a GitHub discussion

Previous
Text entry