2023-05-07 07:13:18 +00:00
|
|
|
<template>
|
|
|
|
<div class="d-flex flex-row">
|
2023-05-07 07:19:55 +00:00
|
|
|
<div class="flex-grow-1">
|
|
|
|
<slot v-if="!editing"> </slot>
|
|
|
|
<b-form-input v-else v-model="localName" size="sm"> </b-form-input>
|
|
|
|
</div>
|
2023-05-07 13:38:24 +00:00
|
|
|
<div
|
|
|
|
class="flex-grow-2 mt-auto d-flex gap-1 ms-1"
|
|
|
|
:class="alignVertical ? 'flex-column' : 'flex-row'"
|
|
|
|
>
|
2023-05-07 07:19:55 +00:00
|
|
|
<template v-if="allowEdit && !(addNew || editing)">
|
|
|
|
<b-button
|
|
|
|
size="sm"
|
|
|
|
variant="secondary"
|
|
|
|
:title="`Edit this ${editableName}.`"
|
|
|
|
@click="editing = true"
|
|
|
|
>
|
2023-05-09 04:49:13 +00:00
|
|
|
<EditIcon />
|
2023-05-07 07:19:55 +00:00
|
|
|
</b-button>
|
|
|
|
<b-button
|
|
|
|
size="sm"
|
|
|
|
variant="secondary"
|
|
|
|
:title="`Delete this ${editableName}.`"
|
|
|
|
@click="$emit('delete', modelValue)"
|
|
|
|
>
|
2023-05-09 04:49:13 +00:00
|
|
|
<DeleteIcon />
|
2023-05-07 07:19:55 +00:00
|
|
|
</b-button>
|
|
|
|
</template>
|
2023-05-07 07:13:18 +00:00
|
|
|
<b-button
|
2023-05-07 07:19:55 +00:00
|
|
|
v-if="allowAdd && !(addNew || editing)"
|
2023-05-07 07:13:18 +00:00
|
|
|
size="sm"
|
2023-05-07 07:19:55 +00:00
|
|
|
:title="`Add new ${editableName}.`"
|
2023-05-07 07:13:18 +00:00
|
|
|
variant="primary"
|
2023-05-07 07:19:55 +00:00
|
|
|
@click="addNewClick"
|
2023-05-09 04:49:13 +00:00
|
|
|
><AddIcon />
|
2023-05-07 07:13:18 +00:00
|
|
|
</b-button>
|
2023-05-07 10:45:02 +00:00
|
|
|
<template v-if="addNew || editing">
|
2023-05-07 07:19:55 +00:00
|
|
|
<b-button
|
|
|
|
size="sm"
|
|
|
|
:title="`Add new '${editableName}`"
|
|
|
|
variant="primary"
|
|
|
|
@click="saveNewName"
|
|
|
|
>
|
2023-05-09 04:49:13 +00:00
|
|
|
<CheckIcon />
|
2023-05-07 07:19:55 +00:00
|
|
|
</b-button>
|
|
|
|
<b-button size="sm" title="Abort" class="ms-1" variant="secondary" @click="abort">
|
2023-05-09 04:49:13 +00:00
|
|
|
<CloseIcon />
|
2023-05-07 07:19:55 +00:00
|
|
|
</b-button>
|
|
|
|
</template>
|
|
|
|
</div>
|
2023-05-07 07:13:18 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-05-09 04:49:13 +00:00
|
|
|
import CheckIcon from '~icons/mdi/check';
|
|
|
|
import CloseIcon from '~icons/mdi/close';
|
|
|
|
import DeleteIcon from '~icons/mdi/delete';
|
|
|
|
import EditIcon from '~icons/mdi/pencil';
|
|
|
|
import AddIcon from '~icons/mdi/plus-box-outline';
|
2023-05-07 07:13:18 +00:00
|
|
|
|
2023-05-07 10:45:02 +00:00
|
|
|
import { ref, watch } from 'vue';
|
2023-05-07 07:13:18 +00:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
modelValue: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
allowEdit: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-05-07 07:16:25 +00:00
|
|
|
allowAdd: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-05-07 07:13:18 +00:00
|
|
|
editableName: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2023-05-07 13:38:24 +00:00
|
|
|
alignVertical: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-05-07 07:13:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'delete', value: string): void;
|
|
|
|
(e: 'new', value: string): void;
|
|
|
|
(e: 'rename', oldName: string, newName: string): void;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const addNew = ref(false);
|
|
|
|
const localName = ref<string>(props.modelValue);
|
|
|
|
const editing = ref<boolean>(false);
|
|
|
|
|
|
|
|
function abort() {
|
|
|
|
editing.value = false;
|
|
|
|
addNew.value = false;
|
|
|
|
localName.value = props.modelValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addNewClick() {
|
|
|
|
localName.value = '';
|
|
|
|
addNew.value = true;
|
|
|
|
editing.value = true;
|
|
|
|
}
|
2023-05-07 10:45:02 +00:00
|
|
|
watch(
|
|
|
|
() => props.modelValue,
|
|
|
|
() => {
|
|
|
|
localName.value = props.modelValue;
|
|
|
|
},
|
|
|
|
);
|
2023-05-07 07:13:18 +00:00
|
|
|
|
|
|
|
function saveNewName() {
|
|
|
|
editing.value = false;
|
|
|
|
if (addNew.value) {
|
|
|
|
addNew.value = false;
|
|
|
|
emit('new', localName.value);
|
|
|
|
} else {
|
|
|
|
// Editing
|
|
|
|
emit('rename', props.modelValue, localName.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|