Skip to content

Commit de9dbdc

Browse files
feat: add DisplayOnEnum with list and grid view support
1 parent 47005d8 commit de9dbdc

File tree

11 files changed

+1529
-802
lines changed

11 files changed

+1529
-802
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ JsonMediaGallery::make('images')
125125
)
126126
->editableCustomProperties(bool|Closure) // if you want to enable/disable the custom properties edition ;
127127
```
128+
### Show your media in a grid way
129+
130+
You can now view your medias in **grid** list like this :
131+
![img.png](img.png)
132+
```php
133+
use GalleryJsonMedia\Tables\Columns\JsonMediaColumn;
134+
JsonMediaGallery::make('images')
135+
...
136+
->displayOnGrid()
137+
```
128138

129139
### In Filament Tables
130140
![table-filament-json-media.png](https://raw.githubusercontent.com/webplusmultimedia/filament-json-media/main/table-filament-json-media.png)

img.png

436 KB
Loading

package-lock.json

Lines changed: 1432 additions & 764 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@awcodes/filament-plugin-purge": "^1.1.1",
1515
"@tailwindcss/postcss": "^4.1.10",
1616
"@tailwindcss/cli": "^4.1.10",
17-
"esbuild": "^0.19.2",
17+
"esbuild": "0.25.0",
1818
"npm-run-all": "^4.1.5",
1919
"postcss": "^8.4.26",
2020
"tailwindcss": "^4.1.10"

resources/css/index.css

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,23 @@
1414
--wp-gallery-icon-wrapper-padding: 0.2rem;
1515
--wm-progress : 0;
1616

17+
/* Flex Context */
1718
display: flex;
18-
gap: 1rem;
19-
margin-block-end: 1rem;
2019
scroll-snap-type: x var(--gallery-file-snap-x);
2120
overflow: hidden;
2221
transition: all 0.2s ease-in-out;
2322

2423
.image-file {
2524
scroll-snap-align: center;
2625
background: var(--gallery-file-green);
27-
width: var( --gallery-image-file-width);
28-
height: var(--gallery-image-file-height);
2926
position: relative;
3027
border-radius: var(--gallery-item-radiux);
3128
overflow: hidden;
3229
display: flex;
3330
flex-shrink: 0;
3431
align-items: stretch;
3532
font-size: 11px;
36-
box-sizing: border-box;
33+
/*box-sizing: border-box;*/
3734
outline: 1px solid rgba(190, 189, 189, 0.46);
3835
outline-offset: -1px;
3936

resources/dist/gallery-json-media.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/forms/content/gallery-content.blade.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
@php
22
use Filament\Support\Enums\IconSize;
33
use Filament\Support\Icons\Heroicon;
4-
use GalleryJsonMedia\Enums\GalleryType;
4+
use GalleryJsonMedia\Enums\DisplayOnEnum;use GalleryJsonMedia\Enums\GalleryType;
55
use function Filament\Support\generate_icon_html;
66
use function Filament\Support\generate_loading_indicator_html;
77
@endphp
88
<template x-for="(file, fileIndex) in uploadFiles" :key="fileIndex">
9-
<li class="image-file" role="listitem"
9+
<li
10+
@class([
11+
"image-file h-[180px]",
12+
"w-[280px]" => $getDisplayOn() === DisplayOnEnum::LIST,
13+
"w-[200px] h-[150px]" => $galleryType() === GalleryType::Document,
14+
])
15+
role="listitem"
1016
x-data="{startGrabbing: false}"
1117
:data-id="file.filekey"
1218
:x-ref="fileIndex"
1319
:x-sortable-item="file.filekey"
1420
:class="{ 'opacity-25': indexBeingDragged === fileIndex }"
15-
@style(['--gallery-image-file-width: 200px;--gallery-image-file-height: 150px;'=> $galleryType() === GalleryType::Document ])
1621
>
1722
<div class="flex w-full max-h-fit"
1823
:class="{'pointer-events-none': indexBeingDragged}"
@@ -38,7 +43,7 @@
3843
<div class="gallery-footer" x-data="{ itemDrag : false }">
3944
<div class="flex">
4045
@if($isReorderable())
41-
<button type="button" class="gallery-icon reorder justify-self-start hidden sm:block"
46+
<button type="button" class="gallery-icon reorder justify-self-start hidden @xs:block"
4247
:class="{
4348
'grabbing-cursor' : startGrabbing,
4449
'grab-cursor' : !startGrabbing,

resources/views/forms/gallery-file-upload.blade.php

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@php
22
use Filament\Support\Facades\FilamentAsset;
33
use Filament\Support\Facades\FilamentView;
4-
use Illuminate\Support\Arr;
4+
use GalleryJsonMedia\Enums\DisplayOnEnum;use Illuminate\Support\Arr;
55
$editPropertiesAction = $getAction($getCustomPropertiesActionName()) ;
66
$key = $getKey();
77
@@ -92,48 +92,59 @@ class="hidden"
9292
x-bind="dropZone"
9393
x-show="canUpload"
9494
>
95-
<div class="flex gap-3 pointer-events-none text-gray-400 dark:text-gray-500 group-hover:text-primary-600 dark:group-hover:text-primary-500 transition-all duration-200" x-ref="ladroptitle">
95+
<div
96+
class="flex gap-3 pointer-events-none text-gray-400 dark:text-gray-500 group-hover:text-primary-600 dark:group-hover:text-primary-500 transition-all duration-200"
97+
x-ref="ladroptitle">
9698
@svg(name: 'heroicon-o-document-arrow-up',class:"w-10 h-auto" )
9799
<div class="flex flex-col x-space-y-2">
98100
<span>{{ trans('gallery-json-media::gallery-json-media.Drag&Drop') }}</span>
99101
<span x-text="@js($getAcceptFileText())"></span>
100102
</div>
101103
</div>
102104
</div>
103-
<div class="flex justify-self-end space-y-2"
104-
x-show="uploadFiles.length"
105-
>
106-
<div class="flex gap-x-4 mt-2">
107-
<button type="button" x-bind="leftArrow"
108-
class="wm-btn"
109-
>
110-
@svg(name: 'heroicon-c-chevron-left',class: 'w-5 h-5')
111-
</button>
112-
<button type="button" x-bind="rightArrow"
113-
class="wm-btn"
114-
>
115-
@svg(name: 'heroicon-c-chevron-right',class: 'w-5 h-5')
116-
</button>
105+
@if($getDisplayOn() === DisplayOnEnum::LIST)
106+
<div class="flex justify-self-end space-y-2"
107+
x-show="uploadFiles.length"
108+
>
109+
<div class="flex gap-x-4 mt-2">
110+
<button type="button" x-bind="leftArrow"
111+
class="wm-btn"
112+
>
113+
@svg(name: 'heroicon-c-chevron-left',class: 'w-5 h-5')
114+
</button>
115+
<button type="button" x-bind="rightArrow"
116+
class="wm-btn"
117+
>
118+
@svg(name: 'heroicon-c-chevron-right',class: 'w-5 h-5')
119+
</button>
120+
</div>
117121
</div>
118-
</div>
122+
@endif
119123

120-
<div class="gallery-file-upload-wrapper"
124+
<div @class([
125+
"gallery-file-upload-wrapper my-4",
126+
"@container" => $getDisplayOn() === DisplayOnEnum::GRID
127+
])
121128
x-ref="galleryImages"
122129
x-bind="onScrolling"
123130
>
124131
<ul role="list"
125-
class="flex gap-2 transition-all duration-200"
132+
133+
@class([
134+
"flex gap-2 transition-all duration-200" => $getDisplayOn() === DisplayOnEnum::LIST,
135+
"grid gap-4 w-full grid-cols-1 @lg:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4 @5xl:grid-cols-5 @7xl:grid-cols-6 transition-all duration-200" => $getDisplayOn() === DisplayOnEnum::GRID
136+
])
126137
x-sortable
127138
@dragend="reorderUsing($el.sortable.toArray())"
128-
{{-- @drop.stop.prevent="resetState()"--}}
139+
{{-- @drop.stop.prevent="resetState()"--}}
129140
x-ref="ulGalleryWrapper"
130141

131-
{{-- @keydown.window.tab="usedKeyboard = true"
132-
@dragenter.stop.prevent="dropcheck++"
133-
@dragleave="dropcheck--;dropcheck || rePositionPlaceholder()"
134-
@dragover.stop.prevent
135-
@dragend="revertState()"
136-
@drop.stop.prevent="getSort();resetState()"--}}
142+
{{-- @keydown.window.tab="usedKeyboard = true"
143+
@dragenter.stop.prevent="dropcheck++"
144+
@dragleave="dropcheck--;dropcheck || rePositionPlaceholder()"
145+
@dragover.stop.prevent
146+
@dragend="revertState()"
147+
@drop.stop.prevent="getSort();resetState()"--}}
137148

138149
{{--:class="{'flex-wrap' : !stopDragging }"--}}
139150
>

src/Enums/DisplayOnEnum.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace GalleryJsonMedia\Enums;
6+
7+
enum DisplayOnEnum: string
8+
{
9+
case GRID = 'grid';
10+
case LIST = 'list';
11+
}

src/Form/JsonMediaGallery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function setUp(): void
9595
if (! $this->getAcceptedFileTypes()) {
9696
$this->image();
9797
}
98-
98+
$this->displayOnList();
9999
$this->multiple();
100100

101101
$this->diskName = config('gallery-json-media.disk');

0 commit comments

Comments
 (0)