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.

125 lines
2.5 KiB

  1. <template>
  2. <v-menu
  3. :value="opened"
  4. :position-x="x"
  5. :position-y="y"
  6. absolute
  7. offset-y
  8. @input="close"
  9. >
  10. <v-list
  11. dense
  12. min-width="150"
  13. max-height="400"
  14. class="overflow-y-auto"
  15. >
  16. <v-list-item>
  17. <v-autocomplete
  18. ref="autocomplete"
  19. v-model="value"
  20. :items="labels"
  21. autofocus
  22. dense
  23. deletable-chips
  24. hide-details
  25. item-text="text"
  26. item-value="id"
  27. label="Select a label"
  28. small-chips
  29. @input="onLabelSelected"
  30. />
  31. </v-list-item>
  32. <v-list-item
  33. v-for="(label, i) in labels"
  34. :key="i"
  35. @click="onLabelSelected(label.id)"
  36. >
  37. <v-list-item-action
  38. v-if="hasAnySuffixKey"
  39. >
  40. <v-chip
  41. v-if="label.suffixKey"
  42. :color="label.backgroundColor"
  43. outlined
  44. small
  45. v-text="label.suffixKey"
  46. />
  47. <span v-else class="mr-8" />
  48. </v-list-item-action>
  49. <v-list-item-content>
  50. <v-list-item-title v-text="label.text"/>
  51. </v-list-item-content>
  52. </v-list-item>
  53. </v-list>
  54. </v-menu>
  55. </template>
  56. <script lang="ts">
  57. import Vue from 'vue'
  58. export default Vue.extend({
  59. props: {
  60. labels: {
  61. type: Array,
  62. default: () => [],
  63. required: true,
  64. },
  65. opened: {
  66. type: Boolean,
  67. default: false,
  68. required: true,
  69. },
  70. selectedLabel: {
  71. type: Object,
  72. default: null,
  73. required: false,
  74. },
  75. x: {
  76. type: Number,
  77. default: 0,
  78. required: true,
  79. },
  80. y: {
  81. type: Number,
  82. default: 0,
  83. required: true,
  84. }
  85. },
  86. data() {
  87. return {
  88. startOffset: 0,
  89. endOffset: 0,
  90. entity: null as any,
  91. fromEntity: null as any,
  92. toEntity: null as any,
  93. value: this.selectedLabel
  94. };
  95. },
  96. computed: {
  97. hasAnySuffixKey(): boolean {
  98. return this.labels.some((label: any) => label.suffixKey !== null)
  99. }
  100. },
  101. methods: {
  102. close() {
  103. // Todo: a bit hacky. I want to fix this problem.
  104. // https://github.com/vuetifyjs/vuetify/issues/10765
  105. this.$nextTick(() => {
  106. this.value = null
  107. if (this.$refs.autocomplete) {
  108. (this.$refs.autocomplete as any).selectedItems = []
  109. }
  110. })
  111. this.$emit('close')
  112. },
  113. onLabelSelected(labelId: number) {
  114. this.value = labelId
  115. this.$emit('click:label', labelId)
  116. this.close()
  117. }
  118. }
  119. })
  120. </script>