3.0.0 • Published 6 years ago

@nicolasparada/html-tag v3.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

@nicolasparada/html-tag

HTML tagged template literal function.

Example Usage

import html from 'https://unpkg.com/@nicolasparada/html-tag'

const template = html`
    <style>:host { display: block }</style>
    Hello, <slot>world</slot>!
`

class HelloWorld extends HTMLElement {
    constructor() {
        super()
        this.attachShadow({ mode: 'open' })
    }

    connectedCallback() {
        this.shadowRoot.appendChild(template.content.cloneNode(true))
    }
}

customElements.define('hello-world', HelloWorld)

This function will create an HTMLTemplateElement. It's meant to give just syntax highlighting.

If you try to use it inside itself again, it will pay the cost of creating a template again and getting its innerHTML. So, use a normal string or something like String.raw.

Instead of:

html`
    <ul>
        ${['foo', 'bar'].map(item => html`
            <li>${item}</li>
        `)}
    </ul>
`

Do:

html`
    <ul>
        ${['foo', 'bar'].map(item => {
            const html = String.raw
            return html`
                <li>${item}</li>
            `
        })}
    </ul>
`
3.0.0

6 years ago

2.0.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago