-
Notifications
You must be signed in to change notification settings - Fork 11
feat: metric card component #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,8 @@ $cloud-3: #a1c5e0; | |
|
|
||
| $brown-1: #9e4c41; | ||
|
|
||
| $off-white: #f6f6f64d; | ||
|
|
||
| /* | ||
| * Specific Usage | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| @import 'mixins'; | ||
|
|
||
| .metric-card { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 4px; | ||
| border: 1px solid; | ||
| padding: 10px; | ||
| border-radius: 6px; | ||
|
|
||
| .indicator-and-title { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 6px; | ||
|
|
||
| .indicator { | ||
| .dot { | ||
| width: 8px; | ||
| height: 8px; | ||
| border-radius: 50%; | ||
| } | ||
| } | ||
|
|
||
| .title-text { | ||
| @include chart-small-regular($gray-7); | ||
| text-transform: uppercase; | ||
| } | ||
| } | ||
|
|
||
| .value { | ||
| @include header-5($gray-7); | ||
| margin-left: 14px; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { IconType } from '@hypertrace/assets-library'; | ||
| import { createComponentFactory } from '@ngneat/spectator/jest'; | ||
| import { MockComponent } from 'ng-mocks'; | ||
| import { IconComponent } from '../icon/icon.component'; | ||
| import { MetricCardIndicatorType } from './metric-card'; | ||
| import { MetricCardComponent } from './metric-card.component'; | ||
|
|
||
| describe('Metric Card Component', () => { | ||
| const createComponent = createComponentFactory({ | ||
| component: MetricCardComponent, | ||
| declarations: [MockComponent(IconComponent)], | ||
| shallow: true | ||
| }); | ||
|
|
||
| test('should render everything correctly', () => { | ||
| const spectator = createComponent({ | ||
| props: { | ||
| value: 123 | ||
| } | ||
| }); | ||
|
|
||
| expect(spectator.query('.metric-card')).toExist(); | ||
| expect(spectator.query('.dot')).toExist(); | ||
| expect(spectator.query('.value')).toHaveText('123'); | ||
| expect(spectator.query(IconComponent)).not.toExist(); | ||
|
|
||
| spectator.setInput({ | ||
| icon: IconType.Add, | ||
| indicator: MetricCardIndicatorType.Icon | ||
| }); | ||
|
|
||
| expect(spectator.query('.dot')).not.toExist(); | ||
| expect(spectator.query(IconComponent)).toExist(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
| import { Color } from '@hypertrace/common'; | ||
| import { IconSize } from '../icon/icon-size'; | ||
| import { MetricCardIndicatorType } from './metric-card'; | ||
| @Component({ | ||
| selector: 'ht-metric-card', | ||
| styleUrls: ['./metric-card.component.scss'], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: ` | ||
| <div class="metric-card" [style.backgroundColor]="this.backgroundColor" [style.borderColor]="this.borderColor"> | ||
| <div class="indicator-and-title"> | ||
| <div class="indicator"> | ||
| <ng-container [ngSwitch]="this.indicator"> | ||
| <ng-container *ngSwitchCase="'${MetricCardIndicatorType.Dot}'"> | ||
| <div class="dot" [style.backgroundColor]="this.indicatorColor"></div> | ||
| </ng-container> | ||
| <ng-container *ngSwitchCase="'${MetricCardIndicatorType.Icon}'"> | ||
| <ht-icon | ||
| *ngIf="this.icon" | ||
| class="icon" | ||
| [icon]="this.icon" | ||
| size="${IconSize.Small}" | ||
| [color]="this.indicatorColor" | ||
| ></ht-icon> | ||
| </ng-container> | ||
| </ng-container> | ||
| </div> | ||
| <div class="title-text">{{ this.titleText }}</div> | ||
| </div> | ||
| <div class="value">{{ value }}</div> | ||
| </div> | ||
| ` | ||
| }) | ||
| export class MetricCardComponent { | ||
| @Input() | ||
| public titleText?: string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be simplified to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I do not want that, this basically collide with HTML |
||
|
|
||
| @Input() | ||
| public value?: string | number; | ||
|
|
||
| @Input() | ||
| public indicator: MetricCardIndicatorType = MetricCardIndicatorType.Dot; | ||
|
|
||
| @Input() | ||
| public icon?: string; // Only be used when indicator type is Icon | ||
|
|
||
| @Input() | ||
| public indicatorColor: Color = Color.Gray7; | ||
|
|
||
| @Input() | ||
| public backgroundColor: Color = Color.OffWhite; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should also default to white/transparent. |
||
|
|
||
| @Input() | ||
| public borderColor: Color = Color.Transparent; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { CommonModule } from '@angular/common'; | ||
| import { NgModule } from '@angular/core'; | ||
| import { IconModule } from '../icon/icon.module'; | ||
| import { MetricCardComponent } from './metric-card.component'; | ||
|
|
||
| @NgModule({ | ||
| imports: [CommonModule, IconModule], | ||
| declarations: [MetricCardComponent], | ||
| exports: [MetricCardComponent] | ||
| }) | ||
| export class MetricCardModule {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export const enum MetricCardIndicatorType { | ||
| Dot = 'dot', | ||
| Icon = 'icon' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should apply the htDisplayNumber pipe if this is a number and htDisplayString pipe if its a string.