Browse Source

Refactor isInteger

pull/351/head
Thomas 4 years ago
parent
commit
510551c115
  1. 2
      apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html
  2. 7
      libs/ui/src/lib/value/value.component.stories.ts
  3. 16
      libs/ui/src/lib/value/value.component.ts

2
apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html

@ -104,8 +104,6 @@
<div class="col-6 mb-3"> <div class="col-6 mb-3">
<gf-value <gf-value
size="medium" size="medium"
[isCurrency]="false"
[isInteger]="true"
[label]="transactionCount === 1 ? 'Transaction' : 'Transactions'" [label]="transactionCount === 1 ? 'Transaction' : 'Transactions'"
[locale]="data.locale" [locale]="data.locale"
[value]="transactionCount" [value]="transactionCount"

7
libs/ui/src/lib/value/value.component.stories.ts

@ -29,13 +29,6 @@ Currency.args = {
value: 7 value: 7
}; };
export const Integer = Template.bind({});
Integer.args = {
isInteger: true,
locale: 'en-US',
value: 7
};
export const Label = Template.bind({}); export const Label = Template.bind({});
Label.args = { Label.args = {
label: 'Label', label: 'Label',

16
libs/ui/src/lib/value/value.component.ts

@ -18,12 +18,11 @@ export class ValueComponent implements OnChanges {
@Input() colorizeSign = false; @Input() colorizeSign = false;
@Input() currency = ''; @Input() currency = '';
@Input() isCurrency = false; @Input() isCurrency = false;
@Input() isInteger = false;
@Input() isPercent = false; @Input() isPercent = false;
@Input() label = ''; @Input() label = '';
@Input() locale = ''; @Input() locale = '';
@Input() position = ''; @Input() position = '';
@Input() precision = 0; @Input() precision: number | undefined;
@Input() size = ''; @Input() size = '';
@Input() value: number | string = ''; @Input() value: number | string = '';
@ -83,20 +82,15 @@ export class ValueComponent implements OnChanges {
minimumFractionDigits: 2 minimumFractionDigits: 2
}); });
} catch {} } catch {}
} else if (this.isInteger) { } else if (this.precision || this.precision === 0) {
try { try {
this.formattedValue = this.value?.toLocaleString(this.locale, { this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: 0, maximumFractionDigits: this.precision,
minimumFractionDigits: 0 minimumFractionDigits: this.precision
}); });
} catch {} } catch {}
} else if (this.precision) {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
});
} else { } else {
this.formattedValue = this.value.toString(); this.formattedValue = this.value?.toString();
} }
} else { } else {
try { try {

Loading…
Cancel
Save