Skip to content

Commit e0fda58

Browse files
committed
Add initial logic for rendering the context menu
1 parent 5aa57e0 commit e0fda58

File tree

2 files changed

+116
-3
lines changed

2 files changed

+116
-3
lines changed

resources/assets/scripts/components/server/components/FileManagerFileRow.vue

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<div class="row" :class="{ clickable: canEdit(file) }">
3+
<div class="row" :class="{ clickable: canEdit(file) }" v-on:contextmenu="showContextMenu">
44
<div class="flex-none icon">
55
<file-text-icon v-if="!file.symlink"/>
66
<link2-icon v-else/>
@@ -10,26 +10,106 @@
1010
<div class="flex-1 text-right text-grey-dark">{{formatDate(file.modified)}}</div>
1111
<div class="flex-none w-1/6"></div>
1212
</div>
13+
<div class="context-menu" v-show="contextMenuVisible" ref="contextMenu">
14+
<div>
15+
<div class="context-row">
16+
<div class="icon"><edit3-icon/></div>
17+
<div class="action"><span>Rename</span></div>
18+
</div>
19+
<div class="context-row">
20+
<div class="icon"><corner-up-left-icon class="h-4"/></div>
21+
<div class="action"><span class="text-left">Move</span></div>
22+
</div>
23+
<div class="context-row">
24+
<div class="icon"><copy-icon class="h-4"/></div>
25+
<div class="action">Copy</div>
26+
</div>
27+
</div>
28+
<div>
29+
<div class="context-row">
30+
<div class="icon"><file-plus-icon class="h-4"/></div>
31+
<div class="action">New File</div>
32+
</div>
33+
<div class="context-row">
34+
<div class="icon"><folder-plus-icon class="h-4"/></div>
35+
<div class="action">New Folder</div>
36+
</div>
37+
</div>
38+
<div>
39+
<div class="context-row">
40+
<div class="icon"><download-icon class="h-4"/></div>
41+
<div class="action">Download</div>
42+
</div>
43+
<div class="context-row danger">
44+
<div class="icon"><delete-icon class="h-4"/></div>
45+
<div class="action">Delete</div>
46+
</div>
47+
</div>
48+
</div>
1349
</div>
1450
</template>
1551

1652
<script>
17-
import { FileTextIcon, Link2Icon } from 'vue-feather-icons';
53+
import { CopyIcon, CornerUpLeftIcon, DeleteIcon, DownloadIcon, Edit3Icon, FileTextIcon, FilePlusIcon, FolderPlusIcon, Link2Icon } from 'vue-feather-icons';
1854
import * as Helpers from './../../../helpers/index';
1955
2056
export default {
2157
name: 'file-manager-file-row',
22-
components: { FileTextIcon, Link2Icon },
58+
components: {
59+
CopyIcon, CornerUpLeftIcon, DeleteIcon, DownloadIcon,
60+
Edit3Icon, FileTextIcon, FilePlusIcon, FolderPlusIcon,
61+
Link2Icon,
62+
},
2363
props: {
2464
file: {type: Object, required: true},
2565
editable: {type: Array, required: true}
2666
},
2767
68+
data: function () {
69+
return {
70+
listener: null,
71+
contextMenuVisible: false,
72+
};
73+
},
74+
2875
mounted: function () {
76+
// Handle a click anywhere in the document and hide the context menu if that click is not
77+
// a right click and isn't occurring somewhere in the currently visible context menu.
78+
this.listener = document.addEventListener('click', (e) => {
79+
if (e.button !== 2
80+
&& this.contextMenuVisible
81+
&& e.target !== this.$refs.contextMenu
82+
&& !this.$refs.contextMenu.contains(e.target)
83+
) {
84+
this.contextMenuVisible = false;
85+
}
86+
});
2987
88+
// If the parent component emits the collapse menu event check if the unique ID of the component
89+
// is this one. If not, collapse the menu (we right clicked into another element).
90+
this.$parent.$on('collapse-menus', (uid) => {
91+
if (this._uid !== uid) {
92+
this.contextMenuVisible = false;
93+
}
94+
})
95+
},
96+
97+
beforeDestroy: function () {
98+
document.removeEventListener('click', this.listener);
3099
},
31100
32101
methods: {
102+
/**
103+
* Handle a right-click action on a file manager row.
104+
*
105+
* @param {Event} e
106+
*/
107+
showContextMenu: function (e) {
108+
e.preventDefault();
109+
this.$parent.$emit('collapse-menus', this._uid);
110+
this.contextMenuVisible = !this.contextMenuVisible;
111+
},
112+
33113
/**
34114
* Determine if a file can be edited on the Panel.
35115
*

resources/assets/styles/components/filemanager.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@
2929
}
3030
}
3131
}
32+
33+
.context-menu {
34+
@apply .absolute .bg-white .py-2 .border .rounded .text-grey-darker .text-sm .cursor-pointer;
35+
36+
& > div:not(:last-of-type) {
37+
@apply .border-b .border-grey-lightest .pb-2 .mb-2;
38+
}
39+
40+
& .context-row {
41+
@apply .flex .flex-row .items-center .py-2 .px-8 .border-t .border-b .border-transparent;
42+
43+
& > .icon {
44+
@apply .flex-none;
45+
46+
& > svg {
47+
@apply .h-4;
48+
}
49+
}
50+
51+
& > .action {
52+
@apply .flex-auto .pl-2;
53+
}
54+
55+
&:hover {
56+
@apply .bg-grey-lightest .border-t .border-b .border-grey-lighter;
57+
}
58+
59+
&.danger:hover {
60+
@apply .bg-red-lightest .border-t .border-b .border-red-lighter;
61+
}
62+
63+
}
64+
}
3265
}
3366

3467
.filemanager-breadcrumbs {

0 commit comments

Comments
 (0)