aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/new-tooltip.js
blob: e6103dc956f1b739037fcb950eb178997b34a775 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const findDOMNode = require('react-dom').findDOMNode
const ReactTooltip = require('react-tooltip')

module.exports = NewTooltip

inherits(NewTooltip, Component)
function NewTooltip () {
  Component.call(this)
  this.state = {
    tooltipNode: null,
    tooltipBase: null,
  }

  // this.pageClick = this.pageClick.bind(this)
}

// NewTooltip.prototype.pageClick = function (e) {
//   // event.preventDefault();
//   const tooltipNode = this.state.tooltipNode
//   console.log(`e.target`, e.target);
//   console.log(`tooltipNode.contains(e.target)`, tooltipNode.contains(e.target));
// },

NewTooltip.prototype.componentDidMount = function () {
  const tooltipNode = findDOMNode(this);
  const tooltipBase = findDOMNode(this.refs.tester)

  this.setState({ tooltipBase, tooltipNode })
}

NewTooltip.prototype.componentDidUpdate = function () {
  const { show } = this.props
  const tooltipBase = this.state.tooltipBase
  const tooltipNode = this.state.tooltipNode
  
  if (show) {
    ReactTooltip.show(tooltipBase)
  }
  else {
    ReactTooltip.hide(tooltipBase)
  } 
}

NewTooltip.prototype.render = function () {
  const props = this.props
  const { position, title, children } = props

  return h('div', {}, [
    h('div', {
      'data-tip': 'test',
      'data-for': 'something',
      'ref': 'tester',
    }),
    h(ReactTooltip, {
      place: position || 'top',
      effect: 'solid',
      id: 'something',
      className: 'send-tooltip',
      type: 'light',
    }, children),
  ])
    
}