-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinfo-value-display.component.ts
More file actions
100 lines (90 loc) · 2.93 KB
/
info-value-display.component.ts
File metadata and controls
100 lines (90 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
92
93
94
95
96
97
98
99
100
import { Component, input, OnChanges } from '@angular/core';
import { BatteryPercentageComponent } from '../battery-percentage/battery-percentage.component';
import { ConnectionDotWithMessageComponent } from '../connection-dot-with-message/connection-dot-with-message.component';
import TypographyComponent from '../typography/typography.component';
import ThermometerComponent from '../thermometer/thermometer.component';
import HStackComponent from '../hstack/hstack.component';
import VStackComponent from '../vstack/vstack.component';
import { StyleVariant } from 'src/utils/style-variant';
export interface ThermometerConfig {
type: 'thermometer-config';
currentValue: number;
min: number;
max: number;
}
export interface BatteryConfig {
type: 'battery-config';
percentage: number;
height: number;
width: number;
}
export interface ConnectionDotConfig {
type: 'connection-dot-config';
getStatusColor: () => string;
getStatusMessage?: () => string;
}
export type WidgetConfig = ThermometerConfig | BatteryConfig | ConnectionDotConfig;
@Component({
selector: 'info-value-display',
templateUrl: './info-value-display.component.html',
styleUrl: './info-value-display.component.css',
standalone: true,
imports: [
BatteryPercentageComponent,
ConnectionDotWithMessageComponent,
TypographyComponent,
ThermometerComponent,
HStackComponent,
VStackComponent
]
})
export class InfoValueDisplayComponent implements OnChanges {
ngOnChanges(): void {
this.formattedValue = (this.value()?.toFixed(this.precision()) ?? '-') + (this.unit() === 'C' ? '°' : '');
}
containerStyle = input<string>('');
valueUnitContainerStyle = input<string>('');
value = input<number>();
valueStyle = input<string>('');
boolValue = input<boolean>();
precision = input<number>(1);
subtitle = input<string>('');
subtitleStyle = input<string>('');
unit = input<string>('');
formattedValue = '-';
size = input<'small' | 'medium' | 'large'>('medium');
// Consolidated widget input
widget = input<WidgetConfig>();
enableWidget = input<boolean>(true);
getStatusMessage = (connectDotConfig: ConnectionDotConfig): (() => string) => {
return connectDotConfig.getStatusMessage ? connectDotConfig.getStatusMessage : () => '';
};
getSubtitleStyle = (): string => {
if (this.unit() === '' && this.boolValue() === undefined) {
return this.subtitleStyle() + 'margin-top: 1vh';
}
return this.subtitleStyle();
};
getInfoValueVariant(): StyleVariant {
switch (this.size()) {
case 'small':
return 'info-value-small';
case 'large':
return 'info-value-large';
case 'medium':
default:
return 'info-value';
}
}
getInfoUnitVariant(): StyleVariant {
switch (this.size()) {
case 'small':
return 'info-unit-small';
case 'large':
return 'info-unit-large';
case 'medium':
default:
return 'info-unit';
}
}
}