betterthancode / ottavino

tiny, fast and declarative ui - using custom elements API (but not only)
MIT License
75 stars 0 forks source link

ottavino

The piccolo /ˈpɪkəloʊ/ (Italian pronunciation: [ˈpikkolo]; Italian for "small", but named ottavino in Italy)

Tiny, Fast and Declarative User Interface Development

Using native custom elements API (but not only)

Build Status

As simple as it gets.

See the docs

import { component } from 'ottavino'

component({
  tag: 'tiny-moji',
  template: '<span>{{this.moodIcon}}</span>',
  shadow: true, // optional shadow DOM
  properties: {
    moodIcon: '😃'
  },
  attributes: {
    mood: function(newValue /*, oldValue, domElement */) {
      this.moodIcon = newValue === 'sad' ? '😢' : '😃'
    }
  }
})
<tiny-moji></tiny-moji>
<tiny-moji mood="sad"></tiny-moji>

IIFE Version (no es-modules)

<script src="https://github.com/betterthancode/ottavino/raw/master/path/to/ottavino/index.nomodule.js"></script>
window.ottavino.component({
  // here you go
});

Footprint (KBGzipped) ~1.5

Small: npm bundle size

API

component(options: ComponentDescriptor<T?>) => ComponentProxy<T>

ComponentDescriptor

Under the hood

<span>{{this.counter}}</span>
<button onclick="{{this.counter++}}">Count UP!</button>
<button onclick="{{this.counter = 0}}">Reset</button>
<button onclick="{{this.hereBeDragons()}}DONT PUSH BUTTON</button>

Anything evaluated between mustache-braces will be executed within the component's context. Every execution can reach this (the component logic) and component as a reference to the DOM element. The component-handler is a component-proxy object that reflects anything to the actual DOM element and vice versa. The proxy is reachable from the DOM via proxy property name. Event handlers (any attribute that starts with "on...") also can use event as an argument passed into the expression.

Fun

Try mounting your awesome component (with shadow DOM) to the document body instead of using a custom element. In your template, don't use slots. Embed it in another webpage. Fun :unicorn:

Contribution / Roadmap

This project attempts to create the simplest developer experience while using the lastest and greatest features the borwser can provide. Next in the list:

usetheplatform