Skip to content

Commit 24d43c4

Browse files
committed
Generate URL bugfix and Use 'defaultDisplayUrl' instead of 'urlAsDefault
1 parent 652ff94 commit 24d43c4

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ Tables\Columns\TextColumn::make('pdf_url')
5656
->simpleLightbox("Your Url address"),
5757
```
5858

59-
You can pass parameter to generate url, also the url can be used as default value (`urlAsDefault` default is true):
59+
You can pass parameter to generate url, also the url can be used as default value (`defaultDisplayUrl` default is true):
6060
```php
6161
Tables\Columns\ImageColumn::make('image')
62-
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
62+
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
6363
```
6464
```php
6565
Tables\Columns\TextColumn::make('url')
66-
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
66+
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
6767
```
6868
```php
6969
InfoLists\Components\ImageEntry::make('image')
70-
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
70+
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
7171
```
7272
```php
7373
Tables\Columns\ImageColumn::make('image')
74-
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
74+
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
7575
```
7676
## Preview
7777

src/SimpleLightBoxPlugin.php

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,49 @@ public function boot(Panel $panel): void
3636
return $url;
3737
};
3838

39-
ImageColumn::macro('simpleLightbox', macro: function ($url = null, $urlAsDefault = true) use ($ensureLightBoxUrl) {
39+
ImageColumn::macro('simpleLightbox', macro: function ($url = null, $defaultDisplayUrl = true) use ($ensureLightBoxUrl) {
4040

41-
$url = $ensureLightBoxUrl($url, $this);
42-
43-
$extraAttributes = $this->extraAttributes[0] ?? [];
44-
$extraImgAttributes = $this->extraImgAttributes[0] ?? [];
45-
46-
if ($urlAsDefault) {
41+
if ($defaultDisplayUrl) {
4742
$this->defaultImageUrl($url);
4843
}
4944

5045
/** @phpstan-ignore-next-line */
5146
return $this
5247
->openUrlInNewTab()
5348
->action(fn () => null) // override default action for table row
54-
->extraAttributes(array_merge($extraAttributes, ['x-on:click' => 'SimpleLightBox.open(event, \'' . $url . '\')']))
55-
->extraImgAttributes(array_merge($extraImgAttributes, ['class' => 'simple-light-box-img-indicator']));
49+
->extraAttributes(fn () => ['x-on:click' => 'SimpleLightBox.open(event, \'' . $ensureLightBoxUrl($url, $this) . '\')'], true)
50+
->extraImgAttributes(['class' => 'simple-light-box-img-indicator'], true);
5651
});
5752

58-
ImageEntry::macro('simpleLightbox', function ($url = null, $urlAsDefault = true) use ($ensureLightBoxUrl) {
59-
60-
$url = $ensureLightBoxUrl($url, $this);
61-
62-
$extraAttributes = $this->extraAttributes[0] ?? [];
63-
$extraImgAttributes = $this->extraImgAttributes[0] ?? [];
53+
ImageEntry::macro('simpleLightbox', function ($url = null, $defaultDisplayUrl = true) use ($ensureLightBoxUrl) {
6454

65-
if ($urlAsDefault) {
55+
if ($defaultDisplayUrl) {
6656
$this->defaultImageUrl($url);
6757
}
6858

6959
/** @phpstan-ignore-next-line */
7060
return $this
7161
->openUrlInNewTab()
72-
->extraAttributes(array_merge($extraAttributes, ['x-on:click' => 'SimpleLightBox.open(event, \'' . $url . '\')']))
73-
->extraImgAttributes(array_merge($extraImgAttributes, ['class' => 'simple-light-box-img-indicator']));
62+
->extraAttributes(fn () => ['x-on:click' => 'SimpleLightBox.open(event, \'' . $ensureLightBoxUrl($url, $this) . '\')'], true)
63+
->extraImgAttributes(['class' => 'simple-light-box-img-indicator'], true);
7464
});
7565

76-
TextColumn::macro('simpleLightbox', function ($url = null, $urlAsDefault = true) use ($ensureLightBoxUrl) {
66+
TextColumn::macro('simpleLightbox', function ($url = null, $defaultDisplayUrl = true) use ($ensureLightBoxUrl) {
7767

78-
$url = $ensureLightBoxUrl($url, $this);
79-
80-
$extraAttributes = $this->extraAttributes[0] ?? [];
81-
82-
if ($urlAsDefault) {
68+
if ($defaultDisplayUrl) {
8369
$this->default($url);
8470
}
8571

8672
/** @phpstan-ignore-next-line */
8773
return $this
8874
->openUrlInNewTab()
8975
->url($url)
90-
->extraAttributes(array_merge($extraAttributes, ['x-on:click' => 'SimpleLightBox.open(event, \'' . $url . '\')']));
76+
->extraAttributes(fn () => ['x-on:click' => 'SimpleLightBox.open(event, \'' . $ensureLightBoxUrl($url, $this) . '\')'], true);
9177
});
9278

93-
TextEntry::macro('simpleLightbox', function ($url = null, $urlAsDefault = true) {
94-
95-
$extraAttributes = $this->extraAttributes[0] ?? [];
79+
TextEntry::macro('simpleLightbox', function ($url = null, $defaultDisplayUrl = true) {
9680

97-
if ($urlAsDefault) {
81+
if ($defaultDisplayUrl) {
9882
$this->default($url);
9983
}
10084

@@ -104,10 +88,10 @@ public function boot(Panel $panel): void
10488
// ->extraAttributes(array_merge($extraAttributes, ['x-on:click' => 'SimpleLightBox.open(event, \'' . $url . '\')']));
10589
// Special case for text entry, open lightbox for text entry as cannot evaluate url at this point
10690
->url($url)
107-
->extraAttributes(array_merge($extraAttributes, [
91+
->extraAttributes([
10892
'x-on:click' => 'SimpleLightBox.openForTextEntry(event, \'a\', \'href\')',
10993
'class' => 'fi-in-text-with-lightbox',
110-
]))
94+
], true)
11195
->extraEntryWrapperAttributes([
11296
'class' => 'fi-in-text-with-lightbox-wrapper',
11397
], true);

0 commit comments

Comments
 (0)