|
| 1 | +<template> |
| 2 | + <div class="dir-line-wrapper"> |
| 3 | + <button |
| 4 | + @click="isOpen = !isOpen" |
| 5 | + :class="[levelClass, isDir ? 'dir' : 'file']" |
| 6 | + class="dir-line bare" |
| 7 | + > |
| 8 | + <span class="bracket" v-if="!isRoot"> ⌞</span> |
| 9 | + <icon>{{ iconName }}</icon> |
| 10 | + <span class="dir-name-label">{{ path }}</span> |
| 11 | + </button> |
| 12 | + <template v-if="hasChildren"> |
| 13 | + <transition name="expand"> |
| 14 | + <div class="expandable" v-show="isOpen"> |
| 15 | + <dir-line |
| 16 | + v-for="[key, child] in children" |
| 17 | + :struct="child.contents" |
| 18 | + :key="child.fullRelativePath" |
| 19 | + :level="level + 1" |
| 20 | + :path="key" |
| 21 | + :isDir="child.isDir" |
| 22 | + /> |
| 23 | + </div> |
| 24 | + </transition> |
| 25 | + </template> |
| 26 | + </div> |
| 27 | +</template> |
| 28 | + |
| 29 | +<script lang="ts"> |
| 30 | +import Vue, { PropType } from 'vue' |
| 31 | +import { DirStructInside } from '../../models/lib-snapshots' |
| 32 | +
|
| 33 | +export default Vue.extend({ |
| 34 | + name: 'DirLine', |
| 35 | +
|
| 36 | + props: { |
| 37 | + path: { |
| 38 | + type: String, |
| 39 | + required: true, |
| 40 | + }, |
| 41 | +
|
| 42 | + struct: { |
| 43 | + type: Object as PropType<DirStructInside>, |
| 44 | + required: true, |
| 45 | + }, |
| 46 | +
|
| 47 | + level: { |
| 48 | + type: Number, |
| 49 | + required: true, |
| 50 | + }, |
| 51 | +
|
| 52 | + isDir: { |
| 53 | + type: Boolean, |
| 54 | + required: true, |
| 55 | + }, |
| 56 | + }, |
| 57 | +
|
| 58 | + data: () => { |
| 59 | + return { |
| 60 | + isOpen: false, |
| 61 | + } |
| 62 | + }, |
| 63 | +
|
| 64 | + computed: { |
| 65 | + children(): [string, DirStructInside][] { |
| 66 | + return Object.entries(this.struct) |
| 67 | + }, |
| 68 | +
|
| 69 | + hasChildren(): boolean { |
| 70 | + return this.children.length > 0 |
| 71 | + }, |
| 72 | +
|
| 73 | + isRoot(): boolean { |
| 74 | + return this.level === 1 |
| 75 | + }, |
| 76 | +
|
| 77 | + levelClass(): string { |
| 78 | + const evaluatedLevel = Math.min(7, this.level) |
| 79 | +
|
| 80 | + return `dir-level-${evaluatedLevel}` |
| 81 | + }, |
| 82 | +
|
| 83 | + iconName(): string { |
| 84 | + if (!this.isDir) { |
| 85 | + return 'description' |
| 86 | + } |
| 87 | +
|
| 88 | + return this.isOpen ? 'folder_open' : 'folder' |
| 89 | + }, |
| 90 | + }, |
| 91 | +
|
| 92 | + methods: {}, |
| 93 | +}) |
| 94 | +</script> |
0 commit comments