Gallery
gallery-13
Slider with two square images per view and the next one peeking, arrows on the edges and dots below.
{{--
Every piece of content is a prop. An image is ['src' => ..., 'alt' => ...];
leave src empty to show a placeholder.
Two square images per view with the next one peeking past the container
edge (one per view on mobile). Arrows sit half outside the edges from md
up, dots below.
<x-ui.blocks.gallery-13
heading="Our work"
description="A few recent projects."
:images="[
['src' => '/images/gallery/1.jpg', 'alt' => 'Photo 1'],
['src' => '/images/gallery/2.jpg', 'alt' => 'Photo 2'],
['src' => '/images/gallery/3.jpg', 'alt' => 'Photo 3'],
]"
previous-label="Previous image"
next-label="Next image"
/>
--}}
@props([
'heading' => 'Image Gallery',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'images' => [
['src' => null, 'alt' => 'Placeholder image 1'],
['src' => null, 'alt' => 'Placeholder image 2'],
['src' => null, 'alt' => 'Placeholder image 3'],
['src' => null, 'alt' => 'Placeholder image 4'],
],
'previousLabel' => 'Previous slide',
'nextLabel' => 'Next slide',
'dotLabel' => 'Go to slide',
])
{{-- The slider spans the full section width. Its track is padded (and
scroll-padded) back to the 80rem container edge, so slides line up with
the heading and the neighbours peek into the page margin. --}}
<section {{ $attributes->merge(['class' => 'w-full overflow-hidden bg-background py-16 text-foreground md:py-24 lg:py-28']) }}>
<div class="px-[5%]">
<div class="mx-auto mb-12 flex max-w-3xl flex-col gap-5 text-center md:mb-20 md:gap-6">
<h2 class="text-4xl font-bold leading-[1.2] md:text-5xl">{{ $heading }}</h2>
<p class="text-muted-foreground md:text-lg">{{ $description }}</p>
</div>
</div>
<x-ui.carousel :arrows="false"
track="gap-6 px-[max(5%,calc((100%_-_80rem)/2))] scroll-px-[max(5%,calc((100%_-_80rem)/2))] md:gap-8">
@foreach ($images as $image)
<x-ui.carousel.item
class="relative aspect-square basis-[calc(100%_-_1.5rem)] overflow-hidden bg-muted md:basis-[calc((100%_-_2rem)/2)]">
@if (!empty($image['src']))
<img src="{{ $image['src'] }}" alt="{{ $image['alt'] ?? '' }}"
loading="lazy" class="absolute inset-0 size-full object-cover">
@else
<div role="img" aria-label="{{ $image['alt'] ?? '' }}"
class="absolute inset-0 flex items-center justify-center text-muted-foreground">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round"
class="size-10 md:size-12" aria-hidden="true">
<rect width="18" height="18" x="3" y="3" rx="2" ry="2" />
<circle cx="9" cy="9" r="2" />
<path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" />
</svg>
</div>
@endif
</x-ui.carousel.item>
@endforeach
<x-slot:controls>
{{-- Centred on the slides: half of the dots row (3rem gap + 28px) is taken off. --}}
<x-ui.button variant="outline" size="icon" data-ui-carousel-prev
aria-label="{{ $previousLabel }}"
class="absolute start-[calc(max(5%,calc((100%_-_80rem)/2))_-_1.75rem)] top-[calc(50%_-_38px)] z-10 hidden size-12 -translate-y-1/2 rounded-full md:inline-flex">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" class="size-6 rtl:rotate-180" aria-hidden="true">
<path d="m12 19-7-7 7-7" />
<path d="M19 12H5" />
</svg>
</x-ui.button>
<x-ui.button variant="outline" size="icon" data-ui-carousel-next
aria-label="{{ $nextLabel }}"
class="absolute end-[calc(max(5%,calc((100%_-_80rem)/2))_-_1.75rem)] top-[calc(50%_-_38px)] z-10 hidden size-12 -translate-y-1/2 rounded-full md:inline-flex">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" class="size-6 rtl:rotate-180" aria-hidden="true">
<path d="M5 12h14" />
<path d="m12 5 7 7-7 7" />
</svg>
</x-ui.button>
<div data-ui-carousel-dots data-label="{{ $dotLabel }}"
class="mt-5 flex justify-center gap-2 p-2.5 md:mt-12"></div>
</x-slot:controls>
</x-ui.carousel>
</section>
Installation
php artisan ui:add-block gallery-13
A single command installs the block's Blade file and every component it depends on. Render it in your own layout as
<x-ui.blocks.gallery-13
/>.
1. Install component dependencies
php artisan ui:add button carousel
2. External packages
- composer:
gehrisandro/tailwind-merge-laravel
3.
Copy the block source into
resources/views/components/ui/
resources/views/components/ui/blocks/gallery-13.blade.php
{{--
Every piece of content is a prop. An image is ['src' => ..., 'alt' => ...];
leave src empty to show a placeholder.
Two square images per view with the next one peeking past the container
edge (one per view on mobile). Arrows sit half outside the edges from md
up, dots below.
<x-ui.blocks.gallery-13
heading="Our work"
description="A few recent projects."
:images="[
['src' => '/images/gallery/1.jpg', 'alt' => 'Photo 1'],
['src' => '/images/gallery/2.jpg', 'alt' => 'Photo 2'],
['src' => '/images/gallery/3.jpg', 'alt' => 'Photo 3'],
]"
previous-label="Previous image"
next-label="Next image"
/>
--}}
@props([
'heading' => 'Image Gallery',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'images' => [
['src' => null, 'alt' => 'Placeholder image 1'],
['src' => null, 'alt' => 'Placeholder image 2'],
['src' => null, 'alt' => 'Placeholder image 3'],
['src' => null, 'alt' => 'Placeholder image 4'],
],
'previousLabel' => 'Previous slide',
'nextLabel' => 'Next slide',
'dotLabel' => 'Go to slide',
])
{{-- The slider spans the full section width. Its track is padded (and
scroll-padded) back to the 80rem container edge, so slides line up with
the heading and the neighbours peek into the page margin. --}}
<section {{ $attributes->merge(['class' => 'w-full overflow-hidden bg-background py-16 text-foreground md:py-24 lg:py-28']) }}>
<div class="px-[5%]">
<div class="mx-auto mb-12 flex max-w-3xl flex-col gap-5 text-center md:mb-20 md:gap-6">
<h2 class="text-4xl font-bold leading-[1.2] md:text-5xl">{{ $heading }}</h2>
<p class="text-muted-foreground md:text-lg">{{ $description }}</p>
</div>
</div>
<x-ui.carousel :arrows="false"
track="gap-6 px-[max(5%,calc((100%_-_80rem)/2))] scroll-px-[max(5%,calc((100%_-_80rem)/2))] md:gap-8">
@foreach ($images as $image)
<x-ui.carousel.item
class="relative aspect-square basis-[calc(100%_-_1.5rem)] overflow-hidden bg-muted md:basis-[calc((100%_-_2rem)/2)]">
@if (!empty($image['src']))
<img src="{{ $image['src'] }}" alt="{{ $image['alt'] ?? '' }}"
loading="lazy" class="absolute inset-0 size-full object-cover">
@else
<div role="img" aria-label="{{ $image['alt'] ?? '' }}"
class="absolute inset-0 flex items-center justify-center text-muted-foreground">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round"
class="size-10 md:size-12" aria-hidden="true">
<rect width="18" height="18" x="3" y="3" rx="2" ry="2" />
<circle cx="9" cy="9" r="2" />
<path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" />
</svg>
</div>
@endif
</x-ui.carousel.item>
@endforeach
<x-slot:controls>
{{-- Centred on the slides: half of the dots row (3rem gap + 28px) is taken off. --}}
<x-ui.button variant="outline" size="icon" data-ui-carousel-prev
aria-label="{{ $previousLabel }}"
class="absolute start-[calc(max(5%,calc((100%_-_80rem)/2))_-_1.75rem)] top-[calc(50%_-_38px)] z-10 hidden size-12 -translate-y-1/2 rounded-full md:inline-flex">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" class="size-6 rtl:rotate-180" aria-hidden="true">
<path d="m12 19-7-7 7-7" />
<path d="M19 12H5" />
</svg>
</x-ui.button>
<x-ui.button variant="outline" size="icon" data-ui-carousel-next
aria-label="{{ $nextLabel }}"
class="absolute end-[calc(max(5%,calc((100%_-_80rem)/2))_-_1.75rem)] top-[calc(50%_-_38px)] z-10 hidden size-12 -translate-y-1/2 rounded-full md:inline-flex">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" class="size-6 rtl:rotate-180" aria-hidden="true">
<path d="M5 12h14" />
<path d="m12 5 7 7-7 7" />
</svg>
</x-ui.button>
<div data-ui-carousel-dots data-label="{{ $dotLabel }}"
class="mt-5 flex justify-center gap-2 p-2.5 md:mt-12"></div>
</x-slot:controls>
</x-ui.carousel>
</section>
Usage
Every piece of content is a prop. An image is ['src' => ..., 'alt' => ...]; leave src empty to show a placeholder. Two square images per view with the next one peeking past the container edge (one per view on mobile). Arrows sit half outside the edges from md up, dots below.
<x-ui.blocks.gallery-13
heading="Our work"
description="A few recent projects."
:images="[
['src' => '/images/gallery/1.jpg', 'alt' => 'Photo 1'],
['src' => '/images/gallery/2.jpg', 'alt' => 'Photo 2'],
['src' => '/images/gallery/3.jpg', 'alt' => 'Photo 3'],
]"
previous-label="Previous image"
next-label="Next image"
/>
Props
Every prop with its default. Pass any of them as attributes, using : to bind a PHP value.
@props([
'heading' => 'Image Gallery',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'images' => [
['src' => null, 'alt' => 'Placeholder image 1'],
['src' => null, 'alt' => 'Placeholder image 2'],
['src' => null, 'alt' => 'Placeholder image 3'],
['src' => null, 'alt' => 'Placeholder image 4'],
],
'previousLabel' => 'Previous slide',
'nextLabel' => 'Next slide',
'dotLabel' => 'Go to slide',
])