2025-07-01 08:47:59 +02:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Filament\Components\Actions;
use Closure;
use Filament\Actions\Action;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Js;
use Livewire\Features\SupportJsEvaluation\HandlesJsEvaluation;
class CopyAction extends Action
{
use HandlesJsEvaluation;
protected Closure|string|null $copyable = null;
public static function getDefaultName(): ?string
{
return 'copy';
}
public function setUp(): void
{
parent::setUp();
$this->icon('tabler-clipboard-copy');
$this->successNotificationTitle(trans('filament::components/copyable.messages.copied'));
$this->extraAttributes(fn () => [
'x-on:click' => new HtmlString('window.navigator.clipboard.writeText('.$this->getCopyable().'); $tooltip('.Js::from($this->getSuccessNotificationTitle()).');'),
]);
}
public function copyable(Closure|string|null $copyable): self
{
$this->copyable = $copyable;
return $this;
}
public function getCopyable(): ?string
{
return Js::from($this->evaluate($this->copyable));
}
}