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 3.1KB

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