-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFileListRow.vue
More file actions
153 lines (137 loc) · 4.18 KB
/
FileListRow.vue
File metadata and controls
153 lines (137 loc) · 4.18 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
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
150
151
152
153
<!--
- SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<tr :tabindex="(showCheckbox && !isDirectory) ? undefined : 0"
:aria-selected="!isPickable ? undefined : selected"
:class="['file-picker__row', {
'file-picker__row--selected': selected && !showCheckbox
}]"
:data-filename="node.basename"
data-testid="file-list-row"
v-on="{
click: handleClick,
/* same as tabindex -> if we hide the checkbox or this is a directory we need keyboard access to enter the directory or select the node */
...(!showCheckbox || isDirectory ? { keydown: handleKeyDown } : {}),
}">
<td v-if="showCheckbox" class="row-checkbox" @click.stop="() => {/* Stop the click event */}">
<NcCheckboxRadioSwitch :aria-label="t('Select the row for {nodename}', { nodename: displayName })"
:model-value="selected"
:disabled="!isPickable"
data-testid="row-checkbox"
@update:model-value="toggleSelected" />
</td>
<td class="row-name">
<div class="file-picker__name-container" data-testid="row-name">
<FilePreview :node="node" :crop-image-previews="cropImagePreviews" />
<div class="file-picker__file-name" :title="displayName" v-text="displayName" />
<div class="file-picker__file-extension" v-text="fileExtension" />
</div>
</td>
<td class="row-size">
{{ formatFileSize(node.size || 0) }}
</td>
<td class="row-modified">
<NcDateTime :timestamp="node.mtime" :ignore-seconds="true" />
</td>
</tr>
</template>
<script setup lang="ts">
import type { Node } from '@nextcloud/files'
import { formatFileSize, FileType } from '@nextcloud/files'
import { NcCheckboxRadioSwitch, NcDateTime } from '@nextcloud/vue'
import { computed } from 'vue'
import { t } from '../../utils/l10n'
import FilePreview from './FilePreview.vue'
const props = defineProps<{
/** Can directories be picked */
allowPickDirectory: boolean
/** Is this node currently selected */
selected: boolean
/** Whether to show the checkbox in first column */
showCheckbox: boolean
/** Whether the node can be picked */
canPick: boolean
/** The current node */
node: Node
/** Whether the preview should be cropped */
cropImagePreviews: boolean
}>()
const emit = defineEmits<{
/** Emitted when the selected state is changed */
(e: 'update:selected', v: boolean): void
/** Emitted when a directory was not selected but entered */
(e: 'enter-directory', node: Node): void
}>()
/**
* The displayname of the current node (excluding file extension)
*/
const displayName = computed(() => props.node.attributes?.displayName || props.node.basename.slice(0, props.node.extension ? -props.node.extension.length : undefined))
/**
* The file extension of the file
*/
const fileExtension = computed(() => props.node.extension)
/**
* Check if the node is a directory
*/
const isDirectory = computed(() => props.node.type === FileType.Folder)
/**
* If this node can be picked, basically just check if picking a directory is allowed
*/
const isPickable = computed(() => props.canPick && (props.allowPickDirectory || !isDirectory.value))
/**
* Toggle the selection state
*/
function toggleSelected() {
emit('update:selected', !props.selected)
}
/**
* Handle clicking the table row, if it is a directory it is opened, else selected
*/
function handleClick() {
if (isDirectory.value) {
emit('enter-directory', props.node)
} else {
toggleSelected()
}
}
/**
* Handle keydown on the table row, pressing the enter key will be similar to clicking for keyboard navigation
* @param event The Keydown event
*/
function handleKeyDown(event: KeyboardEvent) {
if (event.key === 'Enter') {
handleClick()
}
}
</script>
<style scoped lang="scss">
@use './FileList.scss';
.file-picker {
&__row {
&--selected {
background-color: var(--color-background-dark);
}
&:hover {
background-color: var(--color-background-hover);
}
}
&__name-container {
display: flex;
justify-content: start;
align-items: center;
height: 100%;
}
&__file-name {
padding-inline-start: 6px;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
&__file-extension {
color: var(--color-text-maxcontrast);
min-width: fit-content;
}
}
</style>