Jan Hoogeveen
Hoopy frood.
Jan is located at The Netherlands
How to make scaleable image gallery's
export default {
name: 'gallery',
type: 'object',
title: 'Gallery',
fields: [
{
name: 'images',
type: 'array',
title: 'Images',
of: [
{
name: 'image',
type: 'image',
title: 'Image',
options: {
hotspot: true,
},
fields: [
{
name: 'alt',
type: 'string',
title: 'Alternative text',
},
],
},
],
options: {
layout: 'grid',
},
},
{
name: 'display',
type: 'string',
title: 'Display as',
description: 'How should we display these images?',
options: {
list: [
{ title: 'Stacked on top of eachother', value: 'stacked' },
{ title: 'In-line', value: 'inline' },
{ title: 'Carousel', value: 'carousel' },
],
layout: 'radio', // <-- defaults to 'dropdown'
},
},
{
name: 'zoom',
type: 'boolean',
title: 'Zoom enabled',
description: 'Should we enable zooming of images?',
},
],
preview: {
select: {
images: 'images',
image: 'images.0',
},
prepare(selection) {
const { images, image } = selection;
return {
title: `Gallery block of ${Object.keys(images).length} images`,
subtitle: `Alt text: ${image.alt}`,
media: image,
};
},
},
};
Wondering how to make an image gallery in Sanity? Ask no more. This is a snippet I'm using across multiple projects.
You define a list of images including alt-texts, and you can toggle different presentation styles with the click of a button.
With this solution, you should switch image components in your front-end based on the display field.
Hoopy frood.
Feature flags with Sanity and Next.js
Go to Feature flags with Sanity and Next.jsContent operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store