Skip to content

Commit d391ae0

Browse files
author
ankitcodes4u
committed
feat: implementing requested changes
1 parent 5b32543 commit d391ae0

2 files changed

Lines changed: 39 additions & 28 deletions

File tree

src/Admin/Filament/Tables/Columns/SliderColumn.php renamed to src/Filament/Tables/Columns/ImageColumn.php

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
11
<?php
22

3-
namespace Eclipse\Common\Admin\Filament\Tables\Columns;
3+
namespace Eclipse\Common\Filament\Tables\Columns;
44

55
use Closure;
6-
use Filament\Tables\Columns\ImageColumn;
6+
use Filament\Tables\Columns\ImageColumn as BaseImageColumn;
77
use Illuminate\Database\Eloquent\Model;
88

9-
class SliderColumn extends ImageColumn
9+
class ImageColumn extends BaseImageColumn
1010
{
1111
protected mixed $titleCallback = null;
1212

1313
protected mixed $linkCallback = null;
1414

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;
2116

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),
3343
];
34-
}
44+
});
45+
}
3546

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();
4253
}
4354

4455
public function title(string|Closure $title): static
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Eclipse\Common\Foundation\Helpers;
3+
namespace Eclipse\Common\Helpers;
44

55
class MediaHelper
66
{

0 commit comments

Comments
 (0)