-
-
Save inodaf/769de75cb408d5f95fa4af1daef56a10 to your computer and use it in GitHub Desktop.
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
const createElement = name => | |
document.createElement(String(name).toUpperCase()) | |
const defineAttributes = (VNode, attributes) => | |
Object.keys(attributes).forEach(attr => | |
VNode.setAttribute(attr, attributes[attr])) | |
const defineChildren = (VNode, children) => | |
Array.isArray(children) && children.forEach(e => VNode.appendChild(e)) | |
const defineProperties = (VNode, props) => | |
Object.keys(props).forEach(prop => (VNode[prop] = props[prop])) | |
export const h = (nodeName, data, children) => { | |
const DOMNode = createElement(nodeName) | |
const componentData = { ...data } | |
defineAttributes(DOMNode, componentData.attrs || {}) | |
delete componentData.attrs | |
defineChildren(DOMNode, componentData.children || children) | |
delete componentData.children | |
defineProperties(DOMNode, componentData) | |
return DOMNode | |
} | |
const Label = text => h('span', { | |
className: 'ui-label', | |
textContent: text | |
}) | |
const Button = props => h('button', { | |
className: 'ui-button', | |
onclick: e => props.onclick(e) | |
}, [ | |
Label(props.label), | |
...props.slot | |
]) | |
const Dialog = props => h('article', { className: 'ui-dialog' }, [ | |
h('header', { className: 'ui-dialog__heading' }, [ | |
Label('Remove Bucket') | |
]), | |
h('footer', { className: 'ui-dialog__actions' }, [ | |
Button({ label: 'Cancel', onclick: props.oncancel }), | |
Button({ label: 'Confirm', onclick: props.onconfirm }) | |
]) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment