跳到主要内容
版本:4.x

Color entry

简介

颜色条目(ColorEntry)允许你使用 CSS 颜色定义展示颜色预览,通常使用拾色器(ColoPicker)字段获得。颜色支持的格式有(HEX、HSL、RGB、RGBA)。

use Filament\Infolists\Components\ColorEntry;

ColorEntry::make('color')
Color entry

允许将颜色复制到剪切板

你可以让颜色可复制(copyable),比如在预览上单击将 CSS 值复制到剪切板,且可选地指定自定义确认消息及时长(以毫秒计)。该特性只有在应用启用 SSL 时有效:

use Filament\Infolists\Components\ColorEntry;

ColorEntry::make('color')
->copyable()
->copyMessage('Copied!')
->copyMessageDuration(1500)
Color entry with a button to copy it

此外,你也可以传入一个布尔值,控制颜色是否可复制:

use Filament\Infolists\Components\ColorEntry;

ColorEntry::make('color')
->copyable(FeatureFlag::active())
除了允许静态值之外,copyable()copyMessage()copyMessageDuration() 方法也接受函数以动态计算它们的值。你可以将各种 utility 作为参数注入到这些函数中。Learn more about utility injection.
UtilityTypeParameterDescription
EntryFilament\Infolists\Components\Entry$componentThe current entry component instance.
Get functionFilament\Schemas\Components\Utilities\Get$getA function for retrieving values from the current schema data. Validation is not run on form fields.
LivewireLivewire\Component$livewireThe Livewire component instance.
Eloquent model FQN?string<Illuminate\Database\Eloquent\Model>$modelThe Eloquent model FQN for the current schema.
Operationstring$operationThe current operation being performed by the schema. Usually <code>create</code>, <code>edit</code>, or <code>view</code>.
Eloquent record?Illuminate\Database\Eloquent\Model$recordThe Eloquent record for the current schema.
Statemixed$stateThe current value of the entry.