Skip to content

Commit

Permalink
feat(components): added NeBreadCrumbs (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile authored Nov 26, 2024
1 parent 7929115 commit a380765
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/components/NeBreadcrumbs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script generic="T extends BreadcrumbItem" lang="ts" setup>
import { computed } from 'vue'
export type BreadcrumbItem = {
order: number
label: string
}
const { items, separator = '>' } = defineProps<{
items: T[]
separator?: string
}>()
defineEmits<{
click: [item: T]
}>()
const orderedItems = computed<T[]>(() => [...items].sort((a, b) => a.order - b.order))
</script>

<template>
<nav aria-label="Breadcrumb" class="font-medium">
<ul class="flex space-x-1">
<template v-for="(item, index) in orderedItems" :key="item.order">
<li class="space-x-1">
<template v-if="index < orderedItems.length - 1">
<a
class="text-primary-700 hover:text-primary-800 hover:underline dark:text-primary-500 dark:hover:text-primary-400"
href="#"
@click.prevent="$emit('click', item)"
>
{{ item.label }}
</a>
<span>{{ separator }}</span>
</template>
<template v-else>
<span aria-label="page">{{ item.label }}</span>
</template>
</li>
</template>
</ul>
</nav>
</template>

0 comments on commit a380765

Please sign in to comment.