Get started with elemental CDN

MIT licensed

Elemental: Lightweight JS for interactive UIs with HTML, CSS, JS.

Tags:
  • react
  • react-component
  • ui
  • framework
  • controls
  • element
  • css
  • less

Stable version

Copied!

How to start using elemental CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with elemental CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/elemental/0.5.3/elemental.min.js"></script>
  <style>
    .my-component {
      width: 100px;
      height: 100px;
      background-color: lightblue;
      border: 1px solid black;
    }
  </style>
</head>
<body>
  <div class="my-component"></div>
  <script>
    import { Component, h } from 'elemental';

    @Component
    class MyComponent extends HTMLElement {
      static get observedAttributes() {
        return ['color'];
      }

      constructor() {
        super();
        this.attachShadow({ mode: 'open' });
      }

      attributeChangedCallback(name, oldValue, newValue) {
        if (name === 'color') {
          this.shadowRoot.style.backgroundColor = newValue;
        }
      }

      render() {
        return h('div', { style: { width: '50px', height: '50px' } }, [
          h('div', { style: { width: '25px', height: '25px', backgroundColor: this.getAttribute('color') } }),
          h('div', { style: { width: '25px', height: '25px' } }),
        ]);
      }
    }

    customElements.define('my-component', MyComponent);

    document.querySelector('my-component').setAttribute('color', 'red');
  </script>
</body>
</html>
Copied!
Copied!
Copied!
Copied!

All versions