MultipleTagsSelect.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <b-form-tags
  3. v-bind="$attrs" v-on="$listeners"
  4. :value="value"
  5. no-outer-focus
  6. >
  7. <template v-slot="{ tags, disabled, addTag, removeTag }">
  8. <b-dropdown
  9. :text="buttonText"
  10. variant="outline-dark" class="tags-dropdown"
  11. dropright
  12. >
  13. <b-dropdown-item-button
  14. v-for="tag in availableOptions" :key="tag"
  15. @click="addTag(tag)"
  16. >
  17. {{ tag }}
  18. </b-dropdown-item-button>
  19. </b-dropdown>
  20. <ul v-if="tags.length > 0" class="list-inline d-inline-block">
  21. <li v-for="tag in tags" :key="tag + '-item'" class="list-inline-item">
  22. <b-form-tag
  23. :title="tag" :disabled="disabled"
  24. pill variant="dark"
  25. @remove="removeTag(tag)"
  26. >
  27. {{ tag }}
  28. </b-form-tag>
  29. </li>
  30. </ul>
  31. </template>
  32. </b-form-tags>
  33. </template>
  34. <script>
  35. export default {
  36. name: 'MultipleTagsSelect',
  37. props: {
  38. value: { type: Array, required: true },
  39. options: { type: Array, required: true },
  40. buttonText: { type: String, required: true }
  41. },
  42. computed: {
  43. availableOptions () {
  44. return this.options.filter(opt => this.value.indexOf(opt.text) === -1)
  45. }
  46. }
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .b-form-tags {
  51. border: 0;
  52. padding: 0;
  53. @include media-breakpoint-up($layout-bp) {
  54. ul li {
  55. display: block;
  56. }
  57. }
  58. .btn-group {
  59. vertical-align: baseline;
  60. }
  61. .tags-dropdown {
  62. margin-right: .5rem;
  63. margin-bottom: .25rem;
  64. }
  65. .list-inline {
  66. margin: 0;
  67. &-item {
  68. margin-bottom: .25rem;
  69. display: inline-block;
  70. }
  71. }
  72. ::v-deep {
  73. .dropdown-menu {
  74. max-height: 30vh;
  75. overflow-y: auto;
  76. max-width: 100vw;
  77. }
  78. .b-form-tag {
  79. font-weight: $font-weight-bold;
  80. text-transform: capitalize;
  81. padding-top: 0;
  82. padding-bottom: 0;
  83. border: $line;
  84. margin-right: 0;
  85. }
  86. .b-form-tag-remove {
  87. opacity: 1;
  88. line-height: 0;
  89. height: 15px;
  90. text-shadow: none;
  91. }
  92. }
  93. }
  94. </style>