Skip to content

Instantly share code, notes, and snippets.

@Shoeboxam
Created April 25, 2019 02:40
Show Gist options
  • Select an option

  • Save Shoeboxam/f9c148b7abc57777cd1298e768e27ef7 to your computer and use it in GitHub Desktop.

Select an option

Save Shoeboxam/f9c148b7abc57777cd1298e768e27ef7 to your computer and use it in GitHub Desktop.
import Popper from 'popper.js';
import m from 'mithril';
class PopperWrapper {
onupdate({state}) {
if (state.popper) state.popper.update()
}
view(vnode) {
let {attrs, children, state} = vnode;
return m('div',
m('div#popper', {
style: {display: state.popper ? 'block' : 'none', width: 'auto'},
key: "popper",
oncreate({dom}) {state.popperDom = dom},
}, attrs.content),
m('div', {
key: "children",
onmouseover: !state.popper &&
(() => state.popper = new Popper(vnode.dom, state.popperDom, attrs.options)),
onmouseout: () => delete state.popper
}, children)
)
}
onremove({state}) {
state.popper && state.popper.destroy()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment