-
-
Save Bondifrench/10598f2e98fed2aa59ff39113c028564 to your computer and use it in GitHub Desktop.
tooltip component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function noop(){} | |
var contentView = noop; | |
var elPos = { left: 0, bottom: 0}; | |
var tooltip = { | |
show: function(content, options) { | |
return function(event) { | |
elPos = event.currentTarget.getBoundingClientRect(); | |
contentView = function() { | |
return content; | |
}; | |
}; | |
}, | |
hide: function() { | |
contentView = noop; | |
}, | |
view: function() { | |
return m('.tooltip', { | |
style: 'top: ' + elPos.bottom + 'px; left: ' + elPos.left + 'px; position: absolute' | |
}, contentView()); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the view where you want to use the tooltip | |
m('div', { | |
onmouseover: tooltip.show('hurray') | |
onmouseout: tooltip.hide | |
}) | |
// somewhere in a baseView | |
m('main', [ | |
// other stuff | |
tooltip.view() | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was done with previous version of Mithril