From 434f83928e0eee19c2313353c2f406d78ac27687 Mon Sep 17 00:00:00 2001 From: gladjanus43 Date: Mon, 28 Oct 2024 11:37:17 +0100 Subject: [PATCH 1/2] add minimal layout method This method adds the possibility for users to choose the minimal layout. This method removes rings, borders, background and divides. Leaving only the Inputs, headers and actions in a minimal way. --- .../views/components/table-repeater.blade.php | 281 ++++++++++-------- src/Components/TableRepeater.php | 15 +- 2 files changed, 166 insertions(+), 130 deletions(-) diff --git a/resources/views/components/table-repeater.blade.php b/resources/views/components/table-repeater.blade.php index 282887f..fda77c4 100644 --- a/resources/views/components/table-repeater.blade.php +++ b/resources/views/components/table-repeater.blade.php @@ -3,6 +3,8 @@ use Filament\Support\Enums\Alignment; use Filament\Support\Enums\MaxWidth; + $isMinimal = $isMinimal(); + $containers = $getChildComponentContainers(); $addAction = $getAction($getAddActionName()); @@ -27,28 +29,26 @@ $statePath = $getStatePath(); foreach ($extraActions as $extraAction) { - $visibleExtraActions = array_filter( - $extraActions, - fn (Action $action): bool => $action->isVisible(), - ); + $visibleExtraActions = array_filter($extraActions, fn(Action $action): bool => $action->isVisible()); } foreach ($extraItemActions as $extraItemAction) { - $visibleExtraItemActions = array_filter( - $extraItemActions, - fn (Action $action): bool => $action->isVisible(), - ); + $visibleExtraItemActions = array_filter($extraItemActions, fn(Action $action): bool => $action->isVisible()); } - $hasActions = $reorderAction->isVisible() - || $cloneAction->isVisible() - || $deleteAction->isVisible() - || $moveUpAction->isVisible() - || $moveDownAction->isVisible() - || filled($visibleExtraItemActions); + $hasActions = + $reorderAction->isVisible() || + $cloneAction->isVisible() || + $deleteAction->isVisible() || + $moveUpAction->isVisible() || + $moveDownAction->isVisible() || + filled($visibleExtraItemActions); @endphp - +
merge($getExtraAttributes())->class([ @@ -60,140 +60,163 @@ 'xl', MaxWidth::ExtraLarge => 'break-point-xl', '2xl', MaxWidth::TwoExtraLarge => 'break-point-2xl', default => 'break-point-md', - } + }, ]) }} > + @if (count($containers) || $emptyLabel !== false) -
+
!$isMinimal, + ])> + ! $renderHeader, - 'table-repeater-header rounded-t-xl overflow-hidden border-b border-gray-950/5 dark:border-white/20' => $renderHeader, + 'table-repeater-header-hidden sr-only' => !$renderHeader, + 'table-repeater-header overflow-hidden' => $renderHeader, + 'border-b border-gray-950/5 dark:border-white/10 rounded-t-xl' => !$isMinimal, ])> - - @foreach ($headers as $key => $header) - !$isMinimal, + ])> + @foreach ($headers as $key => $header) + + @endforeach + @if ($hasActions && count($containers)) + - @endforeach - @if ($hasActions && count($containers)) - - @endif - + + @endif + !$isMinimal, + ]) > - @if (count($containers)) - @foreach ($containers as $uuid => $row) - @php - $visibleExtraItemActions = array_filter( - $extraItemActions, - fn (Action $action): bool => $action(['item' => $uuid])->isVisible(), - ); - @endphp - - @php($counter = 0) - @foreach($row->getComponents() as $cell) - @if($cell instanceof \Filament\Forms\Components\Hidden || $cell->isHidden()) - {{ $cell }} - @else - + @php($counter = 0) + @foreach ($row->getComponents() as $cell) + @if ($cell instanceof \Filament\Forms\Components\Hidden || $cell->isHidden()) {{ $cell }} - - @endif - @endforeach - - @if ($hasActions) - + @endif + @endforeach + + @if ($hasActions) + - @endif + + + @endif + + @endforeach + @else + + - @endforeach - @else - - - - @endif + @endif
getAlignment()) { - 'center', Alignment::Center => 'text-center', - 'right', 'end', Alignment::Right, Alignment::End => 'text-end', - default => 'text-start' - } - ]) - style="width: {{ $header->getWidth() }}" - > - {{ $header->getLabel() }} - @if ($header->isRequired()) - - * +
!$isMinimal, + // 'font-medium text-regular' => $isMinimal, + match ($header->getAlignment()) { + 'center', Alignment::Center => 'text-center', + 'right', 'end', Alignment::Right, Alignment::End => 'text-end', + default => 'text-start', + }, + ]) + style="width: {{ $header->getWidth() }}" + > + {{ $header->getLabel() }} + @if ($header->isRequired()) + + * + + @endif + !$isMinimal, + ])> + + {{ trans('table-repeater::components.repeater.row_actions.label') }} - @endif - - - {{ trans('table-repeater::components.repeater.row_actions.label') }} - -
! $streamlined, - 'has-hidden-label' => $cell->isLabelHidden(), - match($headers[$counter++]->getAlignment()) { - 'center', Alignment::Center => 'text-center', - 'right', 'end', Alignment::Right, Alignment::End => 'text-end', - default => 'text-start' - } - ]) - style="width: {{ $cell->getMaxWidth() ?? 'auto' }}" - > + @if (count($containers)) + @foreach ($containers as $uuid => $row) + @php + $visibleExtraItemActions = array_filter( + $extraItemActions, + fn(Action $action): bool => $action(['item' => $uuid])->isVisible(), + ); + @endphp +
-
    - @foreach ($visibleExtraItemActions as $extraItemAction) -
  • - {{ $extraItemAction(['item' => $uuid]) }} -
  • - @endforeach - - @if ($reorderAction->isVisible()) -
  • - {{ $reorderAction }} -
  • - @endif - - @if ($isReorderableWithButtons) - @if (! $loop->first) + @else +
!$streamlined && !$isMinimal, + 'pr-3 pt-5' => $isMinimal, + 'has-hidden-label' => $cell->isLabelHidden(), + match ($headers[$counter++]->getAlignment()) { + 'center', Alignment::Center => 'text-center', + 'right', 'end', Alignment::Right, Alignment::End => 'text-end', + default => 'text-start', + }, + ]) + style="width: {{ $cell->getMaxWidth() ?? 'auto' }}" + > + {{ $cell }} + +
    + @foreach ($visibleExtraItemActions as $extraItemAction) +
  • + {{ $extraItemAction(['item' => $uuid]) }} +
  • + @endforeach + + @if ($reorderAction->isVisible()) +
  • + {{ $reorderAction }} +
  • + @endif + + @if ($isReorderableWithButtons) + @if (!$loop->first) +
  • + {{ $moveUpAction(['item' => $uuid]) }} +
  • + @endif + + @if (!$loop->last) +
  • + {{ $moveDownAction(['item' => $uuid]) }} +
  • + @endif + @endif + + @if ($cloneAction->isVisible())
  • - {{ $moveUpAction(['item' => $uuid]) }} + {{ $cloneAction(['item' => $uuid]) }}
  • @endif - @if (! $loop->last) + @if ($deleteAction->isVisible())
  • - {{ $moveDownAction(['item' => $uuid]) }} + {{ $deleteAction(['item' => $uuid]) }}
  • @endif - @endif - - @if ($cloneAction->isVisible()) -
  • - {{ $cloneAction(['item' => $uuid]) }} -
  • - @endif - - @if ($deleteAction->isVisible()) -
  • - {{ $deleteAction(['item' => $uuid]) }} -
  • - @endif -
-
+ {{ $emptyLabel ?: trans('table-repeater::components.repeater.empty.label') }} +
- {{ $emptyLabel ?: trans('table-repeater::components.repeater.empty.label') }} -
@@ -209,7 +232,7 @@ class="table-repeater-column table-repeater-empty-column p-4 w-px text-center it @if (filled($visibleExtraActions)) @foreach ($visibleExtraActions as $extraAction)
  • - {{ ($extraAction) }} + {{ $extraAction }}
  • @endforeach @endif diff --git a/src/Components/TableRepeater.php b/src/Components/TableRepeater.php index d323b06..322d905 100644 --- a/src/Components/TableRepeater.php +++ b/src/Components/TableRepeater.php @@ -15,13 +15,14 @@ class TableRepeater extends Repeater use Concerns\HasHeader; protected bool | Closure | null $showLabels = null; + protected bool | Closure | null $minimal = false; protected function setUp(): void { parent::setUp(); $this->registerActions([ - fn (TableRepeater $component): array => $component->getExtraActions() + fn(TableRepeater $component): array => $component->getExtraActions() ]); } @@ -57,6 +58,18 @@ public function shouldShowLabels(): bool return $this->evaluate($this->showLabels) ?? false; } + public function minimal(bool | Closure | null $condition = true): static + { + $this->minimal = $condition; + + return $this; + } + + public function isMinimal(): bool + { + return $this->evaluate($this->minimal) ?? false; + } + public function getView(): string { return 'table-repeater::components.table-repeater'; From 0b15da9c4102c0c2b4d4b3d0f5aaaaa6ebee915c Mon Sep 17 00:00:00 2001 From: gladjanus43 Date: Tue, 29 Oct 2024 11:40:11 +0100 Subject: [PATCH 2/2] fix alignment issue with actions --- resources/views/components/table-repeater.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/components/table-repeater.blade.php b/resources/views/components/table-repeater.blade.php index fda77c4..fe35378 100644 --- a/resources/views/components/table-repeater.blade.php +++ b/resources/views/components/table-repeater.blade.php @@ -133,7 +133,7 @@ @php($counter = 0) @foreach ($row->getComponents() as $cell) @@ -144,7 +144,7 @@ class="table-repeater-row " @class([ 'table-repeater-column', 'p-2' => !$streamlined && !$isMinimal, - 'pr-3 pt-5' => $isMinimal, + 'pr-3 py-3' => $isMinimal, 'has-hidden-label' => $cell->isLabelHidden(), match ($headers[$counter++]->getAlignment()) { 'center', Alignment::Center => 'text-center',