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
|
<script>
import { GlButton } from '@gitlab/ui';
import { sprintf, __ } from '~/locale';
import UserAvatarLink from './user_avatar_link.vue';
export default {
components: {
UserAvatarLink,
GlButton,
},
props: {
items: {
type: Array,
required: true,
},
breakpoint: {
type: Number,
required: false,
default: 10,
},
imgSize: {
type: Number,
required: false,
default: 20,
},
emptyText: {
type: String,
required: false,
default: __('None'),
},
},
data() {
return {
isExpanded: false,
};
},
computed: {
visibleItems() {
if (!this.hasHiddenItems) {
return this.items;
}
return this.items.slice(0, this.breakpoint);
},
hasHiddenItems() {
return this.hasBreakpoint && !this.isExpanded && this.items.length > this.breakpoint;
},
hasBreakpoint() {
return this.breakpoint > 0 && this.items.length > this.breakpoint;
},
expandText() {
if (!this.hasHiddenItems) {
return '';
}
const count = this.items.length - this.breakpoint;
return sprintf(__('%{count} more'), { count });
},
},
methods: {
expand() {
this.isExpanded = true;
},
collapse() {
this.isExpanded = false;
},
},
};
</script>
<template>
<div v-if="!items.length">{{ emptyText }}</div>
<div v-else>
<user-avatar-link
v-for="item in visibleItems"
:key="item.id"
:link-href="item.web_url"
:img-src="item.avatar_url"
:img-alt="item.name"
:tooltip-text="item.name"
:img-size="imgSize"
/>
<template v-if="hasBreakpoint">
<gl-button v-if="hasHiddenItems" variant="link" @click="expand"> {{ expandText }} </gl-button>
<gl-button v-else variant="link" @click="collapse"> {{ __('show less') }} </gl-button>
</template>
</div>
</template>
|