@props([ 'disabled' => false, 'error' => null, 'viewable' => false, 'label', 'fileName' => '', 'viewonly' => false, 'placeholder' => 'Belum memilih file', 'maxFileSize' => 5, // Dalam MB ]) @php $fileInputRef = App\Helpers\Reference::generate('FileInputRef'); $isError = $error && strlen($error) > 1; $defaultClass = 'File relative h-full flex items-center ps-3 pe-8 bg-gray-200 flex-1 rounded-l-none rounded-r-lg border select-none overflow-hidden focus:outline-none focus:ring-[1.5px] focus:ring-inset focus:border-transparent focus:bg-white focus:text-black text-gray-200 border-gray-300 focus:ring-primary-100' . ($isError ? 'border-red-400 text-red-400 focus:ring-red-400 ' : ' ') . $fileInputRef; @endphp @isset($label) @endisset @isset($description) {{ $description }} @endisset twMerge('hidden') }} x-ref="fileInputRef" x-on:change="() => { if ($event.target.files.length !== 0) { if ($event.target.files[0].size > {{ $maxFileSize }} * 1024 * 1024) { $refs.fileInputRef.value = '' files = null return $wire.notify('error', 'Ukuran file tidak boleh melebihi {{ $maxFileSize }}MB') } files = Object.values($event.target.files) } }" tabindex="-1" type="file" @if ($fileName) x-init="() => { const path = '{{ $fileName }}' const filePath = 'storage' + path.split('storage').pop() fetch(path) .then(response => response.blob()) .then(blob => { const file = new File([blob], path.split('/').pop(), { type: blob.type }) files = [file] }) }" @endif /> @if (!$disabled) isNotEmpty()) x-init="files = 'NPE_GAMBAR'" @endif > @else Pilih File @endif @if ($slot->isNotEmpty()) {{ array_slice(explode('/', $fileName), -1)[0] }} @else @endif @if (!$viewonly) @endif @if ($isError) {{ $error }} @endif @if ($viewable) @endif