Newer
Older

Ekaterina Kondareva
committed
export interface LinkBox {
heading: string;
description: string;
imageUrl: string;
imageAlt: string;
boxUrl: string;
isExternal: boolean;

Ekaterina Kondareva
committed
}
import {Component, ComponentInterface, Watch, Prop, h, Host} from '@stencil/core';

Ekaterina Kondareva
committed
import {LinkBoxVariants} from '../../utils/utils';
@Component({
tag: 'hy-link-box-list',
styleUrl: 'link-box-list.scss',
shadow: false,

Ekaterina Kondareva
committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
})
export class LinkBoxList implements ComponentInterface {
@Prop() variant: LinkBoxVariants = LinkBoxVariants.default;
private _dataItems: LinkBox[];
@Prop() dataItems: LinkBox[] | string;
@Watch('dataItems')
arrayDataWatcher(newValue: LinkBox[] | string) {
if (typeof newValue === 'string') {
this._dataItems = JSON.parse(newValue);
} else {
this._dataItems = newValue;
}
}
componentWillLoad() {
this.arrayDataWatcher(this.dataItems);
}
getBoxClassName(count) {
let className = 'small';
if (count % 3 == 0 || count == 5) {
className = 'big';
} else if (count % 4 == 0 || count == 7) {
className = 'small';
}
return className;
}
render() {
const classAttributes = [this.variant, 'hy-link-box-list'].join(' ');
/*
- Logic:
- 3 items: big
- 4 items: small
- 5 items: big
- 6 items: big
- 7 items: small
- 8 items: small
- 9 items: big
* */
const classItem = this.getBoxClassName(this._dataItems.length);

Ekaterina Kondareva
committed
const classItemAttributes = [this.variant, classItem].join(' ');
return (
<Host>
<div class={classAttributes}>
{this._dataItems.map((x) => {
//var target = x.isExternal ? "true" : "false";
return (
<hy-link-box
class={classItemAttributes}
variant={this.variant}
image-url={x.imageUrl}
image-alt={x.imageAlt}
text-title={x.heading}
text-description={x.description}
url={x.boxUrl}
is-external={x.isExternal}
/>
);
})}
</div>
<hy-box pb="3, 5, 6" />
</Host>