-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathEditableList.vue
61 lines (52 loc) · 1.36 KB
/
EditableList.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
<script lang="ts">
import EditableListItem from "@/components/EditableListItem.vue";
export interface EditableListItemModel {
name: string;
icon?: string;
isNamed?: boolean;
id: string;
}
export interface EditableListAction {
label: string;
emitPayload: string;
icon?: string;
}
</script>
<script setup lang="ts">
const props = defineProps<{
actions?: EditableListAction[];
}>();
const emit = defineEmits<{
action: [payload: string, item: EditableListItemModel];
select: [name: string];
rename: [oldName: string, newName: string, item: EditableListItemModel];
}>();
const items = defineModel<EditableListItemModel[]>("items", { required: true });
function onAction(payload: string, item: EditableListItemModel) {
emit("action", payload, item);
}
function onRename(oldName: string, newName: string, item: EditableListItemModel) {
emit("rename", oldName, newName, item);
}
</script>
<template>
<div class="editable-list">
<EditableListItem
v-for="(item, index) in items"
:key="item.id"
v-model="items[index]"
:actions="props.actions"
@action="onAction($event, item)"
@select="emit('select', item.name)"
@rename="onRename"
/>
</div>
</template>
<style scoped>
.editable-list {
display: flex;
flex-direction: column;
padding: var(--spacing-padding-normal);
gap: var(--spacing-padding-normal);
}
</style>