Ce document n’est pas disponible en français (fr). La version en English (en) est affichée.
webkernel/platform-infolists
03-icon-entry
Sur cette page
title: Icon entry
Introduction
Icon entries render an icon representing the state of the entry:
use Webkernel\Platform\Infolists\Components\IconEntry;
use Webkernel\Platform\Support\Icons\Heroicon;
IconEntry::make('status')
->icon(fn (string $state): Heroicon => match ($state) {
'draft' => Heroicon::OutlinedPencil,
'reviewing' => Heroicon::OutlinedClock,
'published' => Heroicon::OutlinedCheckCircle,
})
<UtilityInjection set="infolistEntries" extras="Related record;;Webkernel\ORM\Model;;$relatedRecord;;The current related Eloquent record for the rendered item.">The icon() method can inject various utilities into the function as parameters.</UtilityInjection>
<AutoScreenshot name="infolists/entries/icon/simple" alt="Icon entry" />
Customizing the color
You may change the color of the icon, using the color() method:
use Webkernel\Platform\Infolists\Components\IconEntry;
IconEntry::make('status')
->color('success')
By passing a function to color(), you can customize the color based on the state of the entry:
use Webkernel\Platform\Infolists\Components\IconEntry;
IconEntry::make('status')
->color(fn (string $state): string => match ($state) {
'draft' => 'info',
'reviewing' => 'warning',
'published' => 'success',
default => 'gray',
})
<UtilityInjection set="infolistEntries" extras="Related record;;Webkernel\ORM\Model;;$relatedRecord;;The current related Eloquent record for the rendered item.">The color() method can inject various utilities into the function as parameters.</UtilityInjection>
<AutoScreenshot name="infolists/entries/icon/color" alt="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 Webkernel\Platform\Infolists\Components\IconEntry;
use Webkernel\Platform\Support\Enums\IconSize;
IconEntry::make('status')
->size(IconSize::Medium)
<UtilityInjection set="infolistEntries" extras="Related record;;Webkernel\ORM\Model;;$relatedRecord;;The current related Eloquent record for the rendered item.">As well as allowing a static value, the size() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
<AutoScreenshot name="infolists/entries/icon/medium" alt="Medium-sized icon entry" />
Handling booleans
Icon entries can display a check or "X" icon based on the state of the entry, either true or false, using the boolean() method:
use Webkernel\Platform\Infolists\Components\IconEntry;
IconEntry::make('is_featured')
->boolean()
If this attribute in the model class is already cast as a
boolorboolean, Platform is able to detect this, and you do not need to useboolean()manually.
<AutoScreenshot name="infolists/entries/icon/boolean" alt="Icon entry to display a boolean" />
Optionally, you may pass a boolean value to control if the icon should be boolean or not:
use Webkernel\Platform\Infolists\Components\IconEntry;
IconEntry::make('is_featured')
->boolean(FeatureFlag::active())
<UtilityInjection set="infolistEntries" extras="Related record;;Webkernel\ORM\Model;;$relatedRecord;;The current related Eloquent record for the rendered item.">As well as allowing a static value, the boolean() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
Customizing the boolean icons
You may customize the icon representing each state:
use Webkernel\Platform\Infolists\Components\IconEntry;
use Webkernel\Platform\Support\Icons\Heroicon;
IconEntry::make('is_featured')
->boolean()
->trueIcon(Heroicon::OutlinedCheckBadge)
->falseIcon(Heroicon::OutlinedXMark)
<UtilityInjection set="infolistEntries" extras="Related record;;Webkernel\ORM\Model;;$relatedRecord;;The current related Eloquent record for the rendered item.">As well as allowing static values, the trueIcon() and falseIcon() methods also accept functions to dynamically calculate them. You can inject various utilities into the functions as parameters.</UtilityInjection>
<AutoScreenshot name="infolists/entries/icon/boolean-icon" alt="Icon entry to display a boolean with custom icons" />
Customizing the boolean colors
You may customize the icon color representing each state:
use Webkernel\Platform\Infolists\Components\IconEntry;
IconEntry::make('is_featured')
->boolean()
->trueColor('info')
->falseColor('warning')
<UtilityInjection set="infolistEntries" extras="Related record;;Webkernel\ORM\Model;;$relatedRecord;;The current related Eloquent record for the rendered item.">As well as allowing static values, the trueColor() and falseColor() methods also accept functions to dynamically calculate them. You can inject various utilities into the functions as parameters.</UtilityInjection>
<AutoScreenshot name="infolists/entries/icon/boolean-color" alt="Icon entry to display a boolean with custom colors" />
