Newer
Older

Ekaterina Kondareva
committed
export interface KeyHighlightValue {
heading: string;
description: string;
}
import {Component, ComponentInterface, Watch, Prop, h} from '@stencil/core';
import {KeyHighlightVariants} from '../../utils/utils';
@Component({
tag: 'hy-key-highlight-group',
styleUrl: 'hy-key-highlight-group.scss',
shadow: true
})
export class HyKeyHighlightGroup implements ComponentInterface {
@Prop() variant: KeyHighlightVariants = KeyHighlightVariants.default;
private _dataItems: KeyHighlightValue[];
@Prop() dataItems: KeyHighlightValue[] | string;
@Watch('dataItems')
arrayDataWatcher(newValue: KeyHighlightValue[] | string) {
if (typeof newValue === 'string') {
this._dataItems = JSON.parse(newValue);
} else {
this._dataItems = newValue;
}
}
componentWillLoad() {
this.arrayDataWatcher(this.dataItems);
}
render() {
const classAttributes = [this.variant, 'hy-key-highlight-group'].join(' ');
const dataItemCount = this._dataItems.length;
const classItem = dataItemCount % 4 == 0 ? 'box-4' : 'box';

Ekaterina Kondareva
committed
return (
<div class={classAttributes}>
{this._dataItems.map((x) => {
return (
<hy-key-highlight
class={classItem}
variant={this.variant}
heading={x.heading}
description={x.description}
/>
);

Ekaterina Kondareva
committed
})}
</div>
);
}
}