페이지 앵커
페이지 앵커 (PageAnchors)
페이지에 표시할 앵커(링크) 목록을 보여주는 컴포넌트예요. 문서 사이트의 사이드바 위에 주요 링크를 배치하는 데 유용합니다.
출처: Nuxt UI
본문
PageAnchors 컴포넌트를 사용해 링크 목록을 표시해요.
<script setup lang="ts">
import type { PageAnchor } from '@nuxt/ui'
const links = ref<PageAnchor[]>([
{
label: "Documentation",
icon: "i-lucide-book-open",
to: "/docs/getting-started"
},
{
label: "Components",
icon: "i-lucide-box",
to: "/docs/components"
},
{
label: "Figma Kit",
icon: "i-simple-icons-figma",
to: "https://go.nuxt.com/figma-ui",
target: "_blank"
},
{
label: "Releases",
icon: "i-simple-icons-github",
to: "https://github.com/nuxt/ui/releases",
target: "_blank"
}
])
</script>
<template>
<UPageAnchors :links="links" />
</template>
링크 (Links)
links prop을 아래 속성을 가진 객체 배열로 사용해 주세요:
label: stringicon?: stringclass?: anyui?: { item?: ClassNameValue, link?: ClassNameValue, linkLabel?: ClassNameValue, linkLabelExternalIcon?: ClassNameValue, linkLeading?: ClassNameValue, linkLeadingIcon?: ClassNameValue }
Link 컴포넌트의 to, target 등 어떤 속성이든 전달할 수 있어요.
<script setup lang="ts">
import type { PageAnchor } from '@nuxt/ui'
const links = ref<PageAnchor[]>([
{
label: "Documentation",
icon: "i-lucide-book-open",
to: "/docs/getting-started"
},
{
label: "Components",
icon: "i-lucide-box",
to: "/docs/components"
},
{
label: "Figma Kit",
icon: "i-simple-icons-figma",
to: "https://go.nuxt.com/figma-ui",
target: "_blank"
},
{
label: "Releases",
icon: "i-simple-icons-github",
to: "https://github.com/nuxt/ui/releases",
target: "_blank"
}
])
</script>
<template>
<UPageAnchors :links="links" />
</template>
예시 (Examples)
[!NOTE]
이 예시들은 Nuxt Content를 사용하지만, 컴포넌트는 어떤 콘텐츠 관리 시스템과도 통합할 수 있어요.
레이아웃 안에서 사용 (Within a layout)
PageAside 컴포넌트 안에 PageAnchors 컴포넌트를 넣어 내비게이션 위에 링크 목록을 표시해요.
<script setup lang="ts">
import type { PageAnchor } from '@nuxt/ui'
import type { ContentNavigationItem } from '@nuxt/content'
const navigation = inject<ContentNavigationItem[]>('navigation')
const links: PageAnchor[] = [{
label: 'Documentation',
icon: 'i-lucide-book-open',
to: '/docs/getting-started'
}, {
label: 'Components',
icon: 'i-lucide-box',
to: '/docs/components'
}, {
label: 'Figma Kit',
icon: 'i-simple-icons-figma',
to: 'https://go.nuxt.com/figma-ui',
target: '_blank'
}, {
label: 'Releases',
icon: 'i-lucide-rocket',
to: 'https://github.com/nuxt/ui/releases',
target: '_blank'
}]
</script>
<template>
<UPage>
<template #left>
<UPageAside>
<UPageAnchors :links="links" />
<USeparator type="dashed" />
<UContentNavigation :navigation="navigation" />
</UPageAside>
</template>
<slot />
</UPage>
</template>
API
Props
/**
* Props for the PageAnchors component
*/
interface PageAnchorsProps {
/**
* The element or component this component should render as.
* @default 'nav'
*/
as?: any;
links?: T[] | undefined;
ui?: { root?: SlotClass; list?: SlotClass; item?: SlotClass; link?: SlotClass; linkLeading?: SlotClass; linkLeadingIcon?: SlotClass; linkLabel?: SlotClass; linkLabelExternalIcon?: SlotClass; } | undefined;
}
Slots
/**
* Slots for the PageAnchors component
*/
interface PageAnchorsSlots {
link(): any;
link-leading(): any;
link-label(): any;
link-trailing(): any;
}
테마 (Theme)
export default defineAppConfig({
ui: {
pageAnchors: {
slots: {
root: '',
list: '',
item: 'relative',
link: 'group text-sm flex items-center gap-1.5 py-1 rounded-sm outline-primary/25 focus-visible:outline-3',
linkLeading: 'rounded-md p-1 inline-flex ring-inset ring',
linkLeadingIcon: 'size-4 shrink-0',
linkLabel: 'truncate',
linkLabelExternalIcon: 'size-3 absolute top-0 text-dimmed'
},
variants: {
active: {
true: {
link: 'text-primary font-semibold',
linkLeading: 'bg-primary ring-primary text-inverted'
},
false: {
link: [
'text-muted hover:text-default font-medium',
'transition-colors'
],
linkLeading: [
'bg-elevated/50 ring-accented text-dimmed group-hover:bg-primary group-hover:ring-primary group-hover:text-inverted',
'transition'
]
}
}
}
}
}
})