Newer
Older

Ekaterina Kondareva
committed
export interface KeyFigureValue {
heading: string;
description: string;
}
import {Component, ComponentInterface, Watch, Prop, h} from '@stencil/core';
import {KeyHighlightVariants} from '../../utils/utils';
@Component({
tag: 'hy-key-figure-group',
styleUrl: 'hy-key-figure-group.scss',
shadow: true
})
export class HyKeyFigureGroup implements ComponentInterface {
@Prop() variant: KeyHighlightVariants = KeyHighlightVariants.default;
private _dataItems: KeyFigureValue[];
@Prop() dataItems: KeyFigureValue[] | string;
@Watch('dataItems')
arrayDataWatcher(newValue: KeyFigureValue[] | string) {
if (typeof newValue === 'string') {
this._dataItems = JSON.parse(newValue);
} else {
this._dataItems = newValue;
}
}
componentWillLoad() {
this.arrayDataWatcher(this.dataItems);
}
if (count % 3 == 0) {
className = 'box-3';
} else if (count % 4 == 0) {
className = 'box-4';
} else if (count % 5 == 0) {
className = 'box-5';
}
return className;
}

Ekaterina Kondareva
committed
render() {
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const classAttributes = [this.variant, 'hy-key-figure-group-container'].join(' ');
const classRowAttributes = ['hy-key-figure-group'].join(' ');
const classRowCenteredAttributes = ['hy-key-figure-group', 'hy-key-figure-group-centered'].join(' ');
if (this._dataItems.length % 5 == 0) {
return [
<div class={classAttributes}>
<div class={classRowAttributes}>
{this._dataItems.map((x, index) => {
if (index < 3) {
return (
<hy-key-figure class="box-3" variant={this.variant} heading={x.heading} description={x.description} />
);
}
})}
</div>
<div class={classRowCenteredAttributes}>
{this._dataItems.map((x, index) => {
if (index >= 3) {
return (
<hy-key-figure class="box-2" variant={this.variant} heading={x.heading} description={x.description} />
);
}
})}
</div>
</div>
];
} else {
return (
<div class={classAttributes}>
<div class={classRowAttributes}>
{this._dataItems.map((x) => {
return (
<hy-key-figure
class={this.getBoxClassName(this._dataItems.length)}
variant={this.variant}
heading={x.heading}
description={x.description}
/>
);
})}
</div>
</div>
);
}