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.

112 lines
2.4 KiB

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