콘텐츠 내비게이션
콘텐츠 내비게이션 (ContentNavigation)
페이지 링크를 조직화하기 위한 아코디언 스타일 내비게이션 컴포넌트예요. @nuxt/content 모듈과 함께 사용해 문서 사이트의 사이드바 내비게이션을 만듭니다.
출처: Nuxt UI
[!WARNING] See: /docs/getting-started/integrations/content
이 컴포넌트는
@nuxt/content모듈이 설치되어 있을 때만 사용할 수 있어요.
본문
navigation prop에 앱의 내비게이션을 가져올 때 얻는 navigation 값을 전달해 주세요.
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>
<template>
<UContentNavigation :navigation="navigation" highlight />
</template>
타입 (Type)
type prop을 single로 설정하면 한 번에 하나의 항목만 열 수 있게 해요. 기본값은 multiple입니다.
<script setup lang="ts">
import type { ContentNavigationLink } from '@nuxt/ui'
const navigation = ref<ContentNavigationLink[]>([
{
title: "Guide",
icon: "i-lucide-book-open",
path: "#getting-started",
children: [
{
title: "Introduction",
path: "#introduction",
active: true
},
{
title: "Installation",
path: "#installation"
}
]
},
{
title: "Composables",
icon: "i-lucide-database",
path: "#composables",
children: [
{
title: "defineShortcuts",
path: "#defineshortcuts"
},
{
title: "useModal",
path: "#usemodal"
}
]
}
])
</script>
<template>
<UContentNavigation type="single" />
</template>
색상 (Color)
color prop을 사용해 내비게이션 링크의 색상을 바꿔요.
<script setup lang="ts">
import type { ContentNavigationLink } from '@nuxt/ui'
const navigation = ref<ContentNavigationLink[]>([
{
title: "Guide",
icon: "i-lucide-book-open",
path: "#getting-started",
children: [
{
title: "Introduction",
path: "#introduction",
active: true
},
{
title: "Installation",
path: "#installation"
}
]
},
{
title: "Composables",
icon: "i-lucide-database",
path: "#composables",
children: [
{
title: "defineShortcuts",
path: "#defineshortcuts"
},
{
title: "useModal",
path: "#usemodal"
}
]
}
])
</script>
<template>
<UContentNavigation color="neutral" />
</template>
변형 (Variant)
variant prop을 사용해 내비게이션 링크의 변형을 바꿔요.
<script setup lang="ts">
import type { ContentNavigationLink } from '@nuxt/ui'
const navigation = ref<ContentNavigationLink[]>([
{
title: "Guide",
icon: "i-lucide-book-open",
path: "#getting-started",
children: [
{
title: "Introduction",
path: "#introduction",
active: true
},
{
title: "Installation",
path: "#installation"
}
]
},
{
title: "Composables",
icon: "i-lucide-database",
path: "#composables",
children: [
{
title: "defineShortcuts",
path: "#defineshortcuts"
},
{
title: "useModal",
path: "#usemodal"
}
]
}
])
</script>
<template>
<UContentNavigation variant="link" />
</template>
하이라이트 (Highlight)
highlight prop을 사용해 활성 링크에 하이라이트 테두리를 표시해요.
highlight-color prop을 사용해 테두리 색상을 바꿔요. 기본값은 color prop을 따릅니다.
<script setup lang="ts">
import type { ContentNavigationLink } from '@nuxt/ui'
const navigation = ref<ContentNavigationLink[]>([
{
title: "Guide",
icon: "i-lucide-book-open",
path: "#getting-started",
children: [
{
title: "Introduction",
path: "#introduction",
active: true
},
{
title: "Installation",
path: "#installation"
}
]
},
{
title: "Composables",
icon: "i-lucide-database",
path: "#composables",
children: [
{
title: "defineShortcuts",
path: "#defineshortcuts"
},
{
title: "useModal",
path: "#usemodal"
}
]
}
])
</script>
<template>
<UContentNavigation highlight highlight-color="primary" color="primary" variant="pill" />
</template>
꼬리 아이콘 (Trailing Icon)
trailing-icon prop을 사용해 자식이 있는 항목의 꼬리 Icon을 커스터마이즈해요. 기본값은 i-lucide-chevron-down입니다.
<script setup lang="ts">
import type { ContentNavigationLink } from '@nuxt/ui'
const navigation = ref<ContentNavigationLink[]>([
{
title: "Guide",
icon: "i-lucide-book-open",
path: "#getting-started",
children: [
{
title: "Introduction",
path: "#introduction",
active: true
},
{
title: "Installation",
path: "#installation"
}
]
},
{
title: "Composables",
icon: "i-lucide-database",
path: "#composables",
children: [
{
title: "defineShortcuts",
path: "#defineshortcuts"
},
{
title: "useModal",
path: "#usemodal"
}
]
}
])
</script>
<template>
<UContentNavigation trailing-icon="i-lucide-arrow-up" />
</template>
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
이 아이콘은
app.config.ts의ui.icons.chevronDown키 아래에서 전역으로 커스터마이즈할 수 있어요.
예시 (Examples)
레이아웃 안에서 사용 (Within a layout)
레이아웃 안의 PageAside 컴포넌트 안에 ContentNavigation 컴포넌트를 넣어 페이지의 내비게이션을 표시해요:
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>
<template>
<UPage>
<template #left>
<UPageAside>
<UContentNavigation :navigation="navigation" highlight />
</UPageAside>
</template>
<slot />
</UPage>
</template>
헤더 안에서 사용 (Within a header)
Header 컴포넌트의 content 슬롯 안에 ContentNavigation 컴포넌트를 넣어 모바일에서 페이지 내비게이션을 표시해요:
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>
<template>
<UHeader>
<template #body>
<UContentNavigation :navigation="navigation" highlight />
</template>
</UHeader>
</template>
API
Props
/**
* Props for the ContentNavigation component
*/
interface ContentNavigationProps {
/**
* The element or component this component should render as.
* @default 'nav'
*/
as?: any;
/**
* When `true`, the tree will be opened based on the current route.
* When `false`, the tree will be closed.
* When `undefined` (default), the first item will be opened with `type="single"` and the first level will be opened with `type="multiple"`.
* @default undefined
*/
defaultOpen?: boolean | undefined;
/**
* The icon displayed to toggle the accordion.
* @default appConfig.ui.icons.chevronDown
*/
trailingIcon?: any;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* @default 'pill'
*/
variant?: "pill" | "link" | undefined;
/**
* Display a line next to the active link.
* @default false
*/
highlight?: boolean | undefined;
/**
* @default 'primary'
*/
highlightColor?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* When type is "single", prevents closing the open item when clicking its trigger.
* When type is "multiple", disables the collapsible behavior.
* @default true
*/
collapsible?: boolean | undefined;
/**
* @default 0
*/
level?: number | undefined;
navigation?: T[] | undefined;
ui?: { root?: SlotClass; content?: SlotClass; list?: SlotClass; item?: SlotClass; listWithChildren?: SlotClass; itemWithChildren?: SlotClass; trigger?: SlotClass; link?: SlotClass; linkLeadingIcon?: SlotClass; linkTrailing?: SlotClass; linkTrailingBadge?: SlotClass; linkTrailingBadgeSize?: SlotClass; linkTrailingIcon?: SlotClass; linkTitle?: SlotClass; linkTitleExternalIcon?: SlotClass; } | undefined;
/**
* When `true`, prevents the user from interacting with the accordion and all its items
* @default false
*/
disabled?: boolean | undefined;
/**
* Determines whether a "single" or "multiple" items can be selected at a time.
*
* This prop will overwrite the inferred type from `modelValue` and `defaultValue`.
* @default 'multiple'
*/
type?: "single" | "multiple" | undefined;
/**
* When `true`, the element will be unmounted on closed state.
* @default true
*/
unmountOnHide?: boolean | undefined;
}
Slots
/**
* Slots for the ContentNavigation component
*/
interface ContentNavigationSlots {
link(): any;
link-leading(): any;
link-title(): any;
link-trailing(): any;
}
Emits
/**
* Emitted events for the ContentNavigation component
*/
interface ContentNavigationEmits {
update:modelValue: (payload: [value: string | string[] | undefined]) => void;
}
테마 (Theme)
export default defineAppConfig({
ui: {
contentNavigation: {
slots: {
root: '',
content: 'data-[state=open]:animate-[accordion-down_200ms_var(--ease-out)] data-[state=closed]:animate-[accordion-up_200ms_var(--ease-out)] data-[state=closed]:overflow-hidden focus:outline-none',
list: 'isolate -mx-2.5 -mt-1.5',
item: '',
listWithChildren: 'ms-5 border-s border-default',
itemWithChildren: 'flex flex-col data-[state=open]:mb-1.5',
trigger: 'font-semibold',
link: 'group relative w-full px-2.5 py-1.5 before:inset-y-px before:inset-x-0 flex items-center gap-1.5 text-sm before:absolute before:z-[-1] before:rounded-md focus:outline-none focus-visible:outline-none focus-visible:before:outline-3',
linkLeadingIcon: 'shrink-0 size-5',
linkTrailing: 'ms-auto inline-flex gap-1.5 items-center',
linkTrailingBadge: 'shrink-0',
linkTrailingBadgeSize: 'sm',
linkTrailingIcon: 'size-5 transform transition-transform duration-200 ease-out motion-reduce:transition-none shrink-0 group-data-[state=open]:rotate-180',
linkTitle: 'truncate',
linkTitleExternalIcon: 'size-3 align-top text-dimmed'
},
variants: {
color: {
primary: {
link: 'before:outline-primary/25'
},
secondary: {
link: 'before:outline-secondary/25'
},
success: {
link: 'before:outline-success/25'
},
info: {
link: 'before:outline-info/25'
},
warning: {
link: 'before:outline-warning/25'
},
error: {
link: 'before:outline-error/25'
},
neutral: {
link: 'before:outline-inverted/25'
}
},
highlightColor: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
pill: '',
link: ''
},
active: {
true: {
link: 'font-medium'
},
false: {
link: 'text-muted',
linkLeadingIcon: 'text-dimmed'
}
},
disabled: {
true: {
trigger: 'data-[state=open]:text-highlighted'
}
},
highlight: {
true: {}
},
level: {
true: {
item: 'ps-1.5 -ms-px',
itemWithChildren: 'ps-1.5 -ms-px'
}
}
},
compoundVariants: [
{
highlight: true,
level: true,
class: {
link: [
'after:absolute after:-start-1.5 after:inset-y-0.5 after:block after:w-px after:rounded-full',
'after:transition-colors'
]
}
},
{
disabled: false,
active: false,
variant: 'pill',
class: {
link: [
'hover:text-highlighted hover:before:bg-elevated/50 data-[state=open]:text-highlighted',
'transition-colors before:transition-colors'
],
linkLeadingIcon: [
'group-hover:text-default group-data-[state=open]:text-default',
'transition-colors'
]
}
},
{
color: 'primary',
variant: 'pill',
active: true,
class: {
link: 'text-primary',
linkLeadingIcon: 'text-primary group-data-[state=open]:text-primary'
}
},
{
color: 'secondary',
variant: 'pill',
active: true,
class: {
link: 'text-secondary',
linkLeadingIcon: 'text-secondary group-data-[state=open]:text-secondary'
}
},
{
color: 'success',
variant: 'pill',
active: true,
class: {
link: 'text-success',
linkLeadingIcon: 'text-success group-data-[state=open]:text-success'
}
},
{
color: 'info',
variant: 'pill',
active: true,
class: {
link: 'text-info',
linkLeadingIcon: 'text-info group-data-[state=open]:text-info'
}
},
{
color: 'warning',
variant: 'pill',
active: true,
class: {
link: 'text-warning',
linkLeadingIcon: 'text-warning group-data-[state=open]:text-warning'
}
},
{
color: 'error',
variant: 'pill',
active: true,
class: {
link: 'text-error',
linkLeadingIcon: 'text-error group-data-[state=open]:text-error'
}
},
{
color: 'neutral',
variant: 'pill',
active: true,
class: {
link: 'text-highlighted',
linkLeadingIcon: 'text-highlighted group-data-[state=open]:text-highlighted'
}
},
{
variant: 'pill',
active: true,
highlight: false,
class: {
link: 'before:bg-elevated'
}
},
{
variant: 'pill',
active: true,
highlight: true,
disabled: false,
class: {
link: [
'hover:before:bg-elevated/50',
'before:transition-colors'
]
}
},
{
disabled: false,
active: false,
variant: 'link',
class: {
link: [
'hover:text-highlighted data-[state=open]:text-highlighted',
'transition-colors'
],
linkLeadingIcon: [
'group-hover:text-default group-data-[state=open]:text-default',
'transition-colors'
]
}
},
{
color: 'primary',
variant: 'link',
active: true,
class: {
link: 'text-primary',
linkLeadingIcon: 'text-primary group-data-[state=open]:text-primary'
}
},
{
color: 'secondary',
variant: 'link',
active: true,
class: {
link: 'text-secondary',
linkLeadingIcon: 'text-secondary group-data-[state=open]:text-secondary'
}
},
{
color: 'success',
variant: 'link',
active: true,
class: {
link: 'text-success',
linkLeadingIcon: 'text-success group-data-[state=open]:text-success'
}
},
{
color: 'info',
variant: 'link',
active: true,
class: {
link: 'text-info',
linkLeadingIcon: 'text-info group-data-[state=open]:text-info'
}
},
{
color: 'warning',
variant: 'link',
active: true,
class: {
link: 'text-warning',
linkLeadingIcon: 'text-warning group-data-[state=open]:text-warning'
}
},
{
color: 'error',
variant: 'link',
active: true,
class: {
link: 'text-error',
linkLeadingIcon: 'text-error group-data-[state=open]:text-error'
}
},
{
color: 'neutral',
variant: 'link',
active: true,
class: {
link: 'text-highlighted',
linkLeadingIcon: 'text-highlighted group-data-[state=open]:text-highlighted'
}
},
{
highlightColor: 'primary',
highlight: true,
level: true,
active: true,
class: {
link: 'after:bg-primary'
}
},
{
highlightColor: 'secondary',
highlight: true,
level: true,
active: true,
class: {
link: 'after:bg-secondary'
}
},
{
highlightColor: 'success',
highlight: true,
level: true,
active: true,
class: {
link: 'after:bg-success'
}
},
{
highlightColor: 'info',
highlight: true,
level: true,
active: true,
class: {
link: 'after:bg-info'
}
},
{
highlightColor: 'warning',
highlight: true,
level: true,
active: true,
class: {
link: 'after:bg-warning'
}
},
{
highlightColor: 'error',
highlight: true,
level: true,
active: true,
class: {
link: 'after:bg-error'
}
},
{
highlightColor: 'neutral',
highlight: true,
level: true,
active: true,
class: {
link: 'after:bg-inverted'
}
}
],
defaultVariants: {
color: 'primary',
highlightColor: 'primary',
variant: 'pill'
}
}
}
})