---
title: "Custom buttons"
description: "Add buttons of your own to the toolbar and put your own arrows in place."
canonical_url: "https://kukson777.github.io/nuxt-image-viewer/docs/customization/custom-buttons"
---
# Custom buttons

> Add buttons of your own to the toolbar and put your own arrows in place.

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.

<custom-buttons-demo>



</custom-buttons-demo>

## 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:

```vue [components/Gallery.vue]
<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()`](https://kukson777.github.io/nuxt-image-viewer/docs/customization/options) 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:

```ts [plugins/image-viewer.client.ts]
// 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()`](https://kukson777.github.io/nuxt-image-viewer/docs/guide/open-from-code), pass the buttons to it:

```ts
// 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](https://nuxt.com/modules/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:

```vue [components/Gallery.vue]
<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:

```vue [components/Gallery.vue]
<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

<field-group>
<field name="name" type="string" :required="true">

Unique name. Also the class modifier: `.image-viewer__button--download`.

</field>

<field name="icon" type="string | Component">

Nuxt Icon name or a component. Required without `text`.

</field>

<field name="text" type="string">

Text on the button. Required without `icon`.

</field>

<field name="label" type="string">

Accessible name. Required for an icon-only button; with `text` it defaults to the text.

</field>

<field name="onClick" type="(context) => void" :required="true">

Called with `{ item, index, close }`: the current [`ImageViewerSlide`](https://kukson777.github.io/nuxt-image-viewer/docs/api/types#imageviewerslide), its index and a function that closes the viewer.

</field>
</field-group>

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`](https://kukson777.github.io/nuxt-image-viewer/docs/customization/options#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:

<arrows-demo>



</arrows-demo>

```vue [components/Gallery.vue]
<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`:

```ts [plugins/image-viewer.client.ts]
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

```ts
// 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:

```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](https://kukson777.github.io/nuxt-image-viewer/docs/customization/theming) — plus their own modifier; a button with a text also gets `--has-text`:

```css
.image-viewer__button--share {
  --image-viewer-button-bg: var(--ui-primary);
}
```


## Sitemap

See the full [sitemap](https://kukson777.github.io/nuxt-image-viewer/sitemap.md) for all pages.
