Tonic — A thin wrapper around Web Components

A Low Profile Component Framework – Stable, minimal, easy to audit, zero-dependencies and build-tool-free.

Basic component definition is really simple:

import Tonic from "https://cdn.skypack.dev/@optoolco/tonic"

class MyGreeting extends Tonic {
  render () {
    return this.html`<div>Hello, ${this.props.name ?? 'Stranger'}.</div>`
  }
}

Tonic.add(MyGreeting);

Tonic will automatically convert the CamelCased class name to the proper custom element name.

<my-greeting></my-greeting>
<my-greeting name="Bramus"></my-greeting>

Here’s the code above running on CodePen:

See the Pen
Tonic Web Components Demo
by Bramus (@bramus)
on CodePen.

Also comes with an SSR package.

Tonic →
Tonic (GitHub) →
Tonic SSR (GitHub) →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.