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.

69 lines
1.3 KiB

  1. <template>
  2. <v-chip-group
  3. :value="annotatedLabel"
  4. column
  5. @change="addOrRemove"
  6. >
  7. <v-chip
  8. v-for="item in labels"
  9. :key="item.id"
  10. :color="item.backgroundColor"
  11. filter
  12. :text-color="$contrastColor(item.backgroundColor)"
  13. >
  14. {{ item.text }}
  15. <v-avatar
  16. right
  17. color="white"
  18. class="black--text font-weight-bold"
  19. >
  20. {{ item.suffixKey }}
  21. </v-avatar>
  22. </v-chip>
  23. </v-chip-group>
  24. </template>
  25. <script>
  26. export default {
  27. props: {
  28. labels: {
  29. type: Array,
  30. default: () => [],
  31. required: true
  32. },
  33. annotations: {
  34. type: Array,
  35. default: () => ([]),
  36. required: true
  37. }
  38. },
  39. computed: {
  40. annotatedLabel() {
  41. const labelIds = this.annotations.map(item => item.label)
  42. return this.labels.findIndex(item => labelIds.includes(item.id))
  43. }
  44. },
  45. methods: {
  46. addOrRemove(index) {
  47. if (index === undefined) {
  48. const label = this.labels[this.annotatedLabel]
  49. this.remove(label)
  50. } else {
  51. const label = this.labels[index]
  52. this.add(label)
  53. }
  54. },
  55. add(label) {
  56. this.$emit('add', label.id)
  57. },
  58. remove(label) {
  59. const annotation = this.annotations.find(item => item.label === label.id)
  60. this.$emit('remove', annotation.id)
  61. }
  62. }
  63. }
  64. </script>