Skip to content

Commit

Permalink
Actually hide hidden builder actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfietje committed May 8, 2024
1 parent ce966e5 commit 6c8cd76
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
44 changes: 28 additions & 16 deletions packages/forms/resources/views/components/builder.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
$isReorderableWithButtons = $isReorderableWithButtons();
$isReorderableWithDragAndDrop = $isReorderableWithDragAndDrop();
$collapseAllActionIsVisible = $isCollapsible && $collapseAllAction->isVisible();
$expandAllActionIsVisible = $isCollapsible && $expandAllAction->isVisible();
$statePath = $getStatePath();
@endphp

Expand All @@ -36,22 +39,22 @@
->class(['fi-fo-builder grid gap-y-4'])
}}
>
@if ($isCollapsible && ($collapseAllAction->isVisible() || $expandAllAction->isVisible()))
@if ($collapseAllActionIsVisible || $expandAllActionIsVisible)
<div
@class([
'flex gap-x-3',
'hidden' => count($containers) < 2,
])
>
@if ($collapseAllAction->isVisible())
@if ($collapseAllActionIsVisible)
<span
x-on:click="$dispatch('builder-collapse', '{{ $statePath }}')"
>
{{ $collapseAllAction }}
</span>
@endif

@if ($expandAllAction->isVisible())
@if ($expandAllActionIsVisible)
<span
x-on:click="$dispatch('builder-expand', '{{ $statePath }}')"
>
Expand Down Expand Up @@ -79,6 +82,15 @@ class="space-y-4"
$extraItemActions,
fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
);
$cloneAction = $cloneAction(['item' => $uuid]);
$cloneActionIsVisible = $isCloneable && $cloneAction->isVisible();
$deleteAction = $deleteAction(['item' => $uuid]);
$deleteActionIsVisible = $isDeletable && $deleteAction->isVisible();
$moveDownAction = $moveDownAction(['item' => $uuid])->disabled($loop->last);
$moveDownActionIsVisible = $isReorderableWithButtons && $moveDownAction->isVisible();
$moveUpAction = $moveUpAction(['item' => $uuid])->disabled($loop->first);
$moveUpActionIsVisible = $isReorderableWithButtons && $moveUpAction->isVisible();
$reorderActionIsVisible = $isReorderableWithDragAndDrop && $reorderAction->isVisible();
@endphp

<li
Expand All @@ -93,7 +105,7 @@ class="space-y-4"
class="fi-fo-builder-item rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-white/5 dark:ring-white/10"
x-bind:class="{ 'fi-collapsed overflow-hidden': isCollapsed }"
>
@if ($isReorderableWithDragAndDrop || $isReorderableWithButtons || $hasBlockLabels || $isCloneable || $isDeletable || $isCollapsible || $visibleExtraItemActions)
@if ($reorderActionIsVisible || $moveDownActionIsVisible || $moveUpActionIsVisible || $hasBlockLabels || $cloneActionIsVisible || $deleteActionIsVisible || $isCollapsible || $visibleExtraItemActions)
<div
@if ($isCollapsible)
x-on:click.stop="isCollapsed = !isCollapsed"
Expand All @@ -103,9 +115,9 @@ class="fi-fo-builder-item rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 d
'cursor-pointer select-none' => $isCollapsible,
])
>
@if ($isReorderableWithDragAndDrop || $isReorderableWithButtons)
@if ($reorderActionIsVisible || $moveDownActionIsVisible || $moveUpActionIsVisible)
<ul class="flex items-center gap-x-3">
@if ($isReorderableWithDragAndDrop)
@if ($reorderActionIsVisible)
<li
x-sortable-handle
x-on:click.stop
Expand All @@ -114,13 +126,13 @@ class="fi-fo-builder-item rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 d
</li>
@endif

@if ($isReorderableWithButtons)
@if ($moveUpActionIsVisible || $moveDownActionIsVisible)
<li x-on:click.stop>
{{ $moveUpAction(['item' => $uuid])->disabled($loop->first) }}
{{ $moveUpAction }}
</li>

<li x-on:click.stop>
{{ $moveDownAction(['item' => $uuid])->disabled($loop->last) }}
{{ $moveDownAction }}
</li>
@endif
</ul>
Expand All @@ -141,7 +153,7 @@ class="fi-fo-builder-item rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 d
</h4>
@endif

@if ($isCloneable || $isDeletable || $isCollapsible || $visibleExtraItemActions)
@if ($cloneActionIsVisible || $deleteActionIsVisible || $isCollapsible || $visibleExtraItemActions)
<ul
class="ms-auto flex items-center gap-x-3"
>
Expand All @@ -151,15 +163,15 @@ class="ms-auto flex items-center gap-x-3"
</li>
@endforeach

@if ($isCloneable)
@if ($cloneActionIsVisible)
<li x-on:click.stop>
{{ $cloneAction(['item' => $uuid]) }}
{{ $cloneAction }}
</li>
@endif

@if ($isDeletable)
@if ($deleteActionIsVisible)
<li x-on:click.stop>
{{ $deleteAction(['item' => $uuid]) }}
{{ $deleteAction }}
</li>
@endif

Expand Down Expand Up @@ -198,7 +210,7 @@ class="fi-fo-builder-item-content border-t border-gray-100 p-4 dark:border-white
</li>

@if (! $loop->last)
@if ($isAddable && $addBetweenAction->isVisible())
@if ($isAddable && $addBetweenAction(['afterItem' => $uuid])->isVisible())
<li class="relative -top-2 !mt-0 h-0">
<div
class="flex w-full justify-center opacity-0 transition duration-75 hover:opacity-100"
Expand All @@ -215,7 +227,7 @@ class="fi-fo-builder-block-picker-ctn rounded-lg bg-white dark:bg-gray-900"
:width="$blockPickerWidth"
>
<x-slot name="trigger">
{{ $addBetweenAction }}
{{ $addBetweenAction(['afterItem' => $uuid]) }}
</x-slot>
</x-filament-forms::builder.block-picker>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class="items-start gap-4"
$moveUpAction = $moveUpAction(['item' => $uuid])->disabled($loop->first);
$moveUpActionIsVisible = $isReorderableWithButtons && $moveUpAction->isVisible();
$reorderActionIsVisible = $isReorderableWithDragAndDrop && $reorderAction->isVisible();
$itemHasToolbar = $reorderActionIsVisible || $moveDownActionIsVisible || $moveUpActionIsVisible || filled($itemLabel) || $cloneActionIsVisible || $deleteActionIsVisible || $isCollapsible || $visibleExtraItemActions;
@endphp

<li
Expand All @@ -106,7 +105,7 @@ class="items-start gap-4"
class="fi-fo-repeater-item divide-y divide-gray-100 rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:divide-white/10 dark:bg-white/5 dark:ring-white/10"
x-bind:class="{ 'fi-collapsed overflow-hidden': isCollapsed }"
>
@if ($itemHasToolbar)
@if ($reorderActionIsVisible || $moveDownActionIsVisible || $moveUpActionIsVisible || filled($itemLabel) || $cloneActionIsVisible || $deleteActionIsVisible || $isCollapsible || $visibleExtraItemActions)
<div
@if ($isCollapsible)
x-on:click.stop="isCollapsed = !isCollapsed"
Expand Down

0 comments on commit 6c8cd76

Please sign in to comment.