Skip to content

Commit b892acd

Browse files
feat: header functionality for the list view (#806)
* feat: header functionality for the list view
1 parent 5f7770f commit b892acd

File tree

4 files changed

+75
-29
lines changed

4 files changed

+75
-29
lines changed

projects/components/src/list-view/list-view.component.scss

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
1+
@import 'font';
12
@import 'color-palette';
23

4+
$key-width: 40%;
5+
$value-width: 60%;
6+
$margin-left: 12px;
7+
8+
@mixin grid-view {
9+
width: 100%;
10+
padding: 8px 0;
11+
display: grid;
12+
grid-template-columns: $key-width $value-width;
13+
align-content: center;
14+
}
15+
316
.list-view {
417
height: 100%;
518
width: 100%;
619
overflow: auto;
720
display: flex;
821
flex-direction: column;
922

23+
.header-row,
1024
.data-row {
11-
flex: 0 0 auto;
12-
min-height: 40px;
13-
width: 100%;
14-
word-break: break-word;
15-
padding: 8px 0;
25+
@include grid-view();
26+
}
1627

17-
display: flex;
18-
flex-direction: row;
19-
align-items: center;
20-
font-size: 15px;
21-
font-style: normal;
22-
line-height: 18px;
28+
.header-row {
29+
height: 32px;
30+
background: $gray-1;
31+
box-shadow: inset 0px -1px 0px $gray-2;
32+
border-radius: 6px 6px 0px 0px;
2333

24-
.key {
25-
flex: 1 1 auto;
26-
height: 100%;
27-
width: 40%;
28-
display: flex;
29-
align-items: center;
30-
margin-left: 12px;
31-
font-weight: 500;
34+
.header-key-label,
35+
.header-value-label {
36+
@include overline;
37+
margin-left: $margin-left;
38+
width: 100%;
3239
}
40+
}
3341

42+
.data-row {
43+
@include font-placeholder();
44+
color: $gray-9;
45+
min-height: 40px;
46+
word-break: break-word;
47+
48+
.key,
3449
.value {
35-
flex: 1 1 auto;
3650
height: 100%;
37-
width: 60%;
51+
width: 100%;
3852
display: flex;
3953
align-items: center;
40-
margin-left: 12px;
41-
42-
/* identical to box height, or 120% */
43-
letter-spacing: -0.01em;
54+
margin-left: $margin-left;
55+
}
56+
.key {
57+
font-weight: 500;
4458
}
4559
}
4660

projects/components/src/list-view/list-view.component.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { CommonModule } from '@angular/common';
22
import { Component } from '@angular/core';
33
import { ComponentFixture, TestBed } from '@angular/core/testing';
4-
import { ListViewComponent, ListViewRecord } from './list-view.component';
4+
import { ListViewComponent, ListViewHeader, ListViewRecord } from './list-view.component';
55

66
describe('List View Component', () => {
77
@Component({
88
selector: 'ht-test-host-component',
9-
template: ` <ht-list-view [records]="this.records"></ht-list-view> `
9+
template: ` <ht-list-view [records]="this.records" [header]="this.header"></ht-list-view> `
1010
})
1111
class TestHostComponent {
1212
public records: ListViewRecord[] = [
@@ -19,6 +19,11 @@ describe('List View Component', () => {
1919
value: 'Response 2'
2020
}
2121
];
22+
23+
public header: ListViewHeader = {
24+
keyLabel: 'key',
25+
valueLabel: 'value'
26+
};
2227
}
2328

2429
let fixture: ComponentFixture<TestHostComponent>;
@@ -34,11 +39,22 @@ describe('List View Component', () => {
3439
hostComp = fixture.componentInstance;
3540
});
3641

37-
test('should display rows for each data', () => {
42+
test('should display rows for each data and should display header', () => {
3843
fixture.detectChanges();
3944

4045
const element: HTMLElement = fixture.nativeElement;
4146

47+
const headerElement = element.querySelector<HTMLElement>('.header-row');
48+
expect(headerElement).not.toBeNull();
49+
50+
const headerKeyLabelElement = element.querySelector<HTMLElement>('.header-key-label');
51+
expect(headerKeyLabelElement).not.toBeNull();
52+
expect(headerKeyLabelElement?.textContent).toEqual(hostComp.header.keyLabel);
53+
54+
const headerValueLabelElement = element.querySelector<HTMLElement>('.header-value-label');
55+
expect(headerValueLabelElement).not.toBeNull();
56+
expect(headerValueLabelElement?.textContent).toEqual(hostComp.header.valueLabel);
57+
4258
const rowElements = element.querySelectorAll<HTMLElement>('.data-row');
4359
expect(rowElements).not.toBeNull();
4460
expect(rowElements.length).toBe(2);

projects/components/src/list-view/list-view.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
66
changeDetection: ChangeDetectionStrategy.OnPush,
77
template: `
88
<div class="list-view">
9+
<div *ngIf="this.header" class="header-row">
10+
<div class="header-key-label">
11+
<span>{{ this.header.keyLabel }}</span>
12+
</div>
13+
<div class="header-value-label">
14+
<span>{{ this.header.valueLabel }}</span>
15+
</div>
16+
</div>
917
<div class="data-row" *ngFor="let record of this.records">
1018
<div class="key">
1119
<span>{{ record.key }}</span>
@@ -18,10 +26,18 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
1826
`
1927
})
2028
export class ListViewComponent {
29+
@Input()
30+
public header?: ListViewHeader;
31+
2132
@Input()
2233
public records?: ListViewRecord[];
2334
}
2435

36+
export interface ListViewHeader {
37+
keyLabel: string;
38+
valueLabel: string;
39+
}
40+
2541
export interface ListViewRecord {
2642
key: string;
2743
value: string | number;

projects/components/src/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export * from './link/link.component';
152152
export * from './link/link.module';
153153

154154
// List View
155-
export { ListViewComponent, ListViewRecord } from './list-view/list-view.component';
155+
export { ListViewComponent, ListViewHeader, ListViewRecord } from './list-view/list-view.component';
156156
export { ListViewModule } from './list-view/list-view.module';
157157

158158
// Load Async

0 commit comments

Comments
 (0)