Created
December 28, 2018 11:23
-
-
Save sergey-shpak/88962fdb4002d9a77d315ee9769e6efb to your computer and use it in GitHub Desktop.
Hyperapp #v2 Portal Component (Experimental)
This file contains 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
import { app, h } from "hyperapp"; | |
import { Portal } from './helpers' | |
/* Working example, https://codepen.io/sergey-shpak/pen/gZGpjZ */ | |
// --- PORTAL COMPONENT --- | |
const Modal = (props, child) => Portal( | |
child, // or h(YourDialogComponent, props, child) | |
document.getElementById('modal-root') // dom node | |
) | |
app({ | |
init: 1, | |
view: () => h('div', {}, [ | |
'Application', | |
h(Modal, {}, 'Modal Content') | |
]), | |
container: document.getElementById('app-root') | |
}) |
This file contains 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
import { h } from "hyperapp"; | |
/* | |
This is implementation of Hyperapp#v2 Portal component | |
Portal component renders children into a DOM node | |
that exists outside the DOM hierarchy of the parent component | |
IMPORTANT! It's not recommended approach to use | |
unless you really know what you're doing | |
*/ | |
export const Portal = (child, container) => h('div', { | |
onCreate: element => | |
container.appendChild(document.adoptNode(element)) | |
}, child) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment