@itfin/components 1.3.87 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itfin/components",
3
- "version": "1.3.87",
3
+ "version": "1.3.89",
4
4
  "author": "Vitalii Savchuk <esvit666@gmail.com>",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -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() {
@@ -40,10 +40,9 @@
40
40
  }
41
41
  </style>
42
42
  <script>
43
- import throttle from 'lodash/throttle';
44
43
  import { Vue, Prop, Model, Component } from 'vue-property-decorator';
45
- import itfTextField from '@itfin/components/src/components/text-field/TextField.vue';
46
- import itfRange from '@itfin/components/src/components/range/Range.vue';
44
+ import itfTextField from '../text-field/TextField.vue';
45
+ import itfRange from '../range/Range.vue';
47
46
 
48
47
  export default @Component({
49
48
  name: 'FilterAmountRange',
@@ -136,12 +136,12 @@
136
136
  </style>
137
137
  <script>
138
138
  import { Vue, Model, Prop, Component } from 'vue-property-decorator';
139
- import itfIcon from '@itfin/components/src/components/icon/Icon';
140
- import itfButton from '@itfin/components/src/components/button/Button';
141
- import itfDropdown from '@itfin/components/src/components/dropdown/Dropdown.vue';
142
- import itfDatePickerInline from '@itfin/components/src/components/datepicker/DatePickerInline.vue';
143
- import itfDateRangePickerInline from '@itfin/components/src/components/datepicker/DateRangePickerInline.vue';
144
- import itfTextField from '@itfin/components/src/components/text-field/TextField.vue';
139
+ import itfIcon from '../icon/Icon';
140
+ import itfButton from '../button/Button';
141
+ import itfDropdown from '../dropdown/Dropdown.vue';
142
+ import itfDatePickerInline from '../datepicker/DatePickerInline.vue';
143
+ import itfDateRangePickerInline from '../datepicker/DateRangePickerInline.vue';
144
+ import itfTextField from '../text-field/TextField.vue';
145
145
  import FilterFacetsList from './FilterFacetsList';
146
146
  import FilterAmountRange from './FilterAmountRange.vue';
147
147
 
@@ -102,9 +102,9 @@
102
102
  </style>
103
103
  <script>
104
104
  import { Vue, Prop, Model, Component } from 'vue-property-decorator';
105
- import itfTextField from '@itfin/components/src/components/text-field/TextField.vue';
106
- import itfButton from '@itfin/components/src/components/button/Button';
107
- import itfCheckbox from '@itfin/components/src/components/checkbox/Checkbox.vue';
105
+ import itfTextField from '../text-field/TextField.vue';
106
+ import itfButton from '../button/Button';
107
+ import itfCheckbox from '../checkbox/Checkbox.vue';
108
108
 
109
109
  export default @Component({
110
110
  name: 'FilterFacetsList',
@@ -34,13 +34,13 @@
34
34
  <script>
35
35
  import { DateTime } from 'luxon';
36
36
  import { Vue, Model, Prop, Component } from 'vue-property-decorator';
37
- import tooltip from '@itfin/components/src/directives/tooltip';
38
- import itfIcon from '@itfin/components/src/components/icon/Icon';
39
- import itfButton from '@itfin/components/src/components/button/Button';
40
- import itfDropdown from '@itfin/components/src/components/dropdown/Dropdown.vue';
41
- import itfTextField from '@itfin/components/src/components/text-field/TextField.vue';
42
- import { formatDateonly, formatMoney, formatRangeDates } from '~/helpers/formatters';
43
- import FilterBadge from '~/components/Nomi/FilterBadge.vue';
37
+ import tooltip from '../../directives/tooltip';
38
+ import itfIcon from '../icon/Icon';
39
+ import itfButton from '../button/Button';
40
+ import itfDropdown from '../dropdown/Dropdown.vue';
41
+ import itfTextField from '../text-field/TextField.vue';
42
+ import { formatMoney, formatRangeDates } from '../../helpers/formatters';
43
+ import FilterBadge from './FilterBadge.vue';
44
44
 
45
45
  export default @Component({
46
46
  components: {
@@ -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 = formatDateonly(date.isValid ? value.value : facet.options.defaultValue.value, 'dd MMM yyyy');
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
  });