|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace Eclipse\Common\Admin\Filament\Tables\Columns; |
| 3 | +namespace Eclipse\Common\Filament\Tables\Columns; |
4 | 4 |
|
5 | 5 | use Closure; |
6 | | -use Filament\Tables\Columns\ImageColumn; |
| 6 | +use Filament\Tables\Columns\ImageColumn as BaseImageColumn; |
7 | 7 | use Illuminate\Database\Eloquent\Model; |
8 | 8 |
|
9 | | -class SliderColumn extends ImageColumn |
| 9 | +class ImageColumn extends BaseImageColumn |
10 | 10 | { |
11 | 11 | protected mixed $titleCallback = null; |
12 | 12 |
|
13 | 13 | protected mixed $linkCallback = null; |
14 | 14 |
|
15 | | - protected function setUp(): void |
16 | | - { |
17 | | - parent::setUp(); |
18 | | - |
19 | | - $this->extraImgAttributes(function (Model $record, $column): array { |
20 | | - $imageUrls = $this->getImageUrls($column); |
| 15 | + protected bool $previewEnabled = false; |
21 | 16 |
|
22 | | - if (empty($imageUrls)) { |
23 | | - return []; |
24 | | - } |
25 | | - |
26 | | - $lightboxData = []; |
27 | | - foreach ($imageUrls as $imageUrl) { |
28 | | - $lightboxData[] = [ |
29 | | - 'url' => $imageUrl, |
30 | | - 'title' => $this->getTitle($record), |
31 | | - 'link' => $this->getLink($record), |
32 | | - 'filename' => basename($imageUrl), |
| 17 | + public function preview(bool $condition = true): static |
| 18 | + { |
| 19 | + $this->previewEnabled = $condition; |
| 20 | + |
| 21 | + if ($this->previewEnabled) { |
| 22 | + $this->extraImgAttributes(function (Model $record, $column): array { |
| 23 | + $imageUrls = $this->getImageUrls($column); |
| 24 | + |
| 25 | + if (empty($imageUrls)) { |
| 26 | + return []; |
| 27 | + } |
| 28 | + |
| 29 | + $lightboxData = []; |
| 30 | + foreach ($imageUrls as $imageUrl) { |
| 31 | + $lightboxData[] = [ |
| 32 | + 'url' => $imageUrl, |
| 33 | + 'title' => $this->getTitle($record), |
| 34 | + 'link' => $this->getLink($record), |
| 35 | + 'filename' => basename($imageUrl), |
| 36 | + ]; |
| 37 | + } |
| 38 | + |
| 39 | + return [ |
| 40 | + 'class' => 'cursor-pointer image-preview-trigger hover:opacity-75 transition-opacity', |
| 41 | + 'onclick' => 'event.stopPropagation(); return false;', |
| 42 | + 'data-lightbox-config' => json_encode($lightboxData), |
33 | 43 | ]; |
34 | | - } |
| 44 | + }); |
| 45 | + } |
35 | 46 |
|
36 | | - return [ |
37 | | - 'class' => 'cursor-pointer image-preview-trigger hover:opacity-75 transition-opacity', |
38 | | - 'onclick' => 'event.stopPropagation(); return false;', |
39 | | - 'data-lightbox-config' => json_encode($lightboxData), |
40 | | - ]; |
41 | | - }); |
| 47 | + return $this; |
| 48 | + } |
| 49 | + |
| 50 | + protected function setUp(): void |
| 51 | + { |
| 52 | + parent::setUp(); |
42 | 53 | } |
43 | 54 |
|
44 | 55 | public function title(string|Closure $title): static |
|
0 commit comments