Files

135 lines
6.2 KiB
PHP

{{--
Reloadable body of a product listing — result count + sort, product grid +
pagination, and the filter sidebar. Shared by the category page (scoped to a
collection) and the all-products page. Rendered on full load and on every
turbo-frame navigation, straight from the query string.
Vars (all from App\Catalog\ProductListingPage::build):
$products (LengthAwarePaginator), $sortOptions (array),
$listing (App\Catalog\ProductListing), $listingAction (string, GET form target),
$clearPriceUrl (?string), $priceFloor / $priceCeil (?int)
--}}
<div class="grid grid-cols-1 lg:grid-cols-[1fr_230px] gap-14">
<div class="flex items-center justify-between gap-x-6 gap-y-4 flex-wrap mb-7">
<x-shop.result-count :paginator="$products" />
<div class="flex items-center gap-6">
{{-- Opens the filters drawer below `lg`; at `lg` the sidebar is always shown. --}}
<button
type="button"
popovertarget="shop-filters"
aria-controls="shop-filters"
class="inline-flex items-center gap-2 font-display font-bold uppercase italic lg:hidden"
>
<x-ui.icon name="filter" :size="20" />
<span class="underline-slide [--slide-h:1px]">{{ __('storefront.shop.filters') }}</span>
</button>
<x-shop.sort :options="$sortOptions" id="shop-sort" />
</div>
</div>
<div class="hidden lg:block"></div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-[1fr_230px] gap-14">
{{-- Products --}}
<div>
@if($products->isEmpty())
<p class="text-neutral-500">{{ __('storefront.shop.no_products') }}</p>
@else
<x-product-grid :products="$products->items()" cols="3" />
<div class="mt-12">
<x-ui.pagination :paginator="$products" />
</div>
@endif
</div>
{{-- Sidebar — sort, price and in-stock are wired to the back-end; product
search lives in the nav overlay, not here.
Below `lg` it's a [popover] drawer (.drawer slide-in from the left),
opened by the Filters button above; the lg: utilities undo the
popover's fixed positioning so at `lg` it's a plain, always-visible
sidebar. Changes only auto-submit at `lg` — in the drawer they wait for
Apply, and the frame reload that follows closes the drawer. --}}
<aside
id="shop-filters"
popover
aria-label="{{ __('storefront.shop.filters') }}"
class="drawer fixed inset-y-0 left-0 right-auto m-0 h-dvh max-h-dvh w-full max-w-sm overflow-y-auto border-0 border-r border-black bg-neutral-200 p-0 text-black lg:static lg:block lg:h-auto lg:max-h-none lg:w-auto lg:max-w-none lg:overflow-visible lg:border-r-0 lg:bg-transparent lg:transform-none"
>
<div class="flex flex-col gap-10 px-5 py-6 sm:px-8 lg:p-0">
<button
type="button"
popovertarget="shop-filters"
popovertargetaction="hide"
class="flex items-center justify-center w-10 h-10 -ml-2 hover:opacity-70 transition-opacity lg:hidden"
aria-label="{{ __('storefront.nav.close') }}"
>
<x-ui.icon name="close" :size="32" />
</button>
{{-- Filter form: a plain GET form whose fields ARE the state. Changing
any control auto-submits (auto-submit controller); Turbo captures
the GET, navigates the frame, and advances the URL. `sort` rides
along as a hidden field so it survives a filter change; `page` is
deliberately absent, so filtering drops back to page 1. Without JS
(or in the drawer) the submit button applies the range inputs. --}}
<form
method="get"
action="{{ $listingAction }}"
data-controller="auto-submit"
data-auto-submit-media-value="(min-width: 64rem)"
data-action="change->auto-submit#submit range-slider:change->auto-submit#submit"
class="contents"
>
@if ($listing->sort)
<input type="hidden" name="sort" value="{{ $listing->sort->value }}" />
@endif
@if ($priceFloor !== null && $priceCeil !== null && $priceCeil > $priceFloor)
<div class="flex flex-col gap-4 -mt-2">
<p class="font-extrabold text-h4">{{ __('storefront.shop.filter_price') }}</p>
<x-ui.range-slider
name="price"
:min="$priceFloor"
:max="$priceCeil"
:min-value="max($priceFloor, $listing->minPrice ?? $priceFloor)"
:max-value="min($priceCeil, $listing->maxPrice ?? $priceCeil)"
prefix="€"
separator=" - "
:legend="__('storefront.shop.filter_price')"
:min-label="__('storefront.shop.price_min')"
:max-label="__('storefront.shop.price_max')"
>
@if ($clearPriceUrl)
<a
href="{{ $clearPriceUrl }}"
class="underline-slide [--slide-h:1px] font-display text-sm font-bold uppercase italic"
>{{ __('storefront.shop.reset') }}</a>
@endif
</x-ui.range-slider>
</div>
@endif
<div class="flex flex-col gap-4 [&_label]:text-base">
<p class="font-extrabold text-h4">{{ __('storefront.shop.availability') }}</p>
<x-ui.checkbox id="shop-in-stock" name="in_stock" :checked="$listing->inStockOnly">
{{ __('storefront.shop.in_stock_only') }}
</x-ui.checkbox>
</div>
<x-ui.button type="submit" size="md" class="self-start lg:sr-only">{{ __('storefront.shop.apply') }}</x-ui.button>
</form>
</div>
</aside>
</div>