all files / packages/link/ LinkComponent.js

83.33% Statements 10/12
100% Branches 2/2
66.67% Functions 2/3
83.33% Lines 10/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37          20×   20× 20×                       20×   20× 20×   20× 20× 12×     20×            
import { AnnotationComponent } from '../../ui'
 
class LinkComponent extends AnnotationComponent {
 
  didMount(...args) {
    super.didMount(...args)
 
    let node = this.props.node
    this.context.editorSession.onRender('document', this.rerender, this, {
      path: [node.id, 'url']
    })
  }
 
  dispose(...args) {
    super.dispose(...args)
 
    this.context.editorSession.off(this)
  }
 
  render($$) { // eslint-disable-line
    let el = super.render($$)
 
    el.tagName = 'a'
    el.attr('href', this.props.node.url)
 
    let titleComps = [this.props.node.url]
    if (this.props.node.title) {
      titleComps.push(this.props.node.title)
    }
 
    return el.attr("title", titleComps.join(' | '))
  }
 
}
 
export default LinkComponent