Skip to content
Snippets Groups Projects
hy-general-list.tsx 1.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • druid's avatar
    druid committed
    export interface ListItemValue {
    
      description: string;
    
    druid's avatar
    druid committed
      id: string;
    
      imageAlt: string;
      imageUrl: string;
    
    druid's avatar
    druid committed
      label: string;
      title: string;
    
      type: string;
    
    druid's avatar
    druid committed
      url: string;
    }
    
    
    druid's avatar
    druid committed
    import {Component, Element, h, Prop, Watch} from '@stencil/core';
    
    druid's avatar
    druid committed
    
    @Component({
      tag: 'hy-general-list',
      styleUrl: 'hy-general-list.scss',
      shadow: true,
    })
    export class HyGeneralList {
      @Prop() dataItems: ListItemValue[] | string;
      private _dataItems: ListItemValue[];
    
    druid's avatar
    druid committed
      @Element() el: HTMLElement;
    
    druid's avatar
    druid committed
    
      @Watch('dataItems')
      arrayDataWatcher(newValue: ListItemValue[] | string) {
        if (typeof newValue === 'string') {
          this._dataItems = JSON.parse(newValue);
        } else {
          this._dataItems = newValue;
        }
      }
    
      componentWillLoad() {
        this.arrayDataWatcher(this.dataItems);
      }
    
      render() {
        const classAttributes = ['hy-general-list'].join(' ');
    
    
        return (
          <ul class={classAttributes}>
            {this._dataItems.map((item) => (
              <li>
    
    druid's avatar
    druid committed
                <hy-general-list-item
    
                  data-location={item.url}
                  description={item.description}
                  id={item.id}
                  imageAlt={item.imageAlt}
                  imageUrl={item.imageUrl}
                  item-title={item.title}
                  label={item.label}
                  type={item.type}
                  url={item.url}
                ></hy-general-list-item>
              </li>
            ))}
          </ul>
        );
    
    druid's avatar
    druid committed
      }
    }