DashboardSidebarCollapse

ButtonGitLab
Um Button para recolher a sidebar no desktop.

Uso

O componente DashboardSidebarCollapse é usado para recolher/expandir o componente DashboardSidebar quando a prop collapsible dele está definida.

<template>
  <NDashboardSidebarCollapse />
</template>

Ele estende o componente Button, então você pode passar qualquer propriedade como color, variant, size, etc.

<template>
  <NDashboardSidebarCollapse variant="subtle" />
</template>
O botão usa por padrão color="neutral" e variant="ghost".

Exemplos

Dentro do slot header

Você pode colocar este componente no slot header do componente DashboardSidebar e usar a prop collapsed para ocultar a parte esquerda do cabeçalho, por exemplo:

layouts/dashboard.vue
<template>
  <NDashboardGroup>
    <NDashboardSidebar collapsible>
      <template #header="{ collapsed }">
        <Logo v-if="!collapsed" />

        <NDashboardSidebarCollapse variant="subtle" />
      </template>
    </NDashboardSidebar>

    <slot />
  </NDashboardGroup>
</template>

Dentro do slot leading

Você pode colocar este componente no slot leading do componente DashboardNavbar para exibi-lo antes do título, por exemplo:

pages/index.vue
<script setup lang="ts">
definePageMeta({
  layout: 'dashboard'
})
</script>

<template>
  <NDashboardPanel>
    <template #header>
      <NDashboardNavbar title="Home">
        <template #leading>
          <NDashboardSidebarCollapse variant="subtle" />
        </template>
      </NDashboardNavbar>
    </template>
  </NDashboardPanel>
</template>

API

Props

Prop Default Type
as'button'any

The element or component this component should render as when not a link.

color'neutral' "error" | "neutral" | "primary" | "secondary" | "accent" | "success" | "info" | "warning"
variant'ghost' "ghost" | "solid" | "outline" | "soft" | "subtle" | "link"
side'left' "left" | "right"

The side of the sidebar to collapse.

autofocus false | true | "true" | "false"
disabledboolean
name string
type'button' "reset" | "submit" | "button"

The type of the button when not a link.

label string
activeColor "error" | "neutral" | "primary" | "secondary" | "accent" | "success" | "info" | "warning"
activeVariant "ghost" | "solid" | "outline" | "soft" | "subtle" | "link"
size'md' "xs" | "sm" | "md" | "lg" | "xl"
squareboolean

Render the button with equal padding on all sides.

blockboolean

Render the button full width.

loadingAutoboolean

Set loading state automatically based on the @click promise state

iconany

Display an icon based on the leading and trailing props.

avatar AvatarProps

Display an avatar on the left side.

leadingboolean

When true, the icon will be displayed on the left side.

leadingIconany

Display an icon on the left side.

trailingboolean

When true, the icon will be displayed on the right side.

trailingIconany

Display an icon on the right side.

loadingboolean

When true, the loading icon will be displayed.

loadingIconappConfig.ui.icons.loadingany

The icon when the loading prop is true.

ui { base?: any; }
Este componente também suporta todos os atributos HTML nativos de <button>.

Tema

app.config.ts
export default defineAppConfig({
  ui: {
    dashboardSidebarCollapse: {
      base: 'hidden lg:flex',
      variants: {
        side: {
          left: '',
          right: ''
        }
      }
    }
  }
})
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: {
        dashboardSidebarCollapse: {
          base: 'hidden lg:flex',
          variants: {
            side: {
              left: '',
              right: ''
            }
          }
        }
      }
    })
  ]
})

Changelog

No recent changes