libh

0.0.108 • Public • Published

🐛 libh

Open in StackBlitz NPM Version npm package minimized gzipped size

// get ingredients

import { $, h as html, on } from "libh"


// cook yours

function Component() {

    const count = $(0);

    return html`
        <h1>Count is ${count}</h1>
        <button ${{ [on.click]: () => count.$++ }}>
            Add more!
        </button>
    `;
}


// throw into the DOM

document.body.append(...Component());

Visit live demo.



Install

npm i libh

Download

import { $, h as html } from "https://libh.dev";

Examples

Class-model | Bidirecetional binding | Post-processing

Class-model

import { $, h as html, on, css } from "libh"

const ButtonClass = {
    [css]: {
        color: "white",
        backgroundColor: "blue",
    },
    [on.click]: () => alert("hi")
}

function Main() {

    const count = $(0);

    return html`
        <button ${{ [on.click]: () => count.$++, ...ButtonClass }}>
            I'm styled ${count}!
        </button>
    `
}

Bidirecetional binding

function Linked() {

    const valueHolder = $(0)

    return html`
        <h1>these are linked!</h1>
        <input ${{ value: valueHolder, type: "range" }}>
        <input ${{ value: valueHolder, type: "range" }}>
        <label>value is ${valueHolder}</label>
    `
}

Post-processing

function Canvas() {

    const colorSwitch = $(true);

    return html`
        <canvas ${{ id: "color", [on.click]: () => colorSwitch.switch() }}></canvas>

    `.then(({ color }) => {

        const ctx = color.getContext("2d");
        colorSwitch.into($ => $ ? "red" : "blue").watch($ => {
            ctx.fillStyle = $;
            ctx.fillRect(0, 0, 100, 100);
        });
    })
}

Demo

License

libh is WTFPL licensed.

Dependents (0)

Package Sidebar

Install

npm i libh

Homepage

libh.js.org

Weekly Downloads

14

Version

0.0.108

License

WTFPL

Unpacked Size

16.4 kB

Total Files

9

Last publish

Collaborators

  • ihasq