Skip to content

Latest commit

 

History

History

van_element

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Van Element

Author: Atmos4

WebComponents with VanJS

Create VanJS web components with ease. See it in action on CodePen!.

Main repository

See the source code, contribute and raise issues:
https://github.com/Atmos4/van-element

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

  • automatic hydration of VanJS inside your HTML
  • reusable components without extra boilerplate
  • isolated styles and slots with Web components
  • only 40 lines of code (300b min+gzip)