Last active
October 24, 2022 18:04
-
-
Save Nikaoto/f40a108f43318046e8c181e9a0b7a9d9 to your computer and use it in GitHub Desktop.
js micro framework
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
// Copied from https://news.ycombinator.com/item?id=23590750 | |
const $t = document.createTextNode.bind(document); | |
const $e = (t = 'div', p = {},c = []) => { | |
let el = document.createElement(t); | |
Object.assign(el,p); | |
el.append(...c); | |
return el; | |
} | |
// Make a button | |
let button = $e("button", { className: "my-button" }, ["my text"]) | |
document.appendChild(button) | |
// Button constructor | |
let $button = (p={}, c=[]) => $e("button", {className: "my-button", ...p}, c) | |
// Make a menu of buttons (using the button constructor as well) | |
let menuStyle = "background-color: cyan;" | |
let menu = $e("div", { className: "my-menu", style: menuStyle }, [ | |
$e("button", { className: "my-button" }, ["button1"]), | |
$button({}, "button2"), | |
$button({}, "button3"), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good to use with bling.js: https://gist.github.com/paulirish/12fb951a8b893a454b32