Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DocumentHeaderSection.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Filament\Forms\Components;
  3. use Closure;
  4. use Filament\Forms\Components\FileUpload;
  5. use Filament\Forms\Components\Group;
  6. use Filament\Forms\Components\Section;
  7. use Filament\Forms\Components\Split;
  8. use Filament\Forms\Components\TextInput;
  9. use Filament\Support\Enums\MaxWidth;
  10. use Illuminate\Support\Facades\Auth;
  11. use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
  12. class DocumentHeaderSection extends Section
  13. {
  14. protected string | Closure | null $defaultHeader = null;
  15. protected string | Closure | null $defaultSubheader = null;
  16. public function defaultHeader(string | Closure | null $header): static
  17. {
  18. $this->defaultHeader = $header;
  19. return $this;
  20. }
  21. public function defaultSubheader(string | Closure | null $subheader): static
  22. {
  23. $this->defaultSubheader = $subheader;
  24. return $this;
  25. }
  26. protected function setUp(): void
  27. {
  28. parent::setUp();
  29. $this->collapsible();
  30. $this->collapsed();
  31. $this->schema([
  32. Split::make([
  33. Group::make([
  34. FileUpload::make('logo')
  35. ->openable()
  36. ->maxSize(1024)
  37. ->localizeLabel()
  38. ->visibility('public')
  39. ->disk('public')
  40. ->directory('logos/document')
  41. ->imageResizeMode('contain')
  42. ->imageCropAspectRatio('3:2')
  43. ->panelAspectRatio('3:2')
  44. ->maxWidth(MaxWidth::ExtraSmall)
  45. ->panelLayout('integrated')
  46. ->removeUploadedFileButtonPosition('center bottom')
  47. ->uploadButtonPosition('center bottom')
  48. ->uploadProgressIndicatorPosition('center bottom')
  49. ->getUploadedFileNameForStorageUsing(
  50. static fn (TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName())
  51. ->prepend(Auth::user()->currentCompany->id . '_'),
  52. )
  53. ->acceptedFileTypes(['image/png', 'image/jpeg', 'image/gif']),
  54. ]),
  55. Group::make([
  56. TextInput::make('header')
  57. ->default(fn () => $this->getDefaultHeader()),
  58. TextInput::make('subheader')
  59. ->default(fn () => $this->getDefaultSubheader()),
  60. ])->grow(true),
  61. ])->from('md'),
  62. ]);
  63. }
  64. public function getDefaultHeader(): ?string
  65. {
  66. return $this->evaluate($this->defaultHeader);
  67. }
  68. public function getDefaultSubheader(): ?string
  69. {
  70. return $this->evaluate($this->defaultSubheader);
  71. }
  72. }