🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@enhance/custom-element

Package Overview
Dependencies
Maintainers
7
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@enhance/custom-element

Enhance Custom Element base class

latest
Source
npmnpm
Version
1.2.4
Version published
Maintainers
7
Created
Source

enhance-custom-element

Enhance Custom Element base class.

Install

npm i @enhance/custom-element

unpkg

import CustomElement from 'https://unpkg.com/@enhance/custom-element?module=true'

Usage

/pages/index.html

<my-header heading="YOLO!"></my-header>

/elments/my-header-element.mjs

function MyHeaderElement({ html, state  }) {
  const { attrs={} } = state
  const { heading='default' } = attrs
  return html`
    <style>
      :host {
        color: red;
      }
    </style>
    <h1>${heading}</h1>
  `
}

/browser/index.mjs

import CustomElement from '@enhance/custom-element'
import MyHeaderElement from '../elements/my-header-element.mjs'

class MyHeader extends CustomElement {
  constructor() {
    super()
    this.header = this.querySelector('h1')
  }

  render(args) {
    return MyHeaderElement(args)
  }

  static get observedAttributes() {
    return [ 'heading' ]
  }

  headingChanged(value) {
    this.header.textContent = value
  }
}
customElements.define('my-header', MyHeader)

FAQs

Package last updated on 02 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts