forked from learningequality/kolibri-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
klistwithoverflow.vue
250 lines (231 loc) · 6.88 KB
/
klistwithoverflow.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<template>
<DocsPageTemplate apiDocs>
<DocsPageSection title="Overview" anchor="#overview">
<p>
The <code>KListWithOverflow</code> component is useful when we want a horizontal list that is responsive and adaptable to the container size. The list only shows the items that fit on the container element. When items exceed the available space, the component seamlessly integrates a "see more" button to show additional items.
</p>
</DocsPageSection>
<DocsPageSection title="Example" anchor="#example">
<p>
When a number of items fit within the screen boundaries, the list will be displayed without any changes. For example, since there are only 3 items here, we can see the entire list without problems.
</p>
<div class="klist-example">
<DocsShow block>
<KListWithOverflow
:items="getItems(3)"
>
<template #item="{ item }">
<KIconButton
:tooltip="item.label"
:icon="item.icon"
/>
</template>
<template #more="{ overflowItems }">
<KIconButton
tooltip="More"
icon="optionsVertical"
appearance="flat-button"
:primary="false"
>
<template #menu>
<KDropdownMenu
:options="overflowItems"
/>
</template>
</KIconButton>
</template>
</KListWithOverflow>
</DocsShow>
</div>
<p>
But if the list becomes very long, and does not fit within the screen, then the overflowed items will be cut, and an element will be placed to show more. For example, here are 12 items in the list.
</p>
<div class="klist-example">
<DocsShow block>
<KListWithOverflow
:items="getItems(12)"
>
<template #item="{ item }">
<KIconButton
:tooltip="item.label"
:icon="item.icon"
/>
</template>
<template #more="{ overflowItems }">
<KIconButton
tooltip="More"
icon="optionsVertical"
appearance="flat-button"
:primary="false"
>
<template #menu>
<KDropdownMenu
:options="overflowItems"
/>
</template>
</KIconButton>
</template>
</KListWithOverflow>
</DocsShow>
</div>
<p>
The following is a code example to render the above examples:
</p>
<DocsShowCode language="html">
<KListWithOverflow
:items="items"
>
<template #item="{ item }">
<KIconButton
:tooltip="item.label"
:icon="item.icon"
/>
</template>
<template #more="{ overflowItems }">
<KIconButton
tooltip="More"
icon="optionsVertical"
>
<template #menu>
<KDropdownMenu
:options="overflowItems"
/>
</template>
</KIconButton>
</template>
</KListWithOverflow>
</DocsShowCode>
<!-- eslint-disable -->
<DocsShowCode language="javascript">
data() {
return {
items: [
{ label: "Item 1", icon: "edit" },
{ label: "Item 2", icon: "edit" },
{ label: "Item 3", icon: "edit" },
// ...
{ label: "Item 12", icon: "edit" },
]
};
},
</DocsShowCode>
<!-- eslint-enable -->
<p>
You can also use dividers within the list by passing a <code>{ type: "divider" }</code> object, and set a #divider slot.
Note that the visible list will not end with a divider. And a divider object will not be passed as a first overflowed item.
</p>
<div class="klist-example">
<DocsShow block>
<KListWithOverflow
:items="getItems(12, 2)"
>
<template #item="{ item }">
<KIconButton
:tooltip="item.label"
:icon="item.icon"
/>
</template>
<template #more="{ overflowItems }">
<KIconButton
tooltip="More"
icon="optionsVertical"
appearance="flat-button"
:primary="false"
>
<template #menu>
<KDropdownMenu
:options="overflowItems"
/>
</template>
</KIconButton>
</template>
<template #divider>
<div class="divider-wrapper">
<div :style="dividerStyle"></div>
</div>
</template>
</KListWithOverflow>
</DocsShow>
</div>
<p>
To use dividers, you can include a divider object in the items list, and add a #divider slot.
</p>
<DocsShowCode language="html">
<KListWithOverflow
:items="items"
>
<!-- ... -->
<template #divider>
<div class="divider-wrapper">
<div :style="dividerStyle"></div>
</div>
</template>
</KListWithOverflow>
</DocsShowCode>
<!-- eslint-disable -->
<DocsShowCode language="javascript">
data() {
return {
items: [
{ label: "Item 1", icon: "edit" },
{ label: "Item 2", icon: "edit" },
{ type: "divider" },
{ label: "Item 4", icon: "edit" },
// ...
]
};
},
</DocsShowCode>
<!-- eslint-enable -->
</DocsPageSection>
</DocsPageTemplate>
</template>
<script>
export default {
name: 'DocsKListWithOverflow',
computed: {
dividerStyle() {
return {
height: '100%',
backgroundColor: this.$themeTokens.fineLine,
width: '1px',
};
},
},
methods: {
getItems(number, dividerMod) {
return Array.from({ length: number }, (_, i) =>
dividerMod && i && i % dividerMod === 0
? { type: 'divider' }
: { label: `Item ${i + 1}`, icon: 'edit' }
);
},
},
};
</script>
<style lang="scss" scoped>
.table-number {
text-align: right;
}
.table-text {
text-align: left;
}
.table-number,
.table-text {
padding-right: 16px;
}
.divider-wrapper {
align-self: stretch;
padding: 8px 12px;
}
.klist-example {
width: 50%;
margin-right: auto;
margin-left: auto;
}
@media (max-width: 768px) {
.klist-example {
width: 100%;
}
}
</style>