Skip to content

Commit

Permalink
Merge pull request #21 from cklei-carly/main
Browse files Browse the repository at this point in the history
Generate URL bugfix and Use 'defaultDisplayUrl' instead of 'urlAsDefault
  • Loading branch information
lam0819 authored Aug 6, 2024
2 parents 652ff94 + 24d43c4 commit 873fe86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ Tables\Columns\TextColumn::make('pdf_url')
->simpleLightbox("Your Url address"),
```

You can pass parameter to generate url, also the url can be used as default value (`urlAsDefault` default is true):
You can pass parameter to generate url, also the url can be used as default value (`defaultDisplayUrl` default is true):
```php
Tables\Columns\ImageColumn::make('image')
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
```
```php
Tables\Columns\TextColumn::make('url')
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
```
```php
InfoLists\Components\ImageEntry::make('image')
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
```
```php
Tables\Columns\ImageColumn::make('image')
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", urlAsDefault: true),
->simpleLightbox(fn ($record) => $record?->image ?? "Your Image Url address", defaultDisplayUrl: true),
```
## Preview

Expand Down
46 changes: 15 additions & 31 deletions src/SimpleLightBoxPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,65 +36,49 @@ public function boot(Panel $panel): void
return $url;
};

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

$url = $ensureLightBoxUrl($url, $this);

$extraAttributes = $this->extraAttributes[0] ?? [];
$extraImgAttributes = $this->extraImgAttributes[0] ?? [];

if ($urlAsDefault) {
if ($defaultDisplayUrl) {
$this->defaultImageUrl($url);

Check failure on line 42 in src/SimpleLightBoxPlugin.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method SolutionForest\FilamentSimpleLightBox\SimpleLightBoxPlugin::defaultImageUrl().
}

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

ImageEntry::macro('simpleLightbox', function ($url = null, $urlAsDefault = true) use ($ensureLightBoxUrl) {

$url = $ensureLightBoxUrl($url, $this);

$extraAttributes = $this->extraAttributes[0] ?? [];
$extraImgAttributes = $this->extraImgAttributes[0] ?? [];
ImageEntry::macro('simpleLightbox', function ($url = null, $defaultDisplayUrl = true) use ($ensureLightBoxUrl) {

if ($urlAsDefault) {
if ($defaultDisplayUrl) {
$this->defaultImageUrl($url);

Check failure on line 56 in src/SimpleLightBoxPlugin.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method SolutionForest\FilamentSimpleLightBox\SimpleLightBoxPlugin::defaultImageUrl().
}

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

TextColumn::macro('simpleLightbox', function ($url = null, $urlAsDefault = true) use ($ensureLightBoxUrl) {
TextColumn::macro('simpleLightbox', function ($url = null, $defaultDisplayUrl = true) use ($ensureLightBoxUrl) {

$url = $ensureLightBoxUrl($url, $this);

$extraAttributes = $this->extraAttributes[0] ?? [];

if ($urlAsDefault) {
if ($defaultDisplayUrl) {
$this->default($url);

Check failure on line 69 in src/SimpleLightBoxPlugin.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method SolutionForest\FilamentSimpleLightBox\SimpleLightBoxPlugin::default().
}

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

TextEntry::macro('simpleLightbox', function ($url = null, $urlAsDefault = true) {

$extraAttributes = $this->extraAttributes[0] ?? [];
TextEntry::macro('simpleLightbox', function ($url = null, $defaultDisplayUrl = true) {

if ($urlAsDefault) {
if ($defaultDisplayUrl) {
$this->default($url);

Check failure on line 82 in src/SimpleLightBoxPlugin.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method SolutionForest\FilamentSimpleLightBox\SimpleLightBoxPlugin::default().
}

Expand All @@ -104,10 +88,10 @@ public function boot(Panel $panel): void
// ->extraAttributes(array_merge($extraAttributes, ['x-on:click' => 'SimpleLightBox.open(event, \'' . $url . '\')']));
// Special case for text entry, open lightbox for text entry as cannot evaluate url at this point
->url($url)
->extraAttributes(array_merge($extraAttributes, [
->extraAttributes([
'x-on:click' => 'SimpleLightBox.openForTextEntry(event, \'a\', \'href\')',
'class' => 'fi-in-text-with-lightbox',
]))
], true)
->extraEntryWrapperAttributes([
'class' => 'fi-in-text-with-lightbox-wrapper',
], true);
Expand Down

0 comments on commit 873fe86

Please sign in to comment.