Native nodes, no wrapper
Every tag calls document.createElement and returns that node.
There is no wrapper object between your code and the DOM.
One function per tag. Props, attributes, children and event listeners go in. A native DOM node comes out.
$ npm install -D fiorejs
No runtime dependencies. TypeScript declarations included.
import { div, button } from 'fiorejs';
const save = () => console.log('saved');
const card = div
.props({ className: 'card' })
.attrs({ 'data-state': 'open' })
.create(
button.on({ click: save }).create('Save'),
);
document.body.appendChild(card);
The call creates a node, applies the data you passed and returns it. Every behaviour below links to the line that implements it.
Every tag calls document.createElement and returns that node.
There is no wrapper object between your code and the DOM.
Props, attributes, children and listeners are applied in that order, whatever the order of the builder calls.
A plain object such as style or dataset is merged into the element's existing object.
Only own keys are copied, so a polluted prototype never reaches the element.
Pass nodes, strings, numbers or arrays of them. null, undefined,
true and false are skipped.
A listener in on can be a function, or an object with handler and
options for addEventListener.
Each factory returns the element type from HTMLElementTagNameMap,
with the same pattern for SVG and MathML.
The same builder works for div, circle or mi.
Every method is optional, and .create() creates the element. A plain call
such as div({ props, attrs, on, children }) takes the same keys.
JavaScript properties, including nested objects such as style.
Values passed to setAttribute. null, undefined
and false leave an attribute out.
Passed to .create(): nodes, strings, numbers or arrays of them; empty
values are skipped.
Listeners are attached after the children, as a handler or as
{ handler, options }.
import { element } from 'fiorejs';
const panel = element('section')
.props({ className: 'panel' })
.attrs({ 'aria-label': 'Details' })
.on({
click: { handler: onClick, options: { once: true } },
})
.create([
element('h2')('Details'),
element('p')('Built with functions.'),
]);
element(name) returns the tag for a name, with the same methods as the named
export, so element('div') works wherever div does.
Named exports for HTML, SVG and MathML. Each entry point ships its own type declarations.
Install from npm, import a tag and append the node. The package is ESM and has no
runtime dependencies. Coming from version 1.x or html-dom-js? Read
Upgrading from 1.x.
element.$ npm install -D fiorejs
import { div } from 'fiorejs';
document.body.appendChild(
div('Hello'),
);