Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CustomTableRepeater.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Filament\Forms\Components;
  3. use Awcodes\TableRepeater\Components\TableRepeater;
  4. use Closure;
  5. use Filament\Forms\Components\Actions\Action;
  6. class CustomTableRepeater extends TableRepeater
  7. {
  8. protected bool | Closure $spreadsheet = false;
  9. protected bool | Closure $reorderAtStart = false;
  10. public function spreadsheet(bool | Closure $condition = true): static
  11. {
  12. $this->spreadsheet = $condition;
  13. return $this;
  14. }
  15. public function isSpreadsheet(): bool
  16. {
  17. return (bool) $this->evaluate($this->spreadsheet);
  18. }
  19. public function reorderAtStart(bool | Closure $condition = true): static
  20. {
  21. $this->reorderAtStart = $condition;
  22. return $this;
  23. }
  24. public function isReorderAtStart(): bool
  25. {
  26. return $this->evaluate($this->reorderAtStart) && $this->isReorderable();
  27. }
  28. protected function setUp(): void
  29. {
  30. parent::setUp();
  31. $this->extraAttributes(function (): array {
  32. $attributes = [];
  33. if ($this->isSpreadsheet()) {
  34. $attributes['class'] = 'is-spreadsheet';
  35. }
  36. return $attributes;
  37. });
  38. $this->reorderAction(function (Action $action) {
  39. if ($this->isReorderAtStart()) {
  40. $action->icon('heroicon-m-bars-3');
  41. }
  42. return $action;
  43. });
  44. }
  45. public function getView(): string
  46. {
  47. return 'filament.forms.components.custom-table-repeater';
  48. }
  49. }