tiny-lit
TypeScript icon, indicating that this package has built-in type declarations

1.4.2 • Public • Published

Tiny-Lit

Just another JavaScript library for building user interfaces using template literals

Usage

Html template

import { html, render } from 'tiny-lit';
 
const quote = message => html`
    <div>
        <blockquote>
            ${message}
        </blockquote>
    </div>
`;
 
render(
    quote(
        `
        Neque porro quisquam est 
        qui dolorem ipsum quia dolor sit amet, 
        consectetur, adipisci velit
        `
    ),
    document.body
);

List of templates

import { html, render } from 'tiny-lit';
 
const listItem = item => (
    html`<li>${item}</li>`.withKey(item)
);
 
const list = items => (
    html`
        <ul>
            ${items.map(listItem)}
        </ul>
    `
);
 
render(
    list(['pippo', 'pluto', 'paperino']),
    document.body
);

Custom element

import { Element, html, withElement } from 'tiny-lit';
 
class Clock extends Element {
    connectedCallback() {
        setInterval(() => 
            this.setState({
                time: new Date().toLocaleTimeString()
            }), 1000);
    }
 
    getTemplate() {
        return html`<div>${this.state.time}</div>`;
    }
}
customElement.define('my-clock', Clock);
 
class Select extends withElement(HTMLSelectElement) {
    getTemplate() {
        return html`
            ${this.state.options.map( 
                option => html`
                    <option value=${option.value}>
                        ${option.label}
                    </option>`.withKey(option.value)
            )}
        `;
    }
}
customElement.define('my-select', Select);
<my-clock></my-clock>

Observed props

All observed props will trigger an update when they change

import { Element, html, withProps } from 'tiny-lit';
 
class Clock extends withProps(Element) {
    title = 'My clock';
 
    static get properties() {
        return {
            title: String
        };
    }
 
    connectedCallback() {
        setInterval(() => 
            this.setState({
                time: new Date().toLocaleTimeString()
            }), 1000);
    }
 
    getTemplate() {
        return html`
            <h1>${this.title}</h1>
            <div>${this.state.time}</div>
        `;
    }
}
customElement.define('my-clock', Clock);
<my-clock id="clock"></my-clock>
 
<script>
    const clock = document.querySelector('#clock');
    clock.title = 'The clock';
</script> 

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.4.27latest
1.0.180next

Version History

VersionDownloads (Last 7 Days)Published
1.4.27
1.4.10
1.4.00
1.3.20
1.3.10
1.3.00
1.2.40
1.2.30
1.2.20
1.2.10
1.2.00
1.1.30
1.1.20
1.1.10
1.1.00
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10

Package Sidebar

Install

npm i tiny-lit

Weekly Downloads

7

Version

1.4.2

License

MIT

Unpacked Size

44.4 kB

Total Files

22

Last publish

Collaborators

  • alenaksu