Atmos4 / van-element

Simple function to create VanJS custom elements
MIT License
23 stars 1 forks source link

Van Element - WebComponents with VanJS

A simple function to create VanJS web components. See it in action.

Documentation

https://van-element.pages.dev/.

Usage

import van from "vanjs-core";
import { define } from "vanjs-element";

const { button, div, slot } = van.tags;

define("custom-counter", () => {
  const counter = van.state(0);
  return div(
    slot(),
    counter,
    button({ onclick: () => ++counter.val }, "+"),
    button({ onclick: () => --counter.val }, "-")
  );
});

In your HTML:

<custom-counter>❤️</custom-counter>

<custom-counter>👌</custom-counter>

Why use this