0.7.4 • Published 1 month ago

@webtides/element-js v0.7.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

element-js

Simple and lightweight base classes for web components with a beautiful API. Dependency free.

Introduction

element-js lets you write simple, declarative and beautiful web components without the boilerplate.

How to use

Installation

install element-js

npm install --save @webtides/element-js

Use / Example Element

element-js elements are plain ES6 classes (vanilla JS) with some nice mappings (eg. properties, watch, etc.).

// Import from a CDN
// import { BaseElement, defineElement } from 'https://unpkg.com/@webtides/element-js';
// import { BaseElement, defineElement } from 'https://cdn.skypack.dev/@webtides/element-js';
// or when installed via npm
import { BaseElement, defineElement, Store } from '@webtides/element-js';

const sharedDate = new  Store({date: Date.now()}) 

class ExampleElement extends BaseElement {
    // normal public properties
    greeting = 'Hello';
    name = 'John';

    // lifecycle hook
    connected() {
        this.greet();
    }

    // reactive attributes/properties
    properties() {
        return {
           familyName: 'Doe',
           sharedDate
        };
    }

    // watchers for property changes
    watch() {
        return {
            familyName: (newValue, oldValue) => {
                console.log('familyName changed', newValue, oldValue);
            }
        };
    }

    // computed property
    get computedMsg() {
        return `${this.greeting} ${this.name} ${this.familyName} ${this.sharedDate.date}`;
    }

    // method
    greet() {
        alert('greeting: ' + this.computedMsg);
    }
}
defineElement('example-element', ExampleElement);

To use this element, just import it and use it like any other HTML element

<script type="module" src="example-element.js" />
<example-element family-name="Smith"></example-element>

Documentation

For detailed documentation see the Docs.

Contributing & Development

For contributions and development see contributing docs

License

element-js is open-sourced software licensed under the MIT license.

1.0.0-alpha.12

1 month ago

1.0.0-alpha.11

2 months ago

1.0.0-alpha.10

3 months ago

1.0.0-alpha.9

4 months ago

1.0.0-alpha.8

4 months ago

1.0.0-alpha.7

5 months ago

1.0.0-alpha.6

5 months ago

1.0.0-alpha.5

5 months ago

1.0.0-alpha.4

5 months ago

1.0.0-alpha.3

5 months ago

1.0.0-alpha.2

9 months ago

1.0.0-alpha.1

9 months ago

0.7.4

6 months ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.3

1 year ago

0.6.2

1 year ago

0.5.0

2 years ago

0.7.0

1 year ago

0.6.1

1 year ago

0.4.3

2 years ago

0.6.0

1 year ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.2

2 years ago

0.3.3

3 years ago

0.3.2-rc.3

3 years ago

0.3.2-rc.4

3 years ago

0.3.2-rc.2

3 years ago

0.3.2

3 years ago

0.3.2-publish.1

3 years ago

0.3.2-rc.5

3 years ago

0.3.2-rc.6

3 years ago

0.3.1

3 years ago