mirror of
https://github.com/pelican-dev/panel.git
synced 2025-07-02 13:01:07 +02:00
47 lines
1.1 KiB
PHP
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));
|
|
}
|
|
}
|