-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathEditableChipList.vue
More file actions
85 lines (77 loc) · 2.21 KB
/
Copy pathEditableChipList.vue
File metadata and controls
85 lines (77 loc) · 2.21 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
<script
setup
lang="ts"
generic="T, KeyProp extends keyof T, TitleProp extends keyof T"
>
/* global T, KeyProp, TitleProp */
import { computed } from 'vue';
import { Maybe } from '@/src/types';
defineEmits(['select', 'edit', 'create', 'update:model-value']);
const props = withDefaults(
defineProps<{
items: Array<T>;
itemKey: T[KeyProp] extends string | number | symbol ? KeyProp : never;
itemTitle: T[TitleProp] extends string ? TitleProp : never;
createLabelText?: string;
modelValue: Maybe<T[KeyProp]>;
}>(),
{
createLabelText: 'Create Label',
}
);
const itemsToRender = computed(() =>
props.items.map((item) => ({
key: item[props.itemKey] as string | number | symbol,
title: item[props.itemTitle] as string | undefined,
}))
);
</script>
<template>
<v-item-group
:model-value="modelValue"
@update:model-value="$emit('update:model-value', $event)"
selected-class="selected"
mandatory
>
<v-row dense>
<v-col
cols="12"
v-for="({ key, title }, idx) in itemsToRender"
:key="key"
>
<v-item v-slot="{ selectedClass, toggle }" :value="key">
<v-chip
variant="tonal"
:class="['w-100 d-flex', selectedClass]"
@click="toggle"
>
<slot name="item-prepend" :key="key" :item="items[idx]"></slot>
<v-tooltip :text="title" location="end">
<template #activator="{ props }">
<span v-bind="props" class="text-truncate">{{ title }}</span>
</template>
</v-tooltip>
<v-spacer />
<slot name="item-append" :key="key" :item="items[idx]"></slot>
</v-chip>
</v-item>
</v-col>
<!-- Add Label button -->
<v-col cols="12">
<v-chip variant="outlined" class="w-100" @click="$emit('create')">
<v-icon class="mr-2">mdi-plus</v-icon>
{{ createLabelText }}
</v-chip>
</v-col>
</v-row>
</v-item-group>
</template>
<style scoped>
.selected {
background-color: rgb(var(--v-theme-selection-bg-color));
border-color: rgb(var(--v-theme-selection-border-color));
}
.v-chip:deep() .v-chip__content {
width: 100%;
}
</style>