Custom buttons
The toolbar takes buttons of your own — download, share, anything. They sit before the built-in ones, look the same and get the current image when clicked. The prev / next arrows can be replaced by your own components altogether.



Open an image: two buttons of its own in the toolbar, and Nuxt UI buttons as arrows.
Add a button
Wrap a gallery in <ImageViewerGroup> and give it the buttons — they show up in the viewer opened by a click on any image inside:
<script setup lang="ts">
import type { ImageViewerButton } from 'nuxt-image-viewer'
defineProps<{ photos: { src: string, width: number, height: number }[] }>()
// Only for the viewer of this gallery
const download: ImageViewerButton = {
name: 'download',
label: 'Download',
icon: 'i-lucide-download',
onClick: ({ item }) => {
const link = document.createElement('a')
link.href = item.src
link.download = ''
link.click()
},
}
</script>
<template>
<ImageViewerGroup :options="{ buttons: [download] }">
<ZoomImage v-for="photo in photos" :key="photo.src" v-bind="photo" />
</ImageViewerGroup>
</template>
<ImageViewerGroup> is a data-image-viewer-group with options of its own: it takes everything open() takes — buttons, arrows, loop, ui, labels — for this gallery only. Render it as another tag with as="section".
On the whole site, without groups
Buttons the whole site needs go into a client plugin with configure() — then every viewer has them, no <ImageViewerGroup> needed:
// For every viewer on the site: a click on any <ZoomImage>, and open() from code
export default defineNuxtPlugin(() => {
useImageViewer().configure({
buttons: [
{
name: 'download',
label: 'Download',
icon: 'i-lucide-download',
onClick: ({ item }) => window.open(item.src),
},
],
})
})
They can't live in nuxt.config: buttons hold functions, and nuxt.config is serialized to JSON.
From code
When the viewer is opened with open(), pass the buttons to it:
// For this one viewer only, opened from code
const viewer = useImageViewer()
viewer.open(photos, 0, { buttons: [download] })
The closer setting wins: open() and a group's options over configure(), configure() over nuxt.config. Buttons replace the ones from further away — buttons: [] opens a viewer without them.
Icon
An icon name, as in <UIcon name>, is drawn by Nuxt Icon — Nuxt UI includes it. Any icon set of Iconify works: i-lucide-download, i-heroicons-share, lucide:download.
Without Nuxt Icon, or for icons from elsewhere, pass a component — an icon library, your own SFC or a render function:
<script setup lang="ts">
import { Download } from 'lucide-vue-next'
import type { ImageViewerButton } from 'nuxt-image-viewer'
defineProps<{ photos: { src: string, width: number, height: number }[] }>()
const download: ImageViewerButton = {
name: 'download',
label: 'Download',
icon: Download,
onClick: ({ item }) => window.open(item.src),
}
</script>
<template>
<ImageViewerGroup :options="{ buttons: [download] }">
<ZoomImage v-for="photo in photos" :key="photo.src" v-bind="photo" />
</ImageViewerGroup>
</template>
The icon is sized by --image-viewer-icon-size and drawn by Nuxt Icon or the component itself, filled or stroked.
Text
With text the button becomes a pill with that text, which is also its accessible name. An icon can go next to it:
<script setup lang="ts">
import type { ImageViewerButton } from 'nuxt-image-viewer'
defineProps<{ photos: { src: string, width: number, height: number }[] }>()
const share: ImageViewerButton = {
name: 'share',
text: 'Share',
icon: 'i-lucide-share-2',
onClick: ({ item }) => navigator.share?.({ url: new URL(item.src, location.href).href }),
}
</script>
<template>
<ImageViewerGroup :options="{ buttons: [share] }">
<ZoomImage v-for="photo in photos" :key="photo.src" v-bind="photo" />
</ImageViewerGroup>
</template>
Fields
.image-viewer__button--download.text.icon.text it defaults to the text.{ item, index, close }: the current ImageViewerSlide, its index and a function that closes the viewer.TypeScript checks the combinations: a button without icon and text, or an icon-only one without label, doesn't compile.
Your own arrows
Replace the built-in prev / next arrows with your own buttons — a UButton, your own component, anything. They need nothing bound to them: the viewer puts them in the arrow's place, scrolls when they're clicked, hides them on touch screens and when the mouse rests, and gives an icon-only button its accessible name from labels.
At the ends of a strip that isn't endless (loop: false, or fewer than three images) your arrow stays and looks disabled: its wrapper gets aria-disabled="true" — dimmed, a not-allowed cursor, no clicks, left out of the Tab round. Restyle it with .image-viewer__arrow--own[aria-disabled="true"].
In one gallery
Write the arrows as #prev and #next slots of the group — no separate files, no imports:




Open an image: Back and Next are Nuxt UI buttons from the template. The strip isn't endless — Back is off on the first image, Next on the last.
<script setup lang="ts">
// The #prev and #next slots: arrows only for the viewer of this gallery
defineProps<{ photos: { src: string, width: number, height: number }[] }>()
</script>
<template>
<ImageViewerGroup :options="{ loop: false }">
<ZoomImage v-for="photo in photos" :key="photo.src" v-bind="photo" />
<template #prev>
<UButton icon="i-lucide-arrow-left" label="Back" size="lg" />
</template>
<template #next>
<UButton trailing-icon="i-lucide-arrow-right" label="Next" size="lg" />
</template>
</ImageViewerGroup>
</template>
On the whole site, without groups
Set the arrows once in a client plugin: every viewer gets them — a click on any <ZoomImage>, in a group or not, and open() from code. In a .ts file components come from #components:
import { UButton } from '#components'
// For every viewer on the site: no <ImageViewerGroup> needed anywhere
export default defineNuxtPlugin(() => {
useImageViewer().configure({
controls: {
prev: () => h(UButton, { icon: 'i-lucide-arrow-left', size: 'xl' }),
next: () => h(UButton, { icon: 'i-lucide-arrow-right', size: 'xl' }),
},
})
})
An arrow here is any component: a render function as above, or your own SFC — controls: { next: ViewerNext }.
From code
// For this one viewer only, opened from code
const viewer = useImageViewer()
viewer.open(photos, 0, {
controls: {
next: () => h(UButton, { icon: 'i-lucide-arrow-right' }),
},
})
The closer setting wins, arrow by arrow: a gallery with its own #next keeps the prev from the plugin.
Styling the place
The arrow sits in a .image-viewer__arrow wrapper — --prev or --next — which positions it at the edge of the screen. Move it with your own CSS:
.image-viewer__arrow--next {
top: auto;
bottom: 24px;
transform: none;
}
Styling
Custom buttons have the same classes as the built-in ones — .image-viewer__button and the CSS variables — plus their own modifier; a button with a text also gets --has-text:
.image-viewer__button--share {
--image-viewer-button-bg: var(--ui-primary);
}