본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

대시보드 사이드바

원문 보기 위키 갱신

대시보드 사이드바 (DashboardSidebar)

대시보드 사이드바(DashboardSidebar)는 대시보드 레이아웃에 표시하는 사이드바 컴포넌트예요. 드래그로 크기를 조절할 수 있고 상태가 저장되며, DashboardGroup, DashboardPanel, DashboardNavbar 컴포넌트와 함께 사용할 수 있어요.

출처: Nuxt UI

본문

대시보드에 표시하는 크기 조절·접기 가능한 사이드바예요.

사용법 (Usage)

DashboardSidebar 컴포넌트는 대시보드 레이아웃에 사이드바를 표시하는 데 사용해요. 드래그로 크기 조절, 상태 저장을 지원하며 DashboardGroup, DashboardPanel, DashboardNavbar과 연동돼요.

[!TIP] See: /docs/components/sidebar

DashboardSidebar vs Sidebar: DashboardSidebar는 드래그 크기 조절, 상태 저장, DashboardGroup 연동이 필요한 대시보드 레이아웃용이에요. 채팅 패널·설정·내비게이션 같은 단순 독립형 사이드바에는 Sidebar를 사용해요.

사이드바의 상태(크기, 접힘 등)는 여러분이 DashboardGroup 컴포넌트에 전달한 storage와 storage-key prop에 따라 저장돼요.

DashboardGroup 컴포넌트의 기본 슬롯 안에서 사용해요:

<template>
  <UDashboardGroup>
    <UDashboardSidebar />

    <slot />
  </UDashboardGroup>
</template>

[!WARNING]

이 컴포넌트는 resizable prop을 사용할 때 단일 루트 요소를 갖지 않아요. 페이지 전환을 쓰거나 레이아웃에 단일 루트가 필요하다면 컨테이너(예: <div class="flex flex-1">)로 감싸 주세요.

header, default, footer 슬롯으로 사이드바를, body 또는 content 슬롯으로 사이드바 메뉴를 꾸밀 수 있어요.

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

const items: NavigationMenuItem[][] = [[{
  label: 'Home',
  icon: 'i-lucide-house',
  active: true
}, {
  label: 'Inbox',
  icon: 'i-lucide-inbox',
  badge: '4'
}, {
  label: 'Contacts',
  icon: 'i-lucide-users'
}, {
  label: 'Settings',
  icon: 'i-lucide-settings',
  defaultOpen: true,
  children: [{
    label: 'General'
  }, {
    label: 'Members'
  }, {
    label: 'Notifications'
  }]
}], [{
  label: 'Feedback',
  icon: 'i-lucide-message-circle',
  to: 'https://github.com/nuxt-ui-templates/dashboard',
  target: '_blank'
}, {
  label: 'Help & Support',
  icon: 'i-lucide-info',
  to: 'https://github.com/nuxt/ui',
  target: '_blank'
}]]
</script>

<template>
  <UDashboardSidebar collapsible resizable :ui="{ footer: 'border-t border-default' }">
    <template #header="{ collapsed }">
      <Logo v-if="!collapsed" class="h-5 w-auto shrink-0" />
      <UIcon v-else name="i-simple-icons-nuxtdotjs" class="size-5 text-primary mx-auto" />
    </template>

    <template #default="{ collapsed }">
      <UButton
        :label="collapsed ? undefined : 'Search...'"
        icon="i-lucide-search"
        color="neutral"
        variant="outline"
        block
        :square="collapsed"
      >
        <template v-if="!collapsed" #trailing>
          <div class="flex items-center gap-0.5 ms-auto">
            <UKbd value="meta" variant="subtle" />
            <UKbd value="K" variant="subtle" />
          </div>
        </template>
      </UButton>

      <UNavigationMenu
        :collapsed="collapsed"
        :items="items[0]"
        orientation="vertical"
      />

      <UNavigationMenu
        :collapsed="collapsed"
        :items="items[1]"
        orientation="vertical"
        class="mt-auto"
      />
    </template>

    <template #footer="{ collapsed }">
      <UButton
        :avatar="{
          src: 'https://github.com/benjamincanac.png',
          loading: 'lazy' as const
        }"
        :label="collapsed ? undefined : 'Benjamin'"
        color="neutral"
        variant="ghost"
        class="w-full"
        :block="collapsed"
      />
    </template>
  </UDashboardSidebar>
</template>

[!NOTE]

사이드바를 화면 왼쪽 가장자리 근처로 드래그하면 접힐 수 있어요.

Resizable (크기 조절)

resizable prop으로 사이드바 크기를 조절할 수 있게 만들어요.

<template>
  <UDashboardSidebar resizable>
    <Placeholder class="h-96" />
  </UDashboardSidebar>
</template>

Collapsible (접기 가능)

collapsible prop으로 화면 가장자리로 드래그했을 때 사이드바가 접히도록 만들어요.

[!WARNING]

사이드바가 collapsible이 아니라면 DashboardSidebarCollapse 컴포넌트는 효과가 없어요.

<template>
  <UDashboardSidebar resizable collapsible>
    <Placeholder class="h-96" />
  </UDashboardSidebar>
</template>

[!TIP] See: #slots

슬롯 props에서 collapsed 상태를 접근해 사이드바가 접혔을 때의 내용을 꾸밀 수 있어요.

Size (크기)

min-size, max-size, default-size, collapsed-size prop으로 사이드바 크기를 조절할 수 있어요.

<template>
  <UDashboardSidebar resizable collapsible :min-size="22" :default-size="35" :max-size="40" :collapsed-size="0">
    <Placeholder class="h-96" />
  </UDashboardSidebar>
</template>

[!TIP] See: /docs/components/dashboard-group#props

크기는 기본적으로 백분율로 계산돼요. DashboardGroup 컴포넌트의 unit prop으로 바꿀 수 있어요.

[!NOTE]

collapsed-size prop은 기본값이 0이지만, 사이드바에 min-w-16이 있어 항상 보이도록 보장돼요.

Side (위치)

side prop으로 사이드바의 위치를 바꿀 수 있어요. 기본값은 left예요.

<template>
  <UDashboardSidebar side="right" resizable collapsible>
    <Placeholder class="h-96" />
  </UDashboardSidebar>
</template>

Mode (모드)

mode prop으로 사이드바 메뉴의 모드를 바꿀 수 있어요. 기본값은 slideover예요.

body 슬롯으로 메뉴 본문(헤더 아래)을, content 슬롯으로 메뉴 전체를 채울 수 있어요.

[!TIP] See: #props

menu prop으로 사이드바 메뉴를 꾸밀 수 있는데, 선택한 모드에 따라 자동으로 맞춰져요.

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

defineProps<{
  mode: 'drawer' | 'slideover' | 'modal'
}>()

const items: NavigationMenuItem[] = [{
  label: 'Home',
  icon: 'i-lucide-house',
  active: true
}, {
  label: 'Inbox',
  icon: 'i-lucide-inbox'
}, {
  label: 'Contacts',
  icon: 'i-lucide-users'
}]
</script>

<template>
  <UDashboardGroup>
    <UDashboardSidebar :mode="mode">
      <template #header="{ collapsed }">
        <Logo v-if="!collapsed" class="h-5 w-auto" />
        <UIcon v-else name="i-simple-icons-nuxtdotjs" class="size-5 text-primary mx-auto" />
      </template>

      <UNavigationMenu
        :items="items"
        orientation="vertical"
      />
    </UDashboardSidebar>

    <UDashboardPanel>
      <template #header>
        <UDashboardNavbar title="Dashboard" />
      </template>
    </UDashboardPanel>
  </UDashboardGroup>
</template>

[!NOTE]

이 예시들은 모바일에서 사이드바를 보여주기 위해 DashboardGroup, DashboardPanel, DashboardNavbar 컴포넌트를 포함하고 있어요.

Toggle (토글)

toggle prop으로 모바일에서 표시되는 DashboardSidebarToggle 컴포넌트를 꾸밀 수 있어요.

Button 컴포넌트의 속성을 아무거나 전달해 커스텀할 수 있어요.

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

const items: NavigationMenuItem[] = [{
  label: 'Home',
  icon: 'i-lucide-house',
  active: true
}, {
  label: 'Inbox',
  icon: 'i-lucide-inbox'
}, {
  label: 'Contacts',
  icon: 'i-lucide-users'
}]
</script>

<template>
  <UDashboardGroup>
    <UDashboardSidebar
      open
      :toggle="{
        color: 'primary',
        variant: 'subtle',
        class: 'rounded-full'
      }"
    >
      <template #header>
        <Logo class="h-5 w-auto" />
      </template>

      <UNavigationMenu
        :items="items"
        orientation="vertical"
      />
    </UDashboardSidebar>

    <UDashboardPanel>
      <template #header>
        <UDashboardNavbar title="Dashboard" />
      </template>
    </UDashboardPanel>
  </UDashboardGroup>
</template>

Toggle Side (토글 위치)

toggle-side prop으로 토글 버튼의 위치를 바꿀 수 있어요. 기본값은 left예요.

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

const items: NavigationMenuItem[] = [{
  label: 'Home',
  icon: 'i-lucide-house',
  active: true
}, {
  label: 'Inbox',
  icon: 'i-lucide-inbox'
}, {
  label: 'Contacts',
  icon: 'i-lucide-users'
}]
</script>

<template>
  <UDashboardGroup>
    <UDashboardSidebar
      open
      toggle-side="right"
    >
      <template #header>
        <Logo class="h-5 w-auto" />
      </template>

      <UNavigationMenu
        :items="items"
        orientation="vertical"
      />
    </UDashboardSidebar>

    <UDashboardPanel>
      <template #header>
        <UDashboardNavbar title="Dashboard" />
      </template>
    </UDashboardPanel>
  </UDashboardGroup>
</template>

예시 (Examples)

열림 상태 제어하기

open prop이나 v-model:open 디렉티브로 열림 상태를 제어할 수 있어요.

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

const items: NavigationMenuItem[] = [{
  label: 'Home',
  icon: 'i-lucide-house',
  active: true
}, {
  label: 'Inbox',
  icon: 'i-lucide-inbox'
}, {
  label: 'Contacts',
  icon: 'i-lucide-users'
}]

const open = ref(true)

defineShortcuts({
  o: () => open.value = !open.value
})
</script>

<template>
  <UDashboardSidebar v-model:open="open">
    <template #header="{ collapsed }">
      <Logo v-if="!collapsed" class="h-5 w-auto" />
      <UIcon v-else name="i-simple-icons-nuxtdotjs" class="size-5 text-primary mx-auto" />
    </template>

    <UNavigationMenu
      :items="items"
      orientation="vertical"
    />
  </UDashboardSidebar>
</template>

[!NOTE]

이 예시에서는 defineShortcuts를 활용해 O 키를 누르면 DashboardSidebar의 열림 상태를 토글해요.

접힘 상태 제어하기

collapsed prop이나 v-model:collapsed 디렉티브로 접힘 상태를 제어할 수 있어요.

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

const items: NavigationMenuItem[] = [{
  label: 'Home',
  icon: 'i-lucide-house',
  active: true
}, {
  label: 'Inbox',
  icon: 'i-lucide-inbox'
}, {
  label: 'Contacts',
  icon: 'i-lucide-users'
}]

const collapsed = ref(false)

defineShortcuts({
  c: () => collapsed.value = !collapsed.value
})
</script>

<template>
  <UDashboardSidebar v-model:collapsed="collapsed" collapsible>
    <template #header>
      <Logo v-if="!collapsed" class="h-5 w-auto" />
      <UIcon v-else name="i-simple-icons-nuxtdotjs" class="size-5 text-primary mx-auto" />
    </template>

    <UNavigationMenu
      :collapsed="collapsed"
      :items="items"
      orientation="vertical"
    />
  </UDashboardSidebar>
</template>

[!NOTE]

이 예시에서는 defineShortcuts를 활용해 C 키를 누르면 DashboardSidebar의 접힘 상태를 토글해요.

API

Props

/**
 * Props for the DashboardSidebar component
 */
interface DashboardSidebarProps {
  /**
   * The mode of the sidebar menu.
   * @default 'slideover'
   */
  mode?: T | undefined;
  /**
   * The props for the sidebar menu component.
   */
  menu?: DashboardSidebarMenu<T> | undefined;
  /**
   * Customize the toggle button to open the sidebar.
   * `{ color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
   * @default true
   */
  toggle?: boolean | Omit<ButtonProps, LinkPropsKeys> | undefined;
  /**
   * The side to render the toggle button on.
   * @default 'left'
   */
  toggleSide?: "left" | "right" | undefined;
  /**
   * Automatically close when route changes.
   * @default true
   */
  autoClose?: boolean | undefined;
  ui?: { root?: SlotClass; header?: SlotClass; body?: SlotClass; footer?: SlotClass; toggle?: SlotClass; handle?: SlotClass; content?: SlotClass; overlay?: SlotClass; } | undefined;
  /**
   * The id of the panel.
   * @default useId()
   */
  id?: string | undefined;
  /**
   * The side to render the panel on.
   * @default 'left'
   */
  side?: "left" | "right" | undefined;
  /**
   * The minimum size of the panel.
   * @default 10
   */
  minSize?: number | undefined;
  /**
   * The maximum size of the panel.
   * @default 20
   */
  maxSize?: number | undefined;
  /**
   * The default size of the panel.
   * @default 15
   */
  defaultSize?: number | undefined;
  /**
   * Whether to allow the user to resize the panel.
   * @default false
   */
  resizable?: boolean | undefined;
  /**
   * Whether to allow the user to collapse the panel.
   * @default false
   */
  collapsible?: boolean | undefined;
  /**
   * The size of the panel when collapsed.
   * @default 0
   */
  collapsedSize?: number | undefined;
  /**
   * @default false
   */
  open?: boolean | undefined;
  /**
   * @default false
   */
  collapsed?: boolean | undefined;
}

Slots

/**
 * Slots for the DashboardSidebar component
 */
interface DashboardSidebarSlots {
  header(): any;
  default(): any;
  footer(): any;
  toggle(): any;
  content(): any;
  resize-handle(): any;
}

테마 (Theme)

export default defineAppConfig({
  ui: {
    dashboardSidebar: {
      slots: {
        root: 'relative hidden lg:flex flex-col min-h-svh min-w-16 w-(--width) shrink-0',
        header: 'h-(--ui-header-height) shrink-0 flex items-center gap-1.5 px-4',
        body: 'flex flex-col gap-4 flex-1 overflow-y-auto px-4 py-2',
        footer: 'shrink-0 flex items-center gap-1.5 px-4 py-2',
        toggle: '',
        handle: '',
        content: 'lg:hidden',
        overlay: 'lg:hidden'
      },
      variants: {
        menu: {
          true: {
            header: 'sm:px-6',
            body: 'sm:px-6',
            footer: 'sm:px-6'
          }
        },
        side: {
          left: {
            root: 'border-e border-default'
          },
          right: {
            root: ''
          }
        },
        toggleSide: {
          left: {
            toggle: ''
          },
          right: {
            toggle: 'ms-auto'
          }
        }
      }
    }
  }
})

변경 기록 (Changelog)

컴포넌트와 테마의 커밋 히스토리를 확인해 보세요.

더 알아보기 (Learn more)