1.3.2 • Published 18 days ago

@enhance/base-element v1.3.2

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
18 days ago

enhance-base-element

Base Element class for Enhance components.

The Enhance Base Element enables reuse of single file components.

Install

npm i @enhance/base-element

Usage

Reusing a single file component.

/pages/index.html

<my-component heading="Heyo!"></my-component>

/elements/my-header.mjs

export default function MyHeader({ html, state }) {
  const { attrs={} } = state
  const { heading='default' } = attrs
  return html`
    <h1>${heading}</h1>
  `
}

/browser/index.mjs

import BaseElement from '@enhance/base-element'
import MyHeaderElement from '../elements/my-header.mjs'

class MyHeader extends BaseElement {
  constructor() {
    super()
    this.innerHTML = this.render({
      html: this.html,
      state: this.state
    })
  }

  render(args) {
    return MyHeaderElement(args)
  }
  // Specify what attributes to use for updating the component
  static get observedAttributes() {
    return [ 'heading' ]
  }
  // adding an attribute changed handler will get automatically called when the attribute changes if it matches the naming convention of ${attributeName}Changed
  headingChanged(value) {
    const header = this.querySelector('h1')
    header.innerHTML = value
  }
}
customElements.define('my-component', MyComponent)
1.3.2

18 days ago

1.2.0

9 months ago

1.1.0

9 months ago

1.0.1

10 months ago

1.3.1

6 months ago

1.3.0

7 months ago

1.0.0

2 years ago