|
5 | 5 | 'showValidation' => true, |
6 | 6 | 'tooltip' => null, |
7 | 7 | 'maxSize' => null, |
| 8 | + 'showProgress' => false, |
8 | 9 | ]) |
9 | 10 |
|
10 | 11 | <div> |
11 | 12 | <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" |
12 | 18 | x-data="{ |
13 | 19 | uuid: Math.random().toString(20).substring(2, 20), |
14 | 20 | errorMessage: '', |
| 21 | + uploading: false, |
| 22 | + progress: 0, |
| 23 | + |
15 | 24 | checkFileSize(event) { |
16 | 25 | this.errorMessage = ''; |
17 | 26 | const file = event.target.files[0]; |
|
37 | 46 | @endif |
38 | 47 |
|
39 | 48 |
|
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') }}/> |
45 | 55 |
|
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> |
52 | 65 | </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> |
53 | 75 | @endif |
54 | 76 | </div> |
| 77 | + @endif |
| 78 | + </div> |
55 | 79 |
|
56 | 80 | @if($hint) |
57 | 81 | <p class="text-on-surface/50 dark:text-on-surface-dark/50 text-xs mt-1"> |
|
0 commit comments