forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesktopTreeNode.vue
More file actions
60 lines (54 loc) · 1.77 KB
/
Copy pathDesktopTreeNode.vue
File metadata and controls
60 lines (54 loc) · 1.77 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
<script setup lang="ts">
import type { DesktopFileNode } from '@/stores/desktop'
import { ChevronRight, FileText, Folder } from '@lucide/vue'
import { storeToRefs } from 'pinia'
import { computed, ref } from 'vue'
import { useDesktopStore } from '@/stores/desktop'
const props = defineProps<{ node: DesktopFileNode, depth: number }>()
const desktop = useDesktopStore()
const { currentFilePath } = storeToRefs(desktop)
const expanded = ref(props.depth < 1)
const isActive = computed(() => !props.node.isDir && currentFilePath.value === props.node.path)
const indent = computed(() => `${props.depth * 12 + 8}px`)
function onClick() {
if (props.node.isDir)
expanded.value = !expanded.value
else
desktop.openPath(props.node.path)
}
</script>
<template>
<div>
<button
class="flex w-full items-center gap-1 truncate rounded py-1.5 pr-2 text-left text-[14px] transition-colors hover:bg-black/5 dark:hover:bg-white/10"
:class="isActive ? 'bg-[#d97757]/15 text-[#c15f3c] font-medium' : 'text-foreground/80'"
:style="{ paddingLeft: indent }"
:title="node.name"
:aria-current="isActive ? 'page' : undefined"
@click="onClick"
>
<ChevronRight
v-if="node.isDir"
class="size-3.5 shrink-0 transition-transform"
:class="expanded ? 'rotate-90' : ''"
/>
<Folder
v-if="node.isDir"
class="size-3.5 shrink-0 text-[#d97757]"
/>
<FileText
v-else
class="ml-3.5 size-3.5 shrink-0 opacity-60"
/>
<span class="truncate">{{ node.name }}</span>
</button>
<div v-if="node.isDir && expanded">
<DesktopTreeNode
v-for="child in node.children"
:key="child.path"
:node="child"
:depth="depth + 1"
/>
</div>
</div>
</template>