Banner

GitLab
Exiba um banner no topo do seu site para informar os usuários sobre informações importantes.

Uso

Título

Use a prop title para exibir um título no Banner.

<template>
  <NBanner title="This is a banner with an important message." />
</template>

Ícone

Use a prop icon para exibir um ícone no Banner.

<template>
  <NBanner icon="i-lucide-info" title="This is a banner with an icon." />
</template>

Cor

Use a prop color para alterar a cor do Banner.

<template>
  <NBanner color="neutral" icon="i-lucide-info" title="This is a banner with an icon." />
</template>

Fechar

Use a prop close para exibir um Button para dispensar o Banner. O padrão é false.

Um evento close será emitido quando o botão de fechar for clicado.
<template>
  <NBanner id="example" title="This is a closable banner." close />
</template>
Quando fechado, banner-${id} será armazenado no local storage para evitar que ele seja exibido novamente.
Para o exemplo acima, banner-example será armazenado no local storage.
Para persistir o estado de dispensado entre recarregamentos de página, você precisa especificar uma prop id. Sem um id explícito, o banner só ficará oculto na sessão atual e reaparecerá ao recarregar a página.

Ícone de fechar

Use a prop close-icon para personalizar o Icon do botão de fechar. O padrão é i-lucide-x.

<template>
  <NBanner
    title="This is a closable banner with a custom close icon."
    close
    close-icon="i-lucide-x-circle"
  />
</template>
Você pode personalizar esse ícone globalmente no seu app.config.ts na chave ui.icons.close.
Você pode personalizar esse ícone globalmente no seu vite.config.ts na chave ui.icons.close.

Ações

Use a prop actions para adicionar algumas ações de Button ao Banner.

<script setup lang="ts">
import type { ButtonProps } from '@nitro/ui'

const actions = ref<ButtonProps[]>([
  {
    label: 'Action 1',
    variant: 'outline'
  },
  {
    label: 'Action 2',
    trailingIcon: 'i-lucide-arrow-right'
  }
])
</script>

<template>
  <NBanner title="This is a banner with actions." :actions="actions" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ButtonProps } from '@nitro/ui'

const actions = ref<ButtonProps[]>([
  {
    label: 'Action 1',
    variant: 'outline'
  },
  {
    label: 'Action 2',
    trailingIcon: 'i-lucide-arrow-right'
  }
])
</script>

<template>
  <NBanner title="This is a banner with actions." :actions="actions" />
</template>
Os botões de ação usam por padrão color="neutral" e size="xs". Você pode personalizar esses valores passando-os diretamente para cada botão de ação.

Você pode passar qualquer propriedade do componente <NuxtLink>, como to, target, rel, etc.

<template>
  <NBanner
    to="https://nuxtlabs.com/"
    target="_blank"
    title="NuxtLabs is joining Vercel!"
    color="primary"
  />
</template>
O componente NuxtLink herdará todos os outros atributos que você passar para o componente User.

Exemplos

Dentro de app.vue

Use o componente Banner no seu app.vue ou em um layout:

app.vue
<template>
  <NApp>
    <NBanner icon="i-lucide-construction" title="Nitro UI v4 has been released!" />

    <NHeader />

    <NMain>
      <NuxtLayout>
        <NuxtPage />
      </NuxtLayout>
    </NMain>

    <NFooter />
  </NApp>
</template>

API

Props

Prop Default Type
as'div'any

The element or component this component should render as.

id string

A unique id saved to local storage to remember if the banner has been dismissed. Without an explicit id, the banner will not be persisted and will reappear on page reload.

iconany

The icon displayed next to the title.

title string
actions ButtonProps[]

Display a list of actions next to the title. { color: 'neutral', size: 'xs' }

to string | it | et
target null | "_blank" | "_parent" | "_self" | "_top" | string & {}
color'primary' "error" | "primary" | "secondary" | "accent" | "success" | "info" | "warning" | "neutral"
closefalseboolean | Omit<ButtonProps, LinkPropsKeys>

Display a close button to dismiss the banner. { size: 'md', color: 'neutral', variant: 'ghost' }

closeIconappConfig.ui.icons.closeany

The icon displayed in the close button.

ui { root?: SlotClass; container?: SlotClass; left?: SlotClass; center?: SlotClass; right?: SlotClass; icon?: SlotClass; title?: SlotClass; actions?: SlotClass; close?: SlotClass; }

Slots

Slot Type
leading{ ui: object; }
title{}
actions{}
close{ ui: object; }

Emits

Event Type
close[]

Tema

app.config.ts
export default defineAppConfig({
  ui: {
    banner: {
      slots: {
        root: [
          'relative z-50 w-full',
          'transition-colors'
        ],
        container: 'flex items-center justify-between gap-3 h-12',
        left: 'hidden lg:flex-1 lg:flex lg:items-center',
        center: 'flex items-center gap-1.5 min-w-0',
        right: 'lg:flex-1 flex items-center justify-end',
        icon: 'size-5 shrink-0 text-inverted pointer-events-none',
        title: 'text-sm text-inverted font-medium truncate',
        actions: 'flex gap-1.5 shrink-0 isolate',
        close: 'text-inverted hover:bg-default/10 focus-visible:bg-default/10 -me-1.5 lg:me-0'
      },
      variants: {
        color: {
          primary: {
            root: 'bg-primary'
          },
          secondary: {
            root: 'bg-secondary'
          },
          accent: {
            root: 'bg-accent'
          },
          success: {
            root: 'bg-success'
          },
          info: {
            root: 'bg-info'
          },
          warning: {
            root: 'bg-warning'
          },
          error: {
            root: 'bg-error'
          },
          neutral: {
            root: 'bg-inverted'
          }
        },
        to: {
          true: ''
        }
      },
      compoundVariants: [
        {
          color: 'primary',
          to: true,
          class: {
            root: 'hover:bg-primary/90'
          }
        },
        {
          color: 'neutral',
          to: true,
          class: {
            root: 'hover:bg-inverted/90'
          }
        }
      ],
      defaultVariants: {
        color: 'primary'
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        banner: {
          slots: {
            root: [
              'relative z-50 w-full',
              'transition-colors'
            ],
            container: 'flex items-center justify-between gap-3 h-12',
            left: 'hidden lg:flex-1 lg:flex lg:items-center',
            center: 'flex items-center gap-1.5 min-w-0',
            right: 'lg:flex-1 flex items-center justify-end',
            icon: 'size-5 shrink-0 text-inverted pointer-events-none',
            title: 'text-sm text-inverted font-medium truncate',
            actions: 'flex gap-1.5 shrink-0 isolate',
            close: 'text-inverted hover:bg-default/10 focus-visible:bg-default/10 -me-1.5 lg:me-0'
          },
          variants: {
            color: {
              primary: {
                root: 'bg-primary'
              },
              secondary: {
                root: 'bg-secondary'
              },
              accent: {
                root: 'bg-accent'
              },
              success: {
                root: 'bg-success'
              },
              info: {
                root: 'bg-info'
              },
              warning: {
                root: 'bg-warning'
              },
              error: {
                root: 'bg-error'
              },
              neutral: {
                root: 'bg-inverted'
              }
            },
            to: {
              true: ''
            }
          },
          compoundVariants: [
            {
              color: 'primary',
              to: true,
              class: {
                root: 'hover:bg-primary/90'
              }
            },
            {
              color: 'neutral',
              to: true,
              class: {
                root: 'hover:bg-inverted/90'
              }
            }
          ],
          defaultVariants: {
            color: 'primary'
          }
        }
      }
    })
  ]
})
Some colors in compoundVariants are omitted for readability. Check out the source code on GitLab.

Changelog

No recent changes