Skip to content

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

License

Notifications You must be signed in to change notification settings

socketsupply/tonic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

648b5f7 · May 26, 2024
Oct 23, 2023
Dec 22, 2023
Oct 11, 2023
Jan 12, 2023
Jan 12, 2023
Feb 6, 2021
Mar 2, 2022
Dec 21, 2022
Dec 21, 2022
Dec 21, 2022
May 26, 2024
Oct 11, 2023
Oct 20, 2023
Oct 22, 2021

Repository files navigation

tonic

https://tonicframework.dev



Tonic is a low profile component framework for the web. It's one file, less than 3kb gzipped and has no dependencies. It's designed to be used with modern Javascript and is compatible with all modern browsers and built on top of the Web Components. It was designed to be similar to React but 100x easier to reason about.

Installation

npm install @socketsupply/tonic

Usage

import Tonic from '@socketsupply/tonic'

You can use functions as components. They can be async or even an async generator function.

async function MyGreeting () {
  const data = await (await fetch('https://example.com/data')).text()
  return this.html`<h1>Hello, ${data}</h1>`
}

Or you can use classes. Every class must have a render method.

class MyGreeting extends Tonic {
  async * render () {
    yield this.html`<div>Loading...</div>`

    const data = await (await fetch('https://example.com/data')).text()
    return this.html`<div>Hello, ${data}.</div>`
  }
}
Tonic.add(MyGreeting, 'my-greeting')

After adding your Javascript to your HTML, you can use your component anywhere.

<html>
  <head>
    <script src="my-greeting.js"></script>
  </head>
  <body>
    <my-greeting></my-greeting>
  </body>
</html>

Useful links

Copyright (c) 2023 Socket Supply Co.

MIT License