Feature/migrate currency to unit in value component (#2043)

* Migrate currency to unit

* Update locales
This commit is contained in:
Thomas Kaul
2023-06-04 21:46:49 +02:00
committed by GitHub
parent d630fb900d
commit a53461d257
16 changed files with 435 additions and 411 deletions

View File

@@ -32,15 +32,9 @@
{{ formattedValue }}
</ng-container>
</div>
<small *ngIf="currency && size === 'medium'" class="ml-1">
{{ currency }}
</small>
<small *ngIf="unit && size === 'medium'" class="ml-1">
{{ unit }}
</small>
<div *ngIf="currency && size !== 'medium'" class="ml-1">
{{ currency }}
</div>
<div *ngIf="unit && size !== 'medium'" class="ml-1">
{{ unit }}
</div>

View File

@@ -24,8 +24,9 @@ Loading.args = {
export const Currency = Template.bind({});
Currency.args = {
currency: 'USD',
isCurrency: true,
locale: 'en-US',
unit: 'USD',
value: 7
};

View File

@@ -15,7 +15,6 @@ import { isNumber } from 'lodash';
})
export class ValueComponent implements OnChanges {
@Input() colorizeSign = false;
@Input() currency = '';
@Input() icon = '';
@Input() isAbsolute = false;
@Input() isCurrency = false;
@@ -47,7 +46,7 @@ export class ValueComponent implements OnChanges {
this.absoluteValue = Math.abs(<number>this.value);
if (this.colorizeSign) {
if (this.currency || this.isCurrency) {
if (this.isCurrency) {
try {
this.formattedValue = this.absoluteValue.toLocaleString(
this.locale,
@@ -68,6 +67,13 @@ export class ValueComponent implements OnChanges {
);
} catch {}
}
} else if (this.isCurrency) {
try {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: 2,
minimumFractionDigits: 2
});
} catch {}
} else if (this.isPercent) {
try {
this.formattedValue = (this.value * 100).toLocaleString(
@@ -78,13 +84,6 @@ export class ValueComponent implements OnChanges {
}
);
} catch {}
} else if (this.currency || this.isCurrency) {
try {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: 2,
minimumFractionDigits: 2
});
} catch {}
} else if (this.precision || this.precision === 0) {
try {
this.formattedValue = this.value?.toLocaleString(this.locale, {