-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBreadCrumbs.vue
More file actions
69 lines (62 loc) · 1.47 KB
/
Copy pathBreadCrumbs.vue
File metadata and controls
69 lines (62 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
<RouterLink
v-for="(parent, index) in displayedParents"
:key="index"
:to="`/note/${parent.id}`"
class="breadcrumb"
>
{{ parentTitle(parent.content) }}
<Icon
v-if="index < displayedParents.length - 1"
name="ChevronRight"
/>
</RouterLink>
</template>
<script setup lang="ts">
import { getTitle } from '@/infrastructure/utils/note.ts';
import { RouterLink } from 'vue-router';
import { computed } from 'vue';
import { Note } from '@/domain/entities/Note.ts';
import { Icon } from '@codexteam/ui/vue';
import { OutputData } from '@editorjs/editorjs';
const props = defineProps<{
noteParents: (Note | { id: string; content: string })[];
}>();
/**
* Note parents hierarchy
* If there are more than 3, only the closest & the furthest ones are shown
*/
const displayedParents = computed(() => {
if (props.noteParents.length > 3) {
return [
props.noteParents[0],
{ id: '',
content: null },
props.noteParents[props.noteParents.length - 1],
];
}
return props.noteParents;
});
/**
* title of the parent
*
* @param content - parent's content, could be
*/
const parentTitle = computed(() => {
return (content: string | null | OutputData) => {
if (content === null) {
return '...';
}
if (typeof content === 'string') {
return content;
}
return getTitle(content);
};
});
</script>
<style scoped>
.breadcrumb {
display: inline-flex;
align-items: center;
}
</style>