11<x-dynamic-component :component =" $getFieldWrapperView()" :field =" $field" >
2- <div x-data =" {
3- selectedMedia: {{ json_encode (
4- $getRecord ()?-> mediaThroughUsables ()?-> get ()-> map (function ($media ) {
5- return [
6- ' id' => $media -> id ,
7- ' url' => $media -> getUrl (),
8- ' file_name' => $media -> file_name ,
9- ' name' => $media -> name
2+ @php
3+ $mimeTypeLabels = [
4+ ' application/pdf' => [
5+ ' label' => ' PDF' ,
6+ ' icon' => ' /vendor/file-icons/pdf.svg'
7+ ],
8+ ' application/msword' => [
9+ ' label' => ' DOC' ,
10+ ' icon' => ' /vendor/file-icons/doc.svg'
11+ ],
12+ ' application/vnd.openxmlformats-officedocument.wordprocessingml.document' => [
13+ ' label' => ' DOCX' ,
14+ ' icon' => ' /vendor/file-icons/doc.svg'
15+ ],
16+ ' application/vnd.ms-excel' => [
17+ ' label' => ' XLS' ,
18+ ' icon' => ' /vendor/file-icons/xls.svg'
19+ ],
20+ ' application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => [
21+ ' label' => ' XLSX' ,
22+ ' icon' => ' /vendor/file-icons/xls.svg'
23+ ],
24+ ' application/vnd.ms-powerpoint' => [
25+ ' label' => ' PPT' ,
26+ ' icon' => ' /vendor/file-icons/ppt.svg'
27+ ],
28+ ' application/vnd.openxmlformats-officedocument.presentationml.presentation' => [
29+ ' label' => ' PPTX' ,
30+ ' icon' => ' /vendor/file-icons/ppt.svg'
31+ ],
32+ ' video/mp4' => [
33+ ' label' => ' MP4' ,
34+ ' icon' => ' /vendor/file-icons/mp4.svg'
35+ ],
36+ ' video/webm' => [
37+ ' label' => ' WEBM' ,
38+ ' icon' => ' /vendor/file-icons/mp4.svg'
39+ ],
40+ ' video/quicktime' => [
41+ ' label' => ' MOV' ,
42+ ' icon' => ' /vendor/file-icons/mp4.svg'
43+ ],
44+ ' audio/mpeg' => [
45+ ' label' => ' MP3' ,
46+ ' icon' => ' /vendor/file-icons/mp3.svg'
47+ ],
48+ ' audio/wav' => [
49+ ' label' => ' WAV' ,
50+ ' icon' => ' /vendor/file-icons/mp3.svg'
51+ ],
52+ ' audio/ogg' => [
53+ ' label' => ' OGG' ,
54+ ' icon' => ' /vendor/file-icons/mp3.svg'
55+ ],
56+ ' image/svg+xml' => [
57+ ' label' => ' SVG' ,
58+ ' icon' => ' /vendor/file-icons/svg.svg'
59+ ],
60+ ' application/zip' => [
61+ ' label' => ' ZIP' ,
62+ ' icon' => ' /vendor/file-icons/zip.svg'
63+ ],
64+ ' application/x-zip-compressed' => [
65+ ' label' => ' ZIP' ,
66+ ' icon' => ' /vendor/file-icons/zip.svg'
67+ ],
68+ ' text/plain' => [
69+ ' label' => ' TXT' ,
70+ ' icon' => ' /vendor/file-icons/txt.svg'
71+ ],
72+ ' text/csv' => [
73+ ' label' => ' CSV' ,
74+ ' icon' => ' /vendor/file-icons/csv.svg'
75+ ],
1076 ];
11- })-> toArray () ?? [],
12- JSON_UNESCAPED_UNICODE
13- ) } } ,
77+ @endphp
78+ <div x-data =" {
79+ selectedMedia: {{ json_encode ($getRecord ()?-> mediaThroughUsables ()?-> get ()-> map (function ($media ) {
80+ return [
81+ ' id' => $media -> id ,
82+ ' url' => $media -> getUrl (),
83+ ' file_name' => $media -> file_name ,
84+ ' name' => $media -> name ,
85+ ' mime_type' => $media -> mime_type
86+ ];
87+ })-> toArray () ?? [], JSON_UNESCAPED_UNICODE ) } } ,
88+ mimeTypes: {{ Js:: from ($mimeTypeLabels ) } } ,
89+ getIconForMimeType(type) {
90+ return this.mimeTypes[type]?.icon || this.mimeTypes['application/pdf'].icon;
91+ },
1492 state: @entangle ($getStatePath () ),
1593 isMultiple: {{ $field -> isMultiple () ? ' true' : ' false' } } ,
1694 isAvatar: {{ $field -> isAvatar () ? ' true' : ' false' } } ,
41119 @if ($this instanceof \Filament\Resources\Pages\ EditRecord || $this instanceof \Filament\Resources\Pages\ CreateRecord )
42120 <x-filament::button color =" primary" size =" sm" class =" w-full flex items-center justify-center space-x-2"
43121 x-on:click ="
44- $dispatch('set-media-picker-model', {
45- modelId: {{ $getRecord ()?-> id ?? 0 } } ,
46- modelClass: '{{ $getRecord () ? addslashes ($getRecord ():: class ) : addslashes ($this -> getResource ():: getModel ()) } } '
47- });
48- $dispatch('open-modal', { id: 'mediaPickerModal' });
49- " >
122+ $dispatch('set-media-picker-model', {
123+ modelId: {{ $getRecord ()?-> id ?? 0 } } ,
124+ modelClass: '{{ $getRecord () ? addslashes ($getRecord ():: class ) : addslashes ($this -> getResource ():: getModel ()) } } '
125+ });
126+ $dispatch('open-modal', { id: 'mediaPickerModal' });
127+ " >
50128 <span >{{ __ (' media::fields.select_media' ) } } </span >
51129 </x-filament::button >
52130 @endif
53131
54-
55132 <div class =" grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4" x-show =" selectedMedia.length > 0" >
56133 <template x-for =" (media, index) in selectedMedia" :key =" media . id" >
57134 <div
58135 class =" relative group bg-white rounded-lg shadow hover:shadow-md transition-shadow duration-300 overflow-hidden border border-gray-200" >
59-
60136 <template x-if =" isAvatar" >
61137 <x-filament::avatar x-bind:src =" media.url" x-bind:alt =" media.name" size =" w-12 h-12" />
62138 </template >
63139
64140 <template x-if =" !isAvatar" >
65- <img :src =" media . url" :alt =" media . name" class =" w-full h-32 object-cover rounded-t-lg" />
141+ <div >
142+ <template x-if =" media.mime_type && media.mime_type.startsWith('image/')" >
143+ <img :src =" media . url" :alt =" media . name"
144+ class =" w-full h-32 object-cover rounded-t-lg" />
145+ </template >
146+
147+ <template x-if =" media.mime_type && !media.mime_type.startsWith('image/')" >
148+ <div class =" flex flex-col justify-between items-center w-full h-32 mt-3" >
149+ <img :src =" $el . dataset . baseUrl + getIconForMimeType(media . mime_type)"
150+ data-base-url =" {{ asset (' ' ) } }" class =" w-16 h-16" />
151+ <div class =" text-xs text-gray-700 w-full mt-2 overflow-hidden text-ellipsis whitespace-normal break-words px-2"
152+ x-text =" media.file_name" ></div >
153+ </div >
154+ </template >
155+ </div >
66156 </template >
67157
68158 @if ($this instanceof \Filament\Resources\Pages\ EditRecord )
@@ -76,7 +166,6 @@ class="relative group bg-white rounded-lg shadow hover:shadow-md transition-shad
76166 </template >
77167 </div >
78168
79-
80169 <div x-show =" selectedMedia.length === 0"
81170 class =" border border-dashed border-gray-300 rounded-lg p-4 bg-gray-50 flex items-center justify-center text-sm text-gray-500" >
82171 {{ __ (' media::fields.no_media_selected' ) } }
0 commit comments