Icon Button

Displays an icon-only button for compact actions.

Installation

npx alixan-ui-nuxt add icon-button

Usage

IconButton uses the same variant and color system as Button, but keeps the control square for icon-only actions.

Filled

Outlined

Ghost

<script setup lang="ts">
import { ArrowUpRight } from '@lucide/vue'
import IconButton from '@/components/ui/icon-button/IconButton.vue'
</script>

<template>
  <div class="space-y-4">
    <div class="flex flex-wrap items-center gap-2">
      <IconButton variant="filled" color="default">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="filled" color="primary">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="filled" color="secondary">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="filled" color="destructive">
        <ArrowUpRight />
      </IconButton>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <IconButton variant="outlined" color="default">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="outlined" color="primary">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="outlined" color="secondary">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="outlined" color="destructive">
        <ArrowUpRight />
      </IconButton>
    </div>

    <div class="flex flex-wrap items-center gap-2">
      <IconButton variant="ghost" color="default">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="ghost" color="primary">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="ghost" color="secondary">
        <ArrowUpRight />
      </IconButton>
      <IconButton variant="ghost" color="destructive">
        <ArrowUpRight />
      </IconButton>
    </div>
  </div>
</template>

Size

<script setup lang="ts">
import { ArrowUpRight } from '@lucide/vue'
import IconButton from '@/components/ui/icon-button/IconButton.vue'
</script>

<template>
  <div class="flex items-center gap-2">
    <IconButton size="sm">
      <ArrowUpRight />
    </IconButton>
    <IconButton>
      <ArrowUpRight />
    </IconButton>
    <IconButton size="lg">
      <ArrowUpRight />
    </IconButton>
  </div>
</template>

Loading

IconButton does not include an inline spinner. Inline loading can leave the user free to navigate away and lose the action context. Use a global loader when the operation should be treated as one blocking action.

<script setup lang="ts">
import { ArrowUpRight } from '@lucide/vue'

const loader = useGlobalLoader()

const save = () => {
  loader.show({ label: 'Saving action...' })

  window.setTimeout(() => {
    loader.hide()
  }, 3000)
}
</script>

<template>
  <IconButton @click="save">
    <ArrowUpRight />
  </IconButton>
</template>

Disabled

Do not make the icon action silent and unavailable. Keep it active, then show a warning dialog that explains what the user needs to do.

<script setup lang="ts">
import { ArrowUpRight } from '@lucide/vue'

const dialog = useDialog()

const openAlert = () => {
  dialog.open(AlertDialog, {
    width: '360px',
    height: '280px',
    data: {
      title: 'componentDocs.iconButton.actionUnavailable',
      description: 'componentDocs.iconButton.exportUnavailable',
      buttonLabel: 'componentDocs.iconButton.gotIt',
    },
  })
}
</script>

<template>
  <IconButton variant="outlined" @click="openAlert">
    <ArrowUpRight />
  </IconButton>
</template>

API Reference

PropTypeDefaultDescription
variant'filled' | 'outlined' | 'ghost''ghost'Visual style of the icon button. Ghost is used by default.
color'default' | 'primary' | 'secondary' | 'destructive''default'Color intent.
size'sm' | 'md' | 'lg''md'Controls square size and icon size.
toRouteLocationRaw-Renders the icon button as a NuxtLink when provided.
hrefstring-Renders the icon button as a native anchor when provided.
target'_blank' | '_self' | '_parent' | '_top'-Anchor target. Works with href links.
tooltipstring-Tooltip content. Values can be translation keys.