您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DocumentHeaderSection.php 3.5KB

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