Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CustomTableRepeater.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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->minItems(1);
  32. $this->extraAttributes(function (): array {
  33. $attributes = [];
  34. if ($this->isSpreadsheet()) {
  35. $attributes['class'] = 'is-spreadsheet';
  36. }
  37. return $attributes;
  38. });
  39. $this->reorderAction(function (Action $action) {
  40. if ($this->isReorderAtStart()) {
  41. $action->icon('heroicon-m-bars-3');
  42. }
  43. return $action;
  44. });
  45. }
  46. public function getView(): string
  47. {
  48. return 'filament.forms.components.custom-table-repeater';
  49. }
  50. }