Filament-SimpleLightBox icon indicating copy to clipboard operation
Filament-SimpleLightBox copied to clipboard

[Bug]: ->extraAttributes([]) does not work

Open sitenzo opened this issue 1 year ago • 1 comments

What happened?

I cannot use ->extraAttributes([]) when using ->simpleLightbox()

How to reproduce the bug

add below code to a ImageEntry

->extraAttributes([
    'class' => 'cursor-pointer',
])
->simpleLightbox()

Package Version

0.0.6

PHP Version

8.2.11

Laravel Version

11.1.1

Which operating systems does with happen with?

Windows

Notes

Also if i dont put ->simpleLightbox() add the end the lightbox wont work at all.

sitenzo avatar Apr 20 '24 08:04 sitenzo

I found the problem with this bug,

The attributes wont merge with already set items.

Here is my solution that works for me.

        \Filament\Tables\Columns\ImageColumn::macro('Lightbox', macro: function ($url = null) {
            $extraAttributes = ! $this->extraAttributes ? [] : $this->extraAttributes[0];
            $extraImgAttributes = ! $this->extraImgAttributes ? [] : $this->extraImgAttributes[0];

            return $this
                ->extraAttributes(array_merge($extraAttributes, ['x-on:click' => 'SimpleLightBox.open(event, \''.$url.'\')']))
                ->extraImgAttributes(array_merge($extraImgAttributes, ['class' => 'simple-light-box-img-indicator']));
        });

        \Filament\Infolists\Components\ImageEntry::macro('Lightbox', function ($url = null) {
            $extraAttributes = ! $this->extraAttributes ? [] : $this->extraAttributes[0];

            return $this
                ->extraAttributes(array_merge($extraAttributes, ['x-on:click' => 'SimpleLightBox.open(event, \''.$url.'\')']))
                ->extraImgAttributes(array_merge($this->extraImgAttributes, ['class' => 'simple-light-box-img-indicator']));
        });

sitenzo avatar Apr 20 '24 18:04 sitenzo