gamebrary/src/components/Lists/ListNameEdit.vue

81 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
:title="$t('list.edit')"
@click="edit"
>
2018-11-24 20:50:27 +00:00
<span>{{ listName }} ({{ gameCount }})</span>
2019-04-03 23:22:26 +00:00
<i class="edit 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>
2019-04-05 19:16:32 +00:00
@import "~styles/styles.scss";
2019-04-03 23:22:26 +00:00
2018-10-19 05:15:28 +00:00
.list-name {
cursor: pointer;
2018-11-24 20:50:27 +00:00
width: 100%;
2019-04-03 23:22:26 +00:00
.edit {
margin: 0 $gp / 2;
2018-11-24 20:50:27 +00:00
}
2018-10-19 05:15:28 +00:00
}
</style>