-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
DiffFileTreeItem.vue
149 lines (132 loc) · 3.26 KB
/
DiffFileTreeItem.vue
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<template>
<div v-show="show" class="tooltip" :title="item.name">
<!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
<div class="item" :class="item.isFile ? 'filewrapper gt-p-1' : ''">
<!-- Files -->
<SvgIcon
v-if="item.isFile"
data-position="right center"
name="octicon-file"
class="svg-icon file"
/>
<a
v-if="item.isFile"
class="file gt-ellipsis muted"
:href="item.isFile ? '#diff-' + item.file.NameHash : ''"
>{{ item.name }}</a>
<SvgIcon
v-if="item.isFile"
data-position="right center"
:name="getIconForDiffType(item.file.Type)"
:class="['svg-icon', getIconForDiffType(item.file.Type), 'status']"
/>
<!-- Directories -->
<div v-if="!item.isFile" class="directory gt-p-1" @click.stop="handleClick(item.isFile)">
<SvgIcon
class="svg-icon"
:name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'"
/>
<SvgIcon
class="svg-icon directory"
name="octicon-file-directory-fill"
/>
<span class="gt-ellipsis">{{ item.name }}</span>
</div>
<div v-show="!collapsed">
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem" class="list" />
</div>
</div>
</div>
</template>
<script>
import {SvgIcon} from '../svg.js';
export default {
components: {SvgIcon},
props: {
item: {
type: Object,
required: true
},
show: {
type: Boolean,
required: false,
default: true
}
},
data: () => ({
collapsed: false,
}),
methods: {
handleClick(itemIsFile) {
if (itemIsFile) {
return;
}
this.collapsed = !this.collapsed;
},
getIconForDiffType(pType) {
const diffTypes = {
1: 'octicon-diff-added',
2: 'octicon-diff-modified',
3: 'octicon-diff-removed',
4: 'octicon-diff-renamed',
5: 'octicon-diff-modified', // there is no octicon for copied, so modified should be ok
};
return diffTypes[pType];
},
},
};
</script>
<style scoped>
span.svg-icon.status {
float: right;
}
span.svg-icon.file {
color: var(--color-secondary-dark-7);
}
span.svg-icon.directory {
color: var(--color-primary);
}
span.svg-icon.octicon-diff-modified {
color: var(--color-yellow);
}
span.svg-icon.octicon-diff-added {
color: var(--color-green);
}
span.svg-icon.octicon-diff-removed {
color: var(--color-red);
}
span.svg-icon.octicon-diff-renamed {
color: var(--color-teal);
}
.item.filewrapper {
display: grid !important;
grid-template-columns: 20px 7fr 1fr;
padding-left: 18px !important;
}
.item.filewrapper:hover {
color: var(--color-text);
background: var(--color-hover);
border-radius: 4px;
}
div.directory {
display: grid;
grid-template-columns: 18px 20px auto;
user-select: none;
cursor: pointer;
}
div.directory:hover {
color: var(--color-text);
background: var(--color-hover);
border-radius: 4px;
}
div.list {
padding-bottom: 0 !important;
padding-top: inherit !important;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
</style>