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.

70 lines
1.4 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. v-if="item.suffixKey"
  17. right
  18. color="white"
  19. class="black--text font-weight-bold"
  20. >
  21. {{ item.suffixKey }}
  22. </v-avatar>
  23. </v-chip>
  24. </v-chip-group>
  25. </template>
  26. <script>
  27. export default {
  28. props: {
  29. labels: {
  30. type: Array,
  31. default: () => [],
  32. required: true
  33. },
  34. annotations: {
  35. type: Array,
  36. default: () => ([]),
  37. required: true
  38. }
  39. },
  40. computed: {
  41. annotatedLabel() {
  42. const labelIds = this.annotations.map(item => item.label)
  43. return this.labels.findIndex(item => labelIds.includes(item.id))
  44. }
  45. },
  46. methods: {
  47. addOrRemove(index) {
  48. if (index === undefined) {
  49. const label = this.labels[this.annotatedLabel]
  50. this.remove(label)
  51. } else {
  52. const label = this.labels[index]
  53. this.add(label)
  54. }
  55. },
  56. add(label) {
  57. this.$emit('add', label.id)
  58. },
  59. remove(label) {
  60. const annotation = this.annotations.find(item => item.label === label.id)
  61. this.$emit('remove', annotation.id)
  62. }
  63. }
  64. }
  65. </script>