๐ข Breadcrumb
Basic
NBreadcrumb
- use to display the path of the current page and the hierarchy of previous routes/links.
Prop | Type | Default | Description |
---|---|---|---|
items | Array | [] | The array of Links that wrapped around NButton component, which means that all the props and slots of NButton are available to use. |
Variant & Color
Prop | Type | Default | Description |
---|---|---|---|
breadcrumb-active | {variant}-{color} | text-primary | The active breadcrumb variant and color. |
breadcrumb-inactive | {variant}-{color} | text-muted | The inactive breadcrumb variant and color. |
You can use any variant and colors provided by the NButton component, just make sure to use
breadcrumb-active
and breadcrumb-inactive
as a prefix instead of btn
.or
or
Separator
Prop | Type | Default | Description |
---|---|---|---|
separator | String | i-radix-icons-chevron-right | The separator icon. |
You can use any icon provided by the NIcon component, the default is
i-radix-icons-chevron-right
.Size
Prop | Type | Default | Description |
---|---|---|---|
size | String | sm | The size of the breadcrumb. This will be applied to all the breadcrumb components. |
_breadcrumbLink.size | String | sm | The size of the breadcrumb link. |
_breadcrumbSeparator.size | String | sm | The size of the breadcrumb separator. |
๐ You can freely adjust the size of the breadcrumb using any size imaginable. No limits exist, and you can use
breakpoints
such assm:sm, xs:lg
to change size based on screen size orstates
such ashover:lg, focus:3xl
to change size based on input state and more.
or
Slots
You can use the following slots to customize the breadcrumb.
Name | Description | Props |
---|---|---|
default | The breadcrumb item | item |
separator | The separator | item |
root | The root breadcrumb | items |
list | The list of items | item |
Props
import type { HTMLAttributes } from 'vue'
import type { NButtonProps } from './button'
interface BaseExtensions { class?: HTMLAttributes['class'] }
export interface NBreadcrumbProps extends BaseExtensions, Pick<NBreadcrumbLinkProps, 'breadcrumbActive' | 'breadcrumbInactive'> {
/**
* List of items to display in the breadcrumb.
*
* @example
* items: [{ label: 'Home', to: '/' }, { label: 'About', to: '/about' }]
*/
items: Partial<NButtonProps>[]
separator?: NBreadcrumbSeparatorProps['icon']
ellipsis?: NBreadcrumbEllipsisProps['icon']
/**
* Allows you to change the size of the input.
*
* @default sm
*
* @example
* size="sm" | size="2cm" | size="2rem" | size="2px"
*/
size?: string
// maxItems?: number
// sub-components
_breadcrumbSeparator?: Partial<NBreadcrumbSeparatorProps>
_breadcrumbItem?: Partial<NBreadcrumbItemProps>
_breadcrumbRoot?: Partial<NBreadcrumbRootProps>
_breadcrumbList?: Partial<NBreadcrumbListProps>
_breadcrumbLink?: Partial<NBreadcrumbLinkProps>
_breadcrumbEllipsis?: Partial<NBreadcrumbEllipsisProps>
/**
* `UnaUI` preset configuration
*
* @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/breadcrumb.ts
*/
una?: NBreadcrumbUnaProps
}
export interface NBreadcrumbRootProps extends BaseExtensions {
una?: Pick<NBreadcrumbUnaProps, 'breadcrumbRoot'>
}
export interface NBreadcrumbItemProps extends BaseExtensions {
/**
* `UnaUI` preset configuration
*
* @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/breadcrumb.ts
*/
una?: Pick<NBreadcrumbUnaProps, 'breadcrumbItem'>
}
export interface NBreadcrumbSeparatorProps extends BaseExtensions {
/**
* Custom separator icon.
*/
icon?: string
/**
* Allows you to change the size of the input.
*
* @default sm
*
* @example
* size="sm" | size="2cm" | size="2rem" | size="2px"
*/
size?: string
/**
* `UnaUI` preset configuration
*
* @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/breadcrumb.ts
*/
una?: Pick<NBreadcrumbUnaProps, 'breadcrumbSeparator' | 'breadcrumbSeparatorIcon'>
}
export interface NBreadcrumbListProps extends BaseExtensions {
/**
* `UnaUI` preset configuration
*
* @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/breadcrumb.ts
*/
una?: Pick<NBreadcrumbUnaProps, 'breadcrumbList'>
}
export interface NBreadcrumbLinkProps extends BaseExtensions, NButtonProps {
active?: boolean
breadcrumbActive?: string
breadcrumbInactive?: string
}
export interface NBreadcrumbEllipsisProps extends BaseExtensions {
/**
* Custom separator icon.
*/
icon?: string
/**
* /**
* Allows you to change the size of the input.
*
* @default sm
*
* @example
* size="sm" | size="2cm" | size="2rem" | size="2px"
*/
size?: string
/**
* `UnaUI` preset configuration
*
* @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/breadcrumb.ts
*/
una?: Pick<NBreadcrumbUnaProps, 'breadcrumbEllipsis' | 'breadcrumbEllipsisIcon'>
}
interface NBreadcrumbUnaProps {
breadcrumb?: HTMLAttributes['class']
breadcrumbRoot?: HTMLAttributes['class']
breadcrumbItem?: HTMLAttributes['class']
breadcrumbEllipsis?: HTMLAttributes
breadcrumbEllipsisIcon?: HTMLAttributes['class']
breadcrumbList?: HTMLAttributes['class']
breadcrumbSeparator?: HTMLAttributes['class']
breadcrumbSeparatorIcon?: HTMLAttributes['class']
}
Presets
type BreadcrumbPrefix = 'breadcrumb'
export const staticBreadcrumb: Record<`${BreadcrumbPrefix}-${string}` | BreadcrumbPrefix, string> = {
// config
'breadcrumb': '',
'breadcrumb-active': 'breadcrumb-active-text-primary',
'breadcrumb-inactive': 'breadcrumb-inactive-text-muted',
'breadcrumb-separator-icon': 'i-radix-icons-chevron-right',
'breadcrumb-elipsis-icon': 'i-radix-icons-dots-horizontal',
// components
'breadcrumb-root': '',
'breadcrumb-list': 'flex flex-wrap items-center break-words text-muted',
'breadcrumb-link': 'transition-colors font-normal',
'breadcrumb-item': 'inline-flex items-center gap-1.5',
// TODO
'breadcrumb-ellipsis': 'flex items-center justify-center',
}
export const dynamicBreadcrumb = [
// states
[
/^breadcrumb-active-([^-]+)-([^-]+)$/,
([, variant = 'text', color = 'primary']) =>
`data-[state=active]:btn-${variant}-${color}`,
],
[
/^breadcrumb-inactive-([^-]+)-([^-]+)$/,
([, variant = 'text', color = 'muted']) =>
`data-[state=inactive]:btn-${variant}-${color}`,
],
]
export const breadcrumb = [
...dynamicBreadcrumb,
staticBreadcrumb,
]
Component
<script lang="ts" setup>
import type { NBreadcrumbProps } from '../../../types'
import { cn } from '../../../utils'
import BreadcrumbItem from './BreadcrumbItem.vue'
import BreadcrumbLink from './BreadcrumbLink.vue'
import BreadcrumbList from './BreadcrumbList.vue'
import BreadcrumbRoot from './BreadcrumbRoot.vue'
import BreadcrumbSeparator from './BreadcrumbSeparator.vue'
const props = defineProps<NBreadcrumbProps>()
</script>
<template>
<BreadcrumbRoot
:class="cn(
'breadcrumb',
props.class,
props.una?.breadcrumb,
)"
:una
:size
v-bind="_breadcrumbRoot"
>
<slot name="root" :items="items">
<BreadcrumbList
:una
:size
v-bind="_breadcrumbList"
>
<template
v-for="(item, i) in props.items"
:key="i"
>
<slot name="list" :item="item">
<BreadcrumbItem
:una
:size
v-bind="_breadcrumbItem"
>
<slot name="item" :item="item">
<BreadcrumbLink
:active="i === items.length - 1"
:breadcrumb-active="props.breadcrumbActive"
:breadcrumb-inactive="props.breadcrumbInactive"
:size
v-bind="{
...item,
..._breadcrumbLink,
}"
>
<slot :item="item" />
</BreadcrumbLink>
</slot>
</BreadcrumbItem>
<BreadcrumbSeparator
v-if="i < props.items!.length - 1"
:icon="props.separator"
:size
:una
v-bind="_breadcrumbSeparator"
>
<slot name="separator" />
</BreadcrumbSeparator>
</slot>
</template>
</BreadcrumbList>
</slot>
</BreadcrumbRoot>
</template>