TrestleAdmin/trestle

View on GitHub
frontend/js/controllers/navigation_tooltip_controller.js

Summary

Maintainability
A
0 mins
Test Coverage
import ApplicationController from './application_controller'

import { Tooltip } from 'bootstrap'

const TEMPLATE = `
<div class="tooltip nav-tooltip" role="tooltip">
  <div class="tooltip-arrow"></div>
  <div class="tooltip-inner"></div>
</div>
`

export default class extends ApplicationController {
  static targets = ["label"]

  connect () {
    this.tooltip = new Tooltip(this.element, {
      trigger: 'hover',
      placement: 'right',
      boundary: 'window',
      template: TEMPLATE,
      title: () => this.labelText
    })
  }

  disconnect () {
    this.tooltip.dispose()
  }

  get labelText () {
    return this.labelTarget.innerText
  }
}