@itfin/components 1.3.88 → 1.3.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/ITFSettings.js
CHANGED
|
@@ -10,15 +10,39 @@ class ITFSettings {
|
|
|
10
10
|
defaultLocale: 'en_US',
|
|
11
11
|
defaultDisplayDateFormat: 'MM/dd/yyyy',
|
|
12
12
|
// defaultDisplayDateFormat: 'dd.MM.yyyy',
|
|
13
|
-
currencies: []
|
|
13
|
+
currencies: [],
|
|
14
|
+
moneyDisplayFormat: '{symbol}{value}',
|
|
15
|
+
moneyThousandSeparator: ',',
|
|
16
|
+
moneyDecimalSeparator: '.',
|
|
14
17
|
};
|
|
15
18
|
|
|
19
|
+
get moneyDisplayFormat() {
|
|
20
|
+
return this.options.moneyDisplayFormat;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get moneyThousandSeparator() {
|
|
24
|
+
return this.options.moneyThousandSeparator;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get moneyDecimalSeparator() {
|
|
28
|
+
return this.options.moneyDecimalSeparator;
|
|
29
|
+
}
|
|
30
|
+
|
|
16
31
|
get defaultLocale() {
|
|
17
32
|
return this.options.defaultLocale;
|
|
18
33
|
}
|
|
19
34
|
|
|
20
35
|
set defaultLocale(val) {
|
|
21
36
|
this.options.defaultLocale = val;
|
|
37
|
+
if (val === 'uk_UA') {
|
|
38
|
+
this.options.moneyDisplayFormat = '{value}\xA0{symbol}';
|
|
39
|
+
this.options.moneyThousandSeparator = '\xA0';
|
|
40
|
+
this.options.moneyDecimalSeparator = ',';
|
|
41
|
+
} else {
|
|
42
|
+
this.options.moneyDisplayFormat = '{symbol}{value}';
|
|
43
|
+
this.options.moneyThousandSeparator = ',';
|
|
44
|
+
this.options.moneyDecimalSeparator = '.';
|
|
45
|
+
}
|
|
22
46
|
}
|
|
23
47
|
|
|
24
48
|
get currencies() {
|
|
@@ -39,7 +39,7 @@ import itfIcon from '../icon/Icon';
|
|
|
39
39
|
import itfButton from '../button/Button';
|
|
40
40
|
import itfDropdown from '../dropdown/Dropdown.vue';
|
|
41
41
|
import itfTextField from '../text-field/TextField.vue';
|
|
42
|
-
import {
|
|
42
|
+
import { formatMoney, formatRangeDates } from '../../helpers/formatters';
|
|
43
43
|
import FilterBadge from './FilterBadge.vue';
|
|
44
44
|
|
|
45
45
|
export default @Component({
|
|
@@ -52,10 +52,6 @@ export default @Component({
|
|
|
52
52
|
},
|
|
53
53
|
directives: {
|
|
54
54
|
tooltip
|
|
55
|
-
},
|
|
56
|
-
filters: {
|
|
57
|
-
formatMoney,
|
|
58
|
-
formatDateonly
|
|
59
55
|
}
|
|
60
56
|
})
|
|
61
57
|
class FilterPanel extends Vue {
|
|
@@ -155,7 +151,7 @@ class FilterPanel extends Vue {
|
|
|
155
151
|
}
|
|
156
152
|
} else if (facet.type === 'date') {
|
|
157
153
|
const date = DateTime.fromISO(value.value);
|
|
158
|
-
value.label =
|
|
154
|
+
value.label = (date.isValid ? value.value : DateTime.fromISO(facet.options.defaultValue.value)).toFormat('dd MMM yyyy');
|
|
159
155
|
value.isDefault = facet.options.defaultValue ? value.value === facet.options.defaultValue.value : false;
|
|
160
156
|
} else if (facet.type === 'facets-list') {
|
|
161
157
|
const firstItem = facet.options.items.find(item => item.value === (Array.isArray(value.value) ? value.value[0] : value.value));
|
|
@@ -36,6 +36,31 @@ export function parseHours (str, { hoursInDay } = { hoursInDay: 8 }) {
|
|
|
36
36
|
return isNegative * seconds;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
|
|
40
|
+
// https://stptrans.com/wp-content/uploads/2020/02/Working-with-currency-number-and-date-formats.pdf
|
|
41
|
+
export function formatMoney (val, symbol = '', digits = null) {
|
|
42
|
+
const format = ITFSettings.moneyDisplayFormat || '{symbol}{value}';
|
|
43
|
+
const thousandSeparator = ITFSettings.moneyThousandSeparator || ',';
|
|
44
|
+
const decimalSeparator = ITFSettings.moneyDecimalSeparator || '.';
|
|
45
|
+
|
|
46
|
+
if (Number.isNaN(val) || val === null) {
|
|
47
|
+
return '—';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let symbolStr = symbol?.symbol ?? symbol?.Symbol ?? symbol ?? '';
|
|
51
|
+
if (digits === null) {
|
|
52
|
+
digits = symbol.precision ?? symbol.Precision ?? 2;
|
|
53
|
+
}
|
|
54
|
+
const value = parseFloat(val.toString()).toFixed(digits)
|
|
55
|
+
.replace(/\d(?=(\d{3})+\.)/g, '$&' + thousandSeparator)
|
|
56
|
+
.replace(/\.(\d+)$/, decimalSeparator + '$1')
|
|
57
|
+
;
|
|
58
|
+
return format
|
|
59
|
+
.replace('{value}', value)
|
|
60
|
+
.replace('{symbol}', symbolStr)
|
|
61
|
+
.trim();
|
|
62
|
+
}
|
|
63
|
+
|
|
39
64
|
export function formatDate (date, inputFormat = 'yyyy-MM-dd', toFormat) {
|
|
40
65
|
if (!date) {
|
|
41
66
|
return date;
|
|
@@ -89,7 +114,7 @@ export function firstLetters(name) {
|
|
|
89
114
|
export function formatHours (val, removeEmptyMinutes = false) {
|
|
90
115
|
let hours = Math.floor(Math.abs(val) / 60);
|
|
91
116
|
let minutes = Math.abs(val) - hours * 60;
|
|
92
|
-
if (isNaN(minutes)) {
|
|
117
|
+
if (Number.isNaN(minutes)) {
|
|
93
118
|
return '—';
|
|
94
119
|
}
|
|
95
120
|
minutes = Math.floor(minutes);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
parseHours
|
|
2
|
+
parseHours, formatMoney
|
|
3
3
|
} from './formatters';
|
|
4
|
+
import ITFSettings from "../ITFSettings";
|
|
4
5
|
|
|
5
6
|
describe('Formatters', () => {
|
|
6
7
|
const $t = (str) => str;
|
|
@@ -14,4 +15,20 @@ describe('Formatters', () => {
|
|
|
14
15
|
expect(parseHours('12h 10m 10s')).toEqual(12 * 60 * 60 + 10 * 60 + 10);
|
|
15
16
|
expect(parseHours('1d 12h 10m 10s')).toEqual(8 * 60 * 60 + 12 * 60 * 60 + 10 * 60 + 10);
|
|
16
17
|
});
|
|
18
|
+
|
|
19
|
+
test('formatMoney', () => {
|
|
20
|
+
ITFSettings.defaultLocale = 'uk_UA';
|
|
21
|
+
let currency = { Id: 1, Symbol: '#', IsCryptoCurrency: false, Code: 'TTT' };
|
|
22
|
+
expect(formatMoney(1, '$')).toEqual('1,00 $');
|
|
23
|
+
expect(formatMoney(-1, '$')).toEqual('-1,00 $');
|
|
24
|
+
expect(formatMoney(-1000000, currency)).toEqual('-1 000 000,00 #');
|
|
25
|
+
expect(formatMoney(NaN)).toEqual('—');
|
|
26
|
+
|
|
27
|
+
ITFSettings.defaultLocale = 'en_US';
|
|
28
|
+
currency = { Id: 1, Symbol: '#', IsCryptoCurrency: false, Code: 'TTT' };
|
|
29
|
+
expect(formatMoney(1, '$')).toEqual('$1.00');
|
|
30
|
+
expect(formatMoney(-1, '$')).toEqual('$-1.00');
|
|
31
|
+
expect(formatMoney(-1, currency)).toEqual('#-1.00');
|
|
32
|
+
expect(formatMoney(NaN)).toEqual('—');
|
|
33
|
+
});
|
|
17
34
|
});
|