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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
<template>
<li :data-cy-app-order-element="app.id"
:class="{
'order-selector-element': true,
'order-selector-element--disabled': app.default
}">
<svg width="20"
height="20"
viewBox="0 0 20 20"
role="presentation">
<image preserveAspectRatio="xMinYMin meet"
x="0"
y="0"
width="20"
height="20"
:xlink:href="app.icon"
class="order-selector-element__icon" />
</svg>
<div class="order-selector-element__label">
{{ app.label ?? app.id }}
</div>
<div class="order-selector-element__actions">
<NcButton v-show="!isFirst && !app.default"
ref="buttonUp"
:aria-label="t('settings', 'Move up')"
data-cy-app-order-button="up"
type="tertiary-no-background"
@click="moveUp">
<template #icon>
<IconArrowUp :size="20" />
</template>
</NcButton>
<div v-show="isFirst || !!app.default" aria-hidden="true" class="order-selector-element__placeholder" />
<NcButton v-show="!isLast && !app.default"
ref="buttonDown"
:aria-label="t('settings', 'Move down')"
data-cy-app-order-button="down"
type="tertiary-no-background"
@click="moveDown">
<template #icon>
<IconArrowDown :size="20" />
</template>
</NcButton>
<div v-show="isLast || !!app.default" aria-hidden="true" class="order-selector-element__placeholder" />
</div>
</li>
</template>
<script lang="ts">
import type { PropType } from 'vue'
import { translate as t } from '@nextcloud/l10n'
import { defineComponent, nextTick, ref } from 'vue'
import IconArrowDown from 'vue-material-design-icons/ArrowDown.vue'
import IconArrowUp from 'vue-material-design-icons/ArrowUp.vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
interface IApp {
id: string // app id
icon: string // path to the icon svg
label?: string // display name
default?: boolean // for app as default app
}
export default defineComponent({
name: 'AppOrderSelectorElement',
components: {
IconArrowDown,
IconArrowUp,
NcButton,
},
props: {
app: {
type: Object as PropType<IApp>,
required: true,
},
isFirst: {
type: Boolean,
default: false,
},
isLast: {
type: Boolean,
default: false,
},
},
emits: {
'move:up': () => true,
'move:down': () => true,
},
setup(props, { emit }) {
const buttonUp = ref()
const buttonDown = ref()
/**
* Used to decide if we need to trigger focus() an a button on update
*/
let needsFocus = 0
/**
* Handle move up, ensure focus is kept on the button
*/
const moveUp = () => {
emit('move:up')
needsFocus = 1 // request focus on buttonUp
}
/**
* Handle move down, ensure focus is kept on the button
*/
const moveDown = () => {
emit('move:down')
needsFocus = -1 // request focus on buttonDown
}
/**
* Reset the focus on the last used button.
* If the button is now visible anymore (because this element is the first/last) then the opposite button is focussed
*
* This function is exposed to the "AppOrderSelector" component which triggers this when the list was successfully rerendered
*/
const keepFocus = () => {
if (needsFocus !== 0) {
// focus requested
if ((needsFocus === 1 || props.isLast) && !props.isFirst) {
// either requested to btn up and it is not the first, or it was requested to btn down but it is the last
nextTick(() => buttonUp.value.$el.focus())
} else {
nextTick(() => buttonDown.value.$el.focus())
}
}
needsFocus = 0
}
return {
buttonUp,
buttonDown,
moveUp,
moveDown,
keepFocus,
t,
}
},
})
</script>
<style lang="scss" scoped>
.order-selector-element {
// hide default styling
list-style: none;
// Align children
display: flex;
flex-direction: row;
align-items: center;
// Spacing
gap: 12px;
padding-inline: 12px;
&:hover {
background-color: var(--color-background-hover);
border-radius: var(--border-radius-large);
}
&--disabled {
border-color: var(--color-text-maxcontrast);
color: var(--color-text-maxcontrast);
.order-selector-element__icon {
opacity: 75%;
}
}
&__actions {
flex: 0 0;
display: flex;
flex-direction: row;
gap: 6px;
}
&__label {
flex: 1 1;
text-overflow: ellipsis;
overflow: hidden;
}
&__placeholder {
height: 44px;
width: 44px;
}
&__icon {
filter: var(--background-invert-if-bright);
}
}
</style>
|