Skip to content

Commit

Permalink
Feat: support extra item attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
awcodes committed Jan 25, 2024
1 parent aebf810 commit e02f186
Showing 1 changed file with 62 additions and 28 deletions.
90 changes: 62 additions & 28 deletions resources/views/components/table-repeater.blade.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
@php
$containers = $getChildComponentContainers();
$addAction = $getAction($getAddActionName());
$cloneAction = $getAction($getCloneActionName());
$deleteAction = $getAction($getDeleteActionName());
$moveDownAction = $getAction($getMoveDownActionName());
$moveUpAction = $getAction($getMoveUpActionName());
$reorderAction = $getAction($getReorderActionName());
$isReorderableWithButtons = $isReorderableWithButtons();
$headers = $getHeaders();
$columnWidths = $getColumnWidths();
$breakPoint = $getBreakPoint();
$hasContainers = count($containers) > 0;
$hasHiddenHeader = $shouldHideHeader();
$statePath = $getStatePath();
$emptyLabel = $getEmptyLabel();
$hasActions = $reorderAction->isVisible() || $cloneAction->isVisible() || $deleteAction->isVisible() || $moveUpAction->isVisible() || $moveDownAction->isVisible();
@endphp
@php
use Filament\Forms\Components\Actions\Action;
$containers = $getChildComponentContainers();
$addAction = $getAction($getAddActionName());
$cloneAction = $getAction($getCloneActionName());
$deleteAction = $getAction($getDeleteActionName());
$moveDownAction = $getAction($getMoveDownActionName());
$moveUpAction = $getAction($getMoveUpActionName());
$reorderAction = $getAction($getReorderActionName());
$isReorderableWithButtons = $isReorderableWithButtons();
$extraItemActions = $getExtraItemActions();
$headers = $getHeaders();
$columnWidths = $getColumnWidths();
$breakPoint = $getBreakPoint();
$hasContainers = count($containers) > 0;
$hasHiddenHeader = $shouldHideHeader();
$statePath = $getStatePath();
$emptyLabel = $getEmptyLabel();
$hasActions = $reorderAction->isVisible() || $cloneAction->isVisible() || $deleteAction->isVisible() || $moveUpAction->isVisible() || $moveDownAction->isVisible() || count($visibleExtraItemActions);
foreach ($containers as $uuid => $row) {
$visibleExtraItemActions = array_filter(
$extraItemActions,
fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
);
}
@endphp

<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
<div
x-data="{}"
{{ $attributes->merge($getExtraAttributes())->class([
Expand All @@ -36,7 +45,7 @@
]) }}
>
@if (count($containers) || $emptyLabel !== false)
<div @class([
<ul @class([
'filament-table-repeater-container rounded-xl relative ring-1 ring-gray-950/5 dark:ring-white/20',
'sm:ring-gray-950/5 dark:sm:ring-white/20' => ! $hasContainers && $breakPoint === 'sm',
'md:ring-gray-950/5 dark:md:ring-white/20' => ! $hasContainers && $breakPoint === 'md',
Expand Down Expand Up @@ -77,6 +86,10 @@
@if ($hasActions)
<th class="filament-table-repeater-header-column w-px ltr:rounded-tr-xl rtl:rounded-tl-xl p-2 bg-gray-100 dark:bg-gray-900/60">
<div class="flex items-center gap-2 md:justify-center">
@foreach ($visibleExtraItemActions as $extraItemAction)
<div class="w-8"></div>
@endforeach

@if ($reorderAction->isVisible())
<div class="w-8"></div>
@endif
Expand Down Expand Up @@ -114,6 +127,13 @@ class="filament-table-repeater-rows-wrapper divide-y divide-gray-950/5 dark:divi
>
@if (count($containers))
@foreach ($containers as $uuid => $row)
@php
$itemLabel = $getItemLabel($uuid);
$visibleExtraItemActions = array_filter(
$extraItemActions,
fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
);
@endphp
<tr
wire:key="{{ $this->getId() }}.{{ $row->getStatePath() }}.{{ $field::class }}.item"
x-sortable-item="{{ $uuid }}"
Expand Down Expand Up @@ -145,31 +165,45 @@ class="filament-table-repeater-row md:divide-x md:divide-gray-950/5 dark:md:divi

@if ($hasActions)
<td class="filament-table-repeater-column p-2 w-px">
<div class="flex items-center gap-2 md:justify-center">
<ul class="flex items-center gap-x-3 lg:justify-center">
@foreach ($visibleExtraItemActions as $extraItemAction)
<li>
{{ $extraItemAction(['item' => $uuid]) }}
</li>
@endforeach

@if ($reorderAction->isVisible())
<div x-sortable-handle>
<li x-sortable-handle class="shrink-0">
{{ $reorderAction }}
</div>
</li>
@endif

@if ($isReorderableWithButtons)
@if (! $loop->first)
<li>
{{ $moveUpAction(['item' => $uuid]) }}
</li>
@endif

@if (! $loop->last)
<li>
{{ $moveDownAction(['item' => $uuid]) }}
</li>
@endif
@endif

@if ($cloneAction->isVisible())
<li>
{{ $cloneAction(['item' => $uuid]) }}
</li>
@endif

@if ($deleteAction->isVisible())
<li>
{{ $deleteAction(['item' => $uuid]) }}
</li>
@endif
</div>
</ul>
</td>
@endif

Expand Down

0 comments on commit e02f186

Please sign in to comment.