Skip to content

Commit

Permalink
Solving issue #14 feat: add breadcrumb component (#28)
Browse files Browse the repository at this point in the history
* Added Breadcrumb component

* feat: breadcrumb improved

---------

Co-authored-by: Anwarul Islam <[email protected]>
  • Loading branch information
The-x-35 and anwarulislam authored Aug 19, 2024
1 parent 25144be commit a996760
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/components/Breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<nav>
<ul
class="flex items-center overflow-x-auto whitespace-nowrap px-4 py-2 text-tiny"
>
<li
v-for="(item, index) in items"
:key="index"
:class="{ 'last-item': index === items.length - 1 }"
class="flex items-center"
@click="emit('select', { item, index })"
>
<span v-if="index < items.length - 1">
{{ item }}
</span>

<span v-else>
{{ item }}
</span>

<span v-if="index < items.length - 1" class="mx-2">
<IconChevronRight />
</span>
</li>
</ul>
</nav>
</template>

<script setup lang="ts">
import IconChevronRight from "~icons/lucide/chevron-right"
defineProps<{
items: string[]
}>()
const emit = defineEmits<{
(
e: "select",
value: {
item: string
index: number
},
): void
}>()
</script>
3 changes: 2 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from "./button"
export * from "./smart"
export * from "./modal"
export * from "./toast"
export { default as HoppBadge } from "./Badge.vue"
export { default as HoppBreadcrumb } from "./Breadcrumb.vue"
export { default as HoppBadge } from "./Badge.vue"
18 changes: 18 additions & 0 deletions src/stories/Breadcrumb.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<Story title="Breadcrumb">
<Variant title="Single">
<HoppBreadcrumb
:items="['Home', 'Library', 'Data']"
@select="onBreadcrumbSelect"
/>
</Variant>
</Story>
</template>

<script setup lang="ts">
import { HoppBreadcrumb } from "../components"
const onBreadcrumbSelect = (value: { item: string; index: number }) => {
alert(`Selected: ${value.item} at index: ${value.index}`)
}
</script>

0 comments on commit a996760

Please sign in to comment.