LegendToggle.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class="legend-toggle">
  3. <b-button
  4. variant="dark"
  5. class="btn-legend-toggle"
  6. :class="visible ? null : 'collapsed'"
  7. :aria-expanded="visible ? 'true' : 'false'"
  8. aria-controls="collapse-legend-toggle"
  9. @click="onBtnClick"
  10. >
  11. <span>?</span>
  12. </b-button>
  13. <b-collapse id="collapse-legend-toggle" v-model="visible">
  14. <div class="collapse-body" ref="body">
  15. <slot name="default" />
  16. </div>
  17. </b-collapse>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'LegendToggle',
  23. data () {
  24. return {
  25. visible: false
  26. }
  27. },
  28. methods: {
  29. onBtnClick () {
  30. this.visible = !this.visible
  31. if (this.visible) {
  32. document.addEventListener('mousedown', this.onDocumentClick, { capture: true })
  33. }
  34. },
  35. onDocumentClick (e) {
  36. if (this.$refs.body.contains(e.target)) return
  37. document.removeEventListener('mousedown', this.onDocumentClick, { capture: true })
  38. if (!e.target.classList.contains('btn')) {
  39. this.visible = false
  40. }
  41. }
  42. }
  43. }
  44. </script>
  45. <style lang="scss" scoped>
  46. .legend-toggle {
  47. position: absolute;
  48. z-index: 1;
  49. top: 15px;
  50. left: 15px;
  51. @include media-breakpoint-up($size-bp) {
  52. top: 30px;
  53. left: 30px;
  54. }
  55. }
  56. .btn-legend-toggle {
  57. display: block;
  58. width: $btn-size;
  59. height: $btn-size;
  60. padding: 0;
  61. border: 0;
  62. font-weight: $font-weight-bold;
  63. // font-size: 1.7rem;
  64. line-height: 1;
  65. margin-bottom: 10px;
  66. span {
  67. pointer-events: none;
  68. }
  69. }
  70. .collapse {
  71. transition: none;
  72. }
  73. .collapse-body {
  74. max-width: 500px;
  75. margin-right: 15px;
  76. border: $line;
  77. background-color: $white;
  78. padding: $node-card-spacer-y $node-card-spacer-x;
  79. @include media-breakpoint-up($size-bp) {
  80. margin-right: 30px;
  81. }
  82. }
  83. </style>