Array Previews - How to Add an Image of a Module
You can absolutely add wireframe images to your array item previews! The key is to use a static image in the media property of your preview configuration. Here's how:
Adding Static Wireframe Images
For each module, you can import a static wireframe image and display it in the preview using the prepare function:
// Import your wireframe images at the top of each module file
import module1Wireframe from './wireframes/module1.png'; // or .svg
export default {
name: 'module1',
title: 'Module One',
type: 'document',
fields: [
// ... your fields
],
preview: {
select: {
title: 'moduleTitle',
},
prepare({title}) {
return {
title: title || 'Module One',
subtitle: 'Three column image layout',
media: module1Wireframe // Your static wireframe image
}
}
}
}Using Icons as Fallback
If you want to use icons instead of images, you can import from @sanity/icons:
import { ImageIcon } from '@sanity/icons';
export default {
name: 'module1',
// ... fields
preview: {
select: {
title: 'moduleTitle',
},
prepare({title}) {
return {
title: title || 'Module One',
subtitle: 'Three column image layout',
media: ImageIcon
}
}
}
}Combining Both Approaches
You can even show the actual content images when they exist, but fall back to your wireframe when the module is empty:
import module1Wireframe from './wireframes/module1.png';
export default {
name: 'module1',
// ... fields
preview: {
select: {
title: 'moduleTitle',
contentImage: 'imageLeft' // Select one of the actual images
},
prepare({title, contentImage}) {
return {
title: title || 'Module One',
subtitle: 'Three column image layout',
media: contentImage || module1Wireframe // Show content or wireframe
}
}
}
}The preview configuration documentation explains how the select and prepare functions work together. When users are adding modules to your page builder array, they'll now see your helpful wireframe images in the dropdown list, making it much easier to choose the right module!
Just make sure your wireframe images are imported correctly based on your project structure. SVGs work great for this since they're crisp at any size.
Show original thread13 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.