MultiLineTextInput.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div>
  3. <!-- Send a label through props -->
  4. <label class="label">{{label}}</label>
  5. <!-- Iterate lines here -->
  6. <div class="multi-field field"
  7. v-for="(line, index) in lines"
  8. :key="line.value">
  9. <div class="control multi-control">
  10. <div class="multi-input-container">
  11. <input
  12. @input="emitUpdate($event, index)"
  13. :value="line.value"
  14. placeholder="Add Something Nice (:"
  15. class="input is-medium multi-input"
  16. type="text">
  17. </div>
  18. <div class="btn-container">
  19. <!-- Delete the line -->
  20. <button
  21. @click.prevent="emitRemove(index)"
  22. type="button"
  23. class="button is-danger multi-button">
  24. Delete
  25. </button>
  26. </div>
  27. </div>
  28. </div>
  29. <!-- Add the Line -->
  30. <button
  31. @click="emitAdd"
  32. type="button"
  33. class="m-b-sm button is-medium is-link is-outlined">
  34. Add an answer
  35. </button>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. props:{
  41. label : {
  42. type: String,
  43. required: true
  44. },
  45. lines: {
  46. type: Array,
  47. required: true
  48. }
  49. },
  50. methods: {
  51. emitAdd() {
  52. this.$emit('addClicked')
  53. },
  54. emitRemove(index) {
  55. this.$emit('removeClicked', index)
  56. },
  57. emitUpdate(event, index){
  58. const {value} = event.target
  59. this.$emit('valueUpdated', {value, index})
  60. }
  61. }
  62. }
  63. </script>
  64. <style scoped lang="scss">
  65. .multi-input {
  66. float: left;
  67. width: 100%;
  68. }
  69. .multi-button {
  70. height: inherit;
  71. }
  72. .multi-input-container {
  73. display: flex;
  74. flex: 1;
  75. }
  76. .btn-container {
  77. display: flex;
  78. opacity: 0;
  79. }
  80. .multi-control {
  81. display: flex;
  82. &:hover > .btn-container {
  83. opacity: 1;
  84. }
  85. }
  86. </style>