0.1.4 • Published 27 days ago

@3share/ui-component v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
27 days ago

AEM UI Component

A simple helper Class to save time while creating component registrations and DOM references to internal element using the Adobe's approach with data-cmp-is="Somecomponent and the reference with hooks data-cmp-hook-somecomponent="nameOfElement".

Installation

npm i @3share/ui-component

Example

HTML

<div data-cmp-is="Slideshow">
  <div data-cmp-hook-slideshow="slides"></div>
  <div data-cmp-hook-slideshow="slides"></div>
  <div data-cmp-hook-slideshow="slides"></div>
  <div data-cmp-hook-slideshow="slides"></div>
  
  <button data-cmp-hook-slideshow="clickButton">Click Here!</button>
</div>

TypeScript

import { Component, descriptor } from '@3share/ui-component';

@descriptor({
  selector: '[data-cmp-is="Slideshow"]', // this is the selector the decorator will use to instantiate this class.
})
class Slideshow extends Component {
  ...

  constructor(cmpRef: HTMLElement) {
    super(cmpRef);
    
    /* Logs the DOM reference to the component itself. */
    console.log(this.$cmp);
    /* 
      Logs and object with all the hooks found on this component. 
      { slides: HTMLElement[], clickButton: HTMLElement[], } 
    */
    console.log(this.$elements);

    this.$elements.slides.forEach((slide) => {
      slide.addEventListener('mouseenter', this.someEventHandler);
    });
    
    this.$elements.button[0].addEventListener('mouseenter', this.someClickHandler);
  }
  
  private someEventHandler(event: MouseEvent):void {}
  
  private this.someClickHandler(event: MouseEvent):void {}
}

export default Slideshow;
0.1.0

27 days ago

0.1.2

27 days ago

0.1.1

27 days ago

0.1.4

27 days ago

0.1.3

27 days ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago