브레드크럼
브레드크럼 (Breadcrumb)
브레드크럼(Breadcrumb)은 웹사이트 안에서 현재 위치가 어디인지 보여주는 이동 경로 컴포넌트예요. 사이트의 계층 구조를 링크로 표시해 사용자가 어디에 있는지 쉽게 파악하고 상위 페이지로 돌아가도록 도와줘요.
출처: Nuxt UI
본문
웹사이트를 탐색하기 위한 링크의 계층 구조예요.
사용법 (Usage)
브레드크럼 컴포넌트로 현재 페이지가 사이트 계층 구조에서 어디에 위치하는지 보여줄 수 있어요.
<script setup lang="ts">
import type { BreadcrumbItem } from '@nuxt/ui'
const items = ref<BreadcrumbItem[]>([
{
label: "Docs",
icon: "i-lucide-book-open",
to: "/docs"
},
{
label: "Components",
icon: "i-lucide-box",
to: "/docs/components"
},
{
label: "Breadcrumb",
icon: "i-lucide-link",
to: "/docs/components/breadcrumb"
}
])
</script>
<template>
<UBreadcrumb :items="items" />
</template>
Items (항목들)
items prop에는 아래 속성들을 가진 객체 배열을 전달해요:
label?: stringicon?: stringavatar?: AvatarPropsslot?: stringclass?: anyui?: { item?: ClassNameValue, link?: ClassNameValue, linkLeadingIcon?: ClassNameValue, linkLeadingAvatar?: ClassNameValue, linkLabel?: ClassNameValue, separator?: ClassNameValue, separatorIcon?: ClassNameValue }
Link 컴포넌트의 속성(to, target 등)을 모두 그대로 전달할 수 있어요.
<script setup lang="ts">
import type { BreadcrumbItem } from '@nuxt/ui'
const items = ref<BreadcrumbItem[]>([
{
label: "Docs",
icon: "i-lucide-book-open",
to: "/docs"
},
{
label: "Components",
icon: "i-lucide-box",
to: "/docs/components"
},
{
label: "Breadcrumb",
icon: "i-lucide-link",
to: "/docs/components/breadcrumb"
}
])
</script>
<template>
<UBreadcrumb :items="items" />
</template>
[!NOTE]
to속성이 없으면 링크 대신span이 렌더링돼요.
Separator Icon (구분 아이콘)
separator-icon prop으로 각 항목 사이에 표시되는 Icon을 바꿀 수 있어요. 기본값은 i-lucide-chevron-right이에요.
<script setup lang="ts">
import type { BreadcrumbItem } from '@nuxt/ui'
const items = ref<BreadcrumbItem[]>([
{
label: "Docs",
icon: "i-lucide-book-open",
to: "/docs"
},
{
label: "Components",
icon: "i-lucide-box",
to: "/docs/components"
},
{
label: "Breadcrumb",
icon: "i-lucide-link",
to: "/docs/components/breadcrumb"
}
])
</script>
<template>
<UBreadcrumb separator-icon="i-lucide-arrow-right" :items="items" />
</template>
Nuxt:
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
You can customize this icon globally in your
app.config.tsunderui.icons.chevronRightkey.
Vue:
[!TIP] See: /docs/getting-started/integrations/icons/vue#theme
You can customize this icon globally in your
vite.config.tsunderui.icons.chevronRightkey.
Color (색상) 4.8+
color prop으로 활성화된 브레드크럼의 색상을 바꿀 수 있어요.
<script setup lang="ts">
import type { BreadcrumbItem } from '@nuxt/ui'
const items = ref<BreadcrumbItem[]>([
{
label: "Docs",
icon: "i-lucide-book-open",
to: "/docs"
},
{
label: "Components",
icon: "i-lucide-box",
to: "/docs/components"
},
{
label: "Breadcrumb",
icon: "i-lucide-link",
to: "/docs/components/breadcrumb"
}
])
</script>
<template>
<UBreadcrumb color="secondary" :items="items" />
</template>
예시 (Examples)
separator 슬롯 사용하기
#separator 슬롯으로 각 항목 사이의 구분 요소를 바꿀 수 있어요.
<script setup lang="ts">
import type { BreadcrumbItem } from '@nuxt/ui'
const items: BreadcrumbItem[] = [
{
label: 'Docs',
to: '/docs'
},
{
label: 'Components',
to: '/docs/components'
},
{
label: 'Breadcrumb',
to: '/docs/components/breadcrumb'
}
]
</script>
<template>
<UBreadcrumb :items="items">
<template #separator>
<span class="mx-2 text-muted">/</span>
</template>
</UBreadcrumb>
</template>
커스텀 슬롯 사용하기
slot 속성으로 특정 항목만 다르게 꾸밀 수 있어요.
다음 슬롯들을 사용할 수 있어요:
#{{ item.slot }}#{{ item.slot }}-leading#{{ item.slot }}-label#{{ item.slot }}-trailing
<script setup lang="ts">
import type { BreadcrumbItem } from '@nuxt/ui'
const items = [
{
label: 'Home',
to: '/'
},
{
slot: 'dropdown' as const,
icon: 'i-lucide-ellipsis',
children: [
{
label: 'Documentation',
to: '/docs'
},
{
label: 'Themes'
},
{
label: 'GitHub'
}
]
},
{
label: 'Components',
to: '/docs/components'
},
{
label: 'Breadcrumb',
to: '/docs/components/breadcrumb'
}
] satisfies BreadcrumbItem[]
</script>
<template>
<UBreadcrumb :items="items">
<template #dropdown="{ item }">
<UDropdownMenu :items="item.children">
<UButton :icon="item.icon" color="neutral" variant="link" class="p-0.5" />
</UDropdownMenu>
</template>
</UBreadcrumb>
</template>
[!TIP] See: #slots
#item,#item-leading,#item-label,#item-trailing슬롯을 사용해 모든 항목을 일괄로 꾸밀 수도 있어요.
API
Props
/**
* Props for the Breadcrumb component
*/
interface BreadcrumbProps {
/**
* The element or component this component should render as.
* @default 'nav'
*/
as?: any;
items?: T[] | undefined;
/**
* The icon to use as a separator.
* @default appConfig.ui.icons.chevronRight
*/
separatorIcon?: any;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* The key used to get the label from the item.
* @default 'label'
*/
labelKey?: keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>> | undefined;
ui?: { root?: SlotClass; list?: SlotClass; item?: SlotClass; link?: SlotClass; linkLeadingIcon?: SlotClass; linkLeadingAvatar?: SlotClass; linkLeadingAvatarSize?: SlotClass; linkLabel?: SlotClass; separator?: SlotClass; separatorIcon?: SlotClass; } | undefined;
}
Slots
/**
* Slots for the Breadcrumb component
*/
interface BreadcrumbSlots {
item(): any;
item-leading(): any;
item-label(): any;
item-trailing(): any;
separator(): any;
}
테마 (Theme)
export default defineAppConfig({
ui: {
breadcrumb: {
slots: {
root: 'relative min-w-0',
list: 'flex items-center gap-1.5',
item: 'flex min-w-0',
link: 'group relative flex items-center gap-1.5 text-sm min-w-0 rounded-md',
linkLeadingIcon: 'shrink-0 size-5',
linkLeadingAvatar: 'shrink-0',
linkLeadingAvatarSize: '2xs',
linkLabel: 'truncate',
separator: 'flex',
separatorIcon: 'shrink-0 size-5 text-muted'
},
variants: {
active: {
true: {
link: 'font-semibold'
},
false: {
link: 'text-muted font-medium'
}
},
disabled: {
true: {
link: 'cursor-not-allowed opacity-75'
}
},
to: {
true: ''
},
color: {
primary: {
link: 'outline-primary/25 focus-visible:outline-3'
},
secondary: {
link: 'outline-secondary/25 focus-visible:outline-3'
},
success: {
link: 'outline-success/25 focus-visible:outline-3'
},
info: {
link: 'outline-info/25 focus-visible:outline-3'
},
warning: {
link: 'outline-warning/25 focus-visible:outline-3'
},
error: {
link: 'outline-error/25 focus-visible:outline-3'
},
neutral: {
link: 'outline-inverted/25 focus-visible:outline-3'
}
}
},
compoundVariants: [
{
disabled: false,
active: false,
to: true,
class: {
link: [
'hover:text-default',
'transition-colors'
]
}
},
{
color: 'primary',
active: true,
class: {
link: 'text-primary'
}
},
{
color: 'secondary',
active: true,
class: {
link: 'text-secondary'
}
},
{
color: 'success',
active: true,
class: {
link: 'text-success'
}
},
{
color: 'info',
active: true,
class: {
link: 'text-info'
}
},
{
color: 'warning',
active: true,
class: {
link: 'text-warning'
}
},
{
color: 'error',
active: true,
class: {
link: 'text-error'
}
},
{
color: 'neutral',
active: true,
class: {
link: 'text-highlighted'
}
}
],
defaultVariants: {
color: 'primary'
}
}
}
})