gamebrary/src/components/GameBoard/ListNameEdit.vue

82 lines
1.6 KiB
Vue
Raw Normal View History

2018-10-19 05:15:28 +00:00
<template lang="html">
<div class="list-name">
<input
v-if="editing"
class="small"
v-model="localListName"
ref="input"
@keyup.enter="save"
@keyup.esc="save"
2019-02-08 07:16:27 +00:00
@blur="exit"
2018-10-19 05:15:28 +00:00
>
2018-12-19 16:30:09 +00:00
<span
v-else
class="not-editing"
:title="$t('list.edit')"
@click="edit"
>
2018-11-24 20:50:27 +00:00
<span>{{ listName }} ({{ gameCount }})</span>
<i class="fas fa-pen" />
2018-10-19 05:15:28 +00:00
</span>
</div>
</template>
<script>
export default {
props: {
listName: String,
listIndex: [String, Number],
gameCount: Number,
},
data() {
return {
editing: false,
localListName: '',
};
},
methods: {
save() {
this.$store.commit('UPDATE_LIST_NAME', {
listIndex: this.listIndex,
listName: this.localListName,
});
this.$emit('update');
},
edit() {
this.editing = true;
this.localListName = this.listName;
this.$nextTick(() => {
this.$refs.input.focus();
});
},
exit() {
2019-02-08 07:16:27 +00:00
if (this.listName !== this.localListName) {
this.save();
}
2018-10-19 05:15:28 +00:00
2019-02-08 07:16:27 +00:00
this.editing = false;
2018-10-19 05:15:28 +00:00
},
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
.list-name {
cursor: pointer;
2018-11-24 20:50:27 +00:00
width: 100%;
.not-editing {
display: flex;
align-items: center;
justify-content: space-between;
}
2018-10-19 05:15:28 +00:00
}
</style>