by glutamate · 6y ago · 0 comments
div(
{ class: "table-responsive" },
table(
{ class: ["table table-sm", opts.onRowSelect && "table-hover"] },
thead(tr(hdrs.map(hdr => headerCell(hdr)))),
tbody(
vs.map(v =>
tr(
mkClickHandler(opts, v),
hdrs.map(hdr =>
td(typeof hdr.key === "string" ? text(v[hdr.key]) : hdr.key(v))
)
)
)
)
)
The first argument to a tag is optionally an object with the attributes, any subsequent arguments are children of the tag, or an array with the children.EDIT:
the library as a gist: https://gist.github.com/glutamate/69d38fb1d2024cb829edfff57d...
[1]: https://github.com/hyperhype/hyperscript (Although this library does not look maintained anymore)
I think combinator libraries like this and one I'm building are definitely better than templating languages, although JSX can also work really well, in particular because it retains the HTML syntax making it easy to copy from the browser into code.
[0] https://github.com/MithrilJS/mithril.js/blob/next/render/hyperscript.jssolid framework, but not great for large applications.
1: https://github.com/bwindels/brawl-chat/blob/master/src/ui/we...
Works very well, and don't need to transpile.
Interestingly, in a very early version classes were allowed to be expressed as arrays of strings just like you had, but in the vast majority of cases a space delimited string worked fine, so this feature was dropped for simplicity/uniformity.
condition && "conditional-class"
At the end of the class list.)