You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.0 KiB

3 years ago
3 years ago
  1. <template>
  2. <v-select
  3. :value="annotatedLabel"
  4. chips
  5. :items="labels"
  6. item-text="text"
  7. hide-details
  8. hide-selected
  9. return-object
  10. class="pt-0"
  11. @change="addOrRemove"
  12. >
  13. <template #selection="{ attrs, item, select, selected }">
  14. <v-chip
  15. v-if="item.backgroundColor"
  16. v-bind="attrs"
  17. :input-value="selected"
  18. :color="item.backgroundColor"
  19. :text-color="$contrastColor(item.backgroundColor)"
  20. close
  21. @click="select"
  22. @click:close="remove(item)"
  23. >
  24. <v-avatar
  25. v-if="item.suffixKey"
  26. left
  27. color="white"
  28. class="black--text font-weight-bold"
  29. >
  30. {{ item.suffixKey }}
  31. </v-avatar>
  32. {{ item.text }}
  33. </v-chip>
  34. </template>
  35. <template #item="{ item }">
  36. <v-chip
  37. :color="item.backgroundColor"
  38. :text-color="$contrastColor(item.backgroundColor)"
  39. >
  40. <v-avatar
  41. v-if="item.suffixKey"
  42. left
  43. color="white"
  44. class="black--text font-weight-bold"
  45. >
  46. {{ item.suffixKey }}
  47. </v-avatar>
  48. {{ item.text }}
  49. </v-chip>
  50. </template>
  51. </v-select>
  52. </template>
  53. <script>
  54. export default {
  55. props: {
  56. labels: {
  57. type: Array,
  58. default: () => [],
  59. required: true
  60. },
  61. annotations: {
  62. type: Array,
  63. default: () => ([]),
  64. required: true
  65. }
  66. },
  67. computed: {
  68. annotatedLabel() {
  69. const labelIds = this.annotations.map(item => item.label)
  70. return this.labels.find(item => labelIds.includes(item.id))
  71. }
  72. },
  73. methods: {
  74. addOrRemove(val) {
  75. if (val) {
  76. this.add(val)
  77. } else {
  78. this.remove(this.annotatedLabel)
  79. }
  80. },
  81. add(label) {
  82. this.$emit('add', label.id)
  83. },
  84. remove(label) {
  85. const annotation = this.annotations.find(item => item.label === label.id)
  86. this.$emit('remove', annotation.id)
  87. }
  88. }
  89. }
  90. </script>