LegendToggle.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. top: 15px;
  49. left: 15px;
  50. @include media-breakpoint-up($size-bp) {
  51. top: 30px;
  52. left: 30px;
  53. }
  54. }
  55. .btn-legend-toggle {
  56. display: block;
  57. width: $btn-size;
  58. height: $btn-size;
  59. padding: 0;
  60. border: 0;
  61. font-weight: $font-weight-bold;
  62. // font-size: 1.7rem;
  63. line-height: 1;
  64. margin-bottom: 10px;
  65. span {
  66. pointer-events: none;
  67. }
  68. }
  69. .collapse {
  70. transition: none;
  71. }
  72. .collapse-body {
  73. max-width: 500px;
  74. margin-right: 15px;
  75. border: $line;
  76. background-color: $white;
  77. padding: $node-card-spacer-y $node-card-spacer-x;
  78. @include media-breakpoint-up($size-bp) {
  79. margin-right: 30px;
  80. }
  81. }
  82. </style>