Skip to content

Commit 21bd11e

Browse files
authored
Merge pull request #23 from chetanupare/feature/file-upload-progress-bar
2 parents 8ecc5eb + e02fe72 commit 21bd11e

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

resources/views/components/file/index.blade.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
'showValidation' => true,
66
'tooltip' => null,
77
'maxSize' => null,
8+
'showProgress' => false,
89
])
910

1011
<div>
1112
<div class="relative flex w-full flex-col gap-1"
13+
x-on:livewire-upload-start="uploading = true"
14+
x-on:livewire-upload-finish="uploading = false"
15+
x-on:livewire-upload-cancel="uploading = false"
16+
x-on:livewire-upload-error="uploading = false"
17+
x-on:livewire-upload-progress="progress = $event.detail.progress"
1218
x-data="{
1319
uuid: Math.random().toString(20).substring(2, 20),
1420
errorMessage: '',
21+
uploading: false,
22+
progress: 0,
23+
1524
checkFileSize(event) {
1625
this.errorMessage = '';
1726
const file = event.target.files[0];
@@ -37,21 +46,36 @@
3746
@endif
3847

3948

40-
<input x-bind:id="uuid"
41-
type="file"
42-
@change="checkFileSize($event)"
43-
@if($tooltip) x-tooltip.raw="{{ $tooltip }}" @endif
44-
{{ $attributes->twMerge('w-full overflow-clip rounded-radius border border-outline bg-surface-alt/50 text-sm text-on-surface file:mr-4 file:border-none file:bg-surface-alt file:px-4 file:py-2 file:font-medium file:text-on-surface-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-75 dark:border-outline-dark dark:bg-surface-dark-alt/50 dark:text-on-surface-dark dark:file:bg-surface-dark-alt dark:file:text-on-surface-dark-strong dark:focus-visible:outline-primary-dark') }}/>
49+
<div class="relative">
50+
<input x-bind:id="uuid"
51+
type="file"
52+
@change="checkFileSize($event)"
53+
@if($tooltip) x-tooltip.raw="{{ $tooltip }}" @endif
54+
{{ $attributes->twMerge('w-full overflow-clip rounded-radius border border-outline bg-surface-alt/50 text-sm text-on-surface file:mr-4 file:border-none file:bg-surface-alt file:px-4 file:py-2 file:font-medium file:text-on-surface-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-75 dark:border-outline-dark dark:bg-surface-dark-alt/50 dark:text-on-surface-dark dark:file:bg-surface-dark-alt dark:file:text-on-surface-dark-strong dark:focus-visible:outline-primary-dark') }}/>
4555

46-
@if($showValidation)
47-
<div class="text-danger text-sm">
48-
<span x-show="errorMessage" x-text="errorMessage" x-cloak></span>
49-
@if($attributes->whereStartsWith('wire:model')->first() && $errors->has($attributes->whereStartsWith('wire:model')->first()))
50-
<span x-show="!errorMessage" x-cloak>{{ $errors->first($attributes->whereStartsWith('wire:model')->first()) }}</span>
51-
@endif
56+
@if($showProgress)
57+
<div class="mt-1" x-show="uploading" x-cloak>
58+
<div class="flex h-2.5 w-full overflow-hidden rounded-radius bg-surface-alt dark:bg-surface-dark-alt">
59+
<div class="h-full bg-primary transition-all duration-500 ease-out dark:bg-primary-dark"
60+
x-bind:style="'width: ' + progress + '%'">
61+
</div>
62+
</div>
63+
<div class="text-right text-xs mt-1 text-on-surface/50 dark:text-on-surface-dark/50">
64+
<span x-text="progress + '%'"></span>
5265
</div>
66+
</div>
67+
@endif
68+
</div>
69+
70+
@if($showValidation)
71+
<div class="text-danger text-sm">
72+
<span x-show="errorMessage" x-text="errorMessage" x-cloak></span>
73+
@if($attributes->whereStartsWith('wire:model')->first() && $errors->has($attributes->whereStartsWith('wire:model')->first()))
74+
<span x-show="!errorMessage" x-cloak>{{ $errors->first($attributes->whereStartsWith('wire:model')->first()) }}</span>
5375
@endif
5476
</div>
77+
@endif
78+
</div>
5579

5680
@if($hint)
5781
<p class="text-on-surface/50 dark:text-on-surface-dark/50 text-xs mt-1">

0 commit comments

Comments
 (0)