editable-headline.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <h2>
  3. <img alt="delete" class="delete"
  4. src="@/assets/icons/x-circle.svg"
  5. @click="$emit('remove', $event)">
  6. <template v-if="!edit">
  7. {{ value }}
  8. <img alt="edit" class="edit"
  9. src="@/assets/icons/pencil.svg"
  10. @click="edit = true">
  11. </template>
  12. <template v-else>
  13. <text-input placeholder="name" v-model="input"
  14. @change="change" @enter="change"/>
  15. <button-row>
  16. <button-input @click="change" type="primary">confirm</button-input>
  17. <button-input @click="edit = false">cancel</button-input>
  18. </button-row>
  19. </template>
  20. </h2>
  21. </template>
  22. <script>
  23. import TextInput from "@/components/base/text-input";
  24. import ButtonInput from "@/components/base/button-input";
  25. import ButtonRow from "@/components/base/button-row";
  26. export default {
  27. name: "editable-headline",
  28. components: {ButtonRow, ButtonInput, TextInput},
  29. props: ['value'],
  30. data: function () {
  31. return {
  32. input: this.value,
  33. edit: false
  34. }
  35. },
  36. methods: {
  37. change: function () {
  38. this.$emit('change', this.input);
  39. this.edit = false;
  40. }
  41. }
  42. }
  43. </script>
  44. <style scoped>
  45. h2 {
  46. display: flex;
  47. align-items: center;
  48. margin: 0;
  49. }
  50. img {
  51. width: 1.5rem;
  52. }
  53. .delete {
  54. margin-right: 1.5rem;
  55. }
  56. .edit,
  57. .button-row {
  58. margin-left: 0.75rem;
  59. }
  60. .text-input {
  61. flex-grow: 1;
  62. margin-top: -0.5rem;
  63. }
  64. </style>