mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Support record action icons
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"/js/filament.js": "/js/filament.js?id=f6f25b9e29038b97ab02",
|
||||
"/css/filament.css": "/css/filament.css?id=4d7c9f792fd10c34ffea"
|
||||
"/css/filament.css": "/css/filament.css?id=6355038f8cb08d58efef"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
@if ($action = $recordAction->getAction($record))
|
||||
<button
|
||||
wire:click="{{ $action }}('{{ $record->getKey() }}')"
|
||||
type="button"
|
||||
class="font-medium transition-colors duration-200 text-primary-600 hover:text-primary-700"
|
||||
>
|
||||
<x-dynamic-component :component="$recordAction->getIcon()" class="w-4 h-4" />
|
||||
</button>
|
||||
@elseif ($url = $recordAction->getUrl($record))
|
||||
<a
|
||||
href="{{ $url }}"
|
||||
class="font-medium transition-colors duration-200 text-primary-600 hover:text-primary-700"
|
||||
@if ($recordAction->shouldOpenUrlInNewTab())
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
@endif
|
||||
>
|
||||
<x-dynamic-component :component="$recordAction->getIcon()" class="w-4 h-4" />
|
||||
</a>
|
||||
@else
|
||||
<span
|
||||
class="inline-flex items-center font-medium text-primary-600"
|
||||
>
|
||||
<x-dynamic-component :component="$recordAction->getIcon()" class="w-4 h-4" />
|
||||
</span>
|
||||
@endif
|
||||
@@ -2,21 +2,37 @@
|
||||
<button
|
||||
wire:click="{{ $action }}('{{ $record->getKey() }}')"
|
||||
type="button"
|
||||
class="font-medium transition-colors duration-200 text-primary-600 hover:underline hover:text-primary-700"
|
||||
class="inline-flex items-center font-medium transition-colors duration-200 text-primary-600 hover:underline hover:text-primary-700"
|
||||
>
|
||||
@if ($recordAction->hasIcon())
|
||||
<x-dynamic-component :component="$recordAction->getIcon()" class="w-4 h-4 mr-1" />
|
||||
@endif
|
||||
|
||||
{{ __($recordAction->getLabel()) }}
|
||||
</button>
|
||||
@elseif ($url = $recordAction->getUrl($record))
|
||||
<a
|
||||
href="{{ $url }}"
|
||||
class="font-medium transition-colors duration-200 text-primary-600 hover:underline hover:text-primary-700"
|
||||
class="inline-flex items-center font-medium transition-colors duration-200 text-primary-600 hover:underline hover:text-primary-700"
|
||||
@if ($recordAction->shouldOpenUrlInNewTab())
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
@endif
|
||||
>
|
||||
@if ($recordAction->hasIcon())
|
||||
<x-dynamic-component :component="$recordAction->getIcon()" class="w-4 h-4 mr-1" />
|
||||
@endif
|
||||
|
||||
{{ __($recordAction->getLabel()) }}
|
||||
</a>
|
||||
@else
|
||||
<span>{{ __($recordAction->getLabel()) }}</span>
|
||||
<span
|
||||
class="inline-flex items-center font-medium text-primary-600"
|
||||
>
|
||||
@if ($recordAction->hasIcon())
|
||||
<x-dynamic-component :component="$recordAction->getIcon()" class="w-4 h-4 mr-1" />
|
||||
@endif
|
||||
|
||||
{{ __($recordAction->getLabel()) }}
|
||||
</span>
|
||||
@endif
|
||||
|
||||
@@ -56,18 +56,6 @@ class Action
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel()
|
||||
{
|
||||
if ($this->label === null) {
|
||||
return (string) Str::of($this->getName())
|
||||
->kebab()
|
||||
->replace(['-', '_', '.'], ' ')
|
||||
->ucfirst();
|
||||
}
|
||||
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Tables\RecordActions;
|
||||
|
||||
class Icon extends Action
|
||||
{
|
||||
use Concerns\CanCallAction;
|
||||
use Concerns\CanOpenUrl;
|
||||
|
||||
protected $icon;
|
||||
|
||||
public function icon($icon)
|
||||
{
|
||||
$this->configure(function () use ($icon) {
|
||||
$this->icon = $icon;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIcon()
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
}
|
||||
@@ -11,24 +11,45 @@ class Link extends Action
|
||||
|
||||
protected $label;
|
||||
|
||||
protected $icon;
|
||||
|
||||
public function label($label)
|
||||
{
|
||||
$this->label = $label;
|
||||
$this->configure(function () use ($label) {
|
||||
$this->label = $label;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function name($name)
|
||||
public function icon($icon)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->configure(function () use ($icon) {
|
||||
$this->icon = $icon;
|
||||
});
|
||||
|
||||
$this->label(
|
||||
(string) Str::of($this->name)
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel()
|
||||
{
|
||||
if ($this->label === null) {
|
||||
return (string) Str::of($this->getName())
|
||||
->kebab()
|
||||
->replace(['-', '_', '.'], ' ')
|
||||
->ucfirst(),
|
||||
);
|
||||
->ucfirst();
|
||||
}
|
||||
|
||||
return $this;
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getIcon()
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
public function hasIcon()
|
||||
{
|
||||
return $this->icon !== null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +90,9 @@ class ListRecords extends Page
|
||||
);
|
||||
})
|
||||
->recordActions([
|
||||
RecordActions\Link::make('edit')
|
||||
->label(static::$editRecordActionLabel)
|
||||
RecordActions\Icon::make('edit')
|
||||
->icon('heroicon-o-pencil')
|
||||
// ->label(static::$editRecordActionLabel)
|
||||
->url(fn ($record) => $this->getResource()::generateUrl($this->recordRoute, ['record' => $record]))
|
||||
->when(fn ($record) => Filament::can('update', $record)),
|
||||
])
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Resources\Tables\RecordActions;
|
||||
|
||||
class Icon extends \Filament\Tables\RecordActions\Icon
|
||||
{
|
||||
//
|
||||
}
|
||||
Reference in New Issue
Block a user