@designcrowd/fe-shared-lib 1.2.11-ml-currency → 1.2.11-ml-currency-2

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.
@@ -14,12 +14,72 @@ export const audCurrency = {
14
14
  abbreviation: 'AU',
15
15
  };
16
16
 
17
+ export const gbpCurrency = {
18
+ id: 3,
19
+ name: 'British Pound',
20
+ iso4127Code: 'GBP',
21
+ symbol: '£',
22
+ abbreviation: 'UK',
23
+ };
24
+
17
25
  export const euroCurrency = {
18
- id: 999,
26
+ id: 4,
19
27
  name: 'Euro',
20
28
  iso4127Code: 'EUR',
21
29
  symbol: '€',
22
30
  abbreviation: 'EU',
23
31
  };
24
32
 
25
- export const currencies = [usdCurrency, audCurrency, euroCurrency];
33
+ export const inrCurrency = {
34
+ id: 5,
35
+ name: 'Indian Rupee',
36
+ iso4127Code: 'INR',
37
+ symbol: '₹',
38
+ abbreviation: 'IN',
39
+ };
40
+
41
+ export const phpCurrency = {
42
+ id: 6,
43
+ name: 'Philippine Peso',
44
+ iso4127Code: 'PHP',
45
+ symbol: '₱',
46
+ abbreviation: 'PH',
47
+ };
48
+
49
+ export const brlCurrency = {
50
+ id: 7,
51
+ name: 'Brazilian Real',
52
+ iso4127Code: 'BRL',
53
+ symbol: 'R$',
54
+ abbreviation: 'R',
55
+ };
56
+
57
+ export const mxnCurrency = {
58
+ id: 8,
59
+ name: 'Mexican Peso',
60
+ iso4127Code: 'MXN',
61
+ symbol: 'MX$',
62
+ abbreviation: 'MX',
63
+ };
64
+
65
+ export const zarCurrency = {
66
+ id: 9,
67
+ name: 'South African Rand',
68
+ iso4127Code: 'ZAR',
69
+ symbol: 'R',
70
+ abbreviation: 'R',
71
+ };
72
+
73
+ export const currencies = [
74
+ usdCurrency,
75
+ audCurrency,
76
+ gbpCurrency,
77
+ euroCurrency,
78
+ inrCurrency,
79
+ phpCurrency,
80
+ brlCurrency,
81
+ mxnCurrency,
82
+ zarCurrency,
83
+ ];
84
+
85
+ export const locales = [ 'en_US', 'fr_FR', 'es_ES', 'pt_PT', 'de-DE']
@@ -1,5 +1,5 @@
1
1
  import Price from './Price.vue';
2
- import { currencies } from './Price.fixtures';
2
+ import { currencies, locales } from './Price.fixtures';
3
3
 
4
4
  // noinspection JSUnusedGlobalSymbols
5
5
  export default {
@@ -7,6 +7,7 @@ export default {
7
7
  component: Price,
8
8
  args: {
9
9
  currencyName: currencies[0].name,
10
+ locale: locales[0]
10
11
  },
11
12
  argTypes: {
12
13
  amount: {
@@ -16,6 +17,10 @@ export default {
16
17
  control: { type: 'select' },
17
18
  options: currencies.map((x) => x.name),
18
19
  },
20
+ locale: {
21
+ control: { type: 'select' },
22
+ options: locales,
23
+ },
19
24
  },
20
25
  };
21
26
 
@@ -31,12 +36,16 @@ export const Sample = {
31
36
  selectedCurrency() {
32
37
  return currencies.find((x) => x.name === this.args.currencyName);
33
38
  },
39
+ selectedLocale() {
40
+ return locales.find((x) => x === this.args.locale);
41
+ },
34
42
  },
35
43
  template: `
36
44
  <span>
37
45
  <price
38
46
  v-bind="args"
39
47
  :currency="selectedCurrency"
48
+ :locale="selectedLocale"
40
49
  />
41
50
  </span>
42
51
  `,
@@ -59,6 +68,9 @@ export const WithFraction = {
59
68
  selectedCurrency() {
60
69
  return currencies.find((x) => x.name === this.args.currencyName);
61
70
  },
71
+ selectedLocale() {
72
+ return locales.find((x) => x === this.args.locale);
73
+ },
62
74
  },
63
75
  template: `
64
76
  <span>
@@ -66,7 +78,7 @@ export const WithFraction = {
66
78
  v-bind="args"
67
79
  :currency="selectedCurrency"
68
80
  fraction="2"
69
- :show-abbreviation="true"
81
+ :locale="selectedLocale"
70
82
  />
71
83
  </span>
72
84
  `,
@@ -89,6 +101,9 @@ export const AlwaysShowFractionOn = {
89
101
  selectedCurrency() {
90
102
  return currencies.find((x) => x.name === this.args.currencyName);
91
103
  },
104
+ selectedLocale() {
105
+ return locales.find((x) => x === this.args.locale);
106
+ },
92
107
  },
93
108
  template: `
94
109
  <span>
@@ -97,7 +112,7 @@ export const AlwaysShowFractionOn = {
97
112
  :always-show-fraction="true"
98
113
  :currency="selectedCurrency"
99
114
  fraction="2"
100
- :show-abbreviation="true"
115
+ :locale="selectedLocale"
101
116
  />
102
117
  </span>
103
118
  `,
@@ -128,7 +143,7 @@ export const AlwaysShowFractionOff = {
128
143
  :always-show-fraction="false"
129
144
  :currency="selectedCurrency"
130
145
  fraction="2"
131
- :show-abbreviation="true"
146
+ :locale="selectedLocale"
132
147
  />
133
148
  </span>
134
149
  `,
@@ -151,6 +166,9 @@ export const WithSuffix = {
151
166
  selectedCurrency() {
152
167
  return currencies.find((x) => x.name === this.args.currencyName);
153
168
  },
169
+ selectedLocale() {
170
+ return locales.find((x) => x === this.args.locale);
171
+ },
154
172
  },
155
173
  template: `
156
174
  <span>
@@ -159,8 +177,8 @@ export const WithSuffix = {
159
177
  :always-show-fraction="true"
160
178
  :currency="selectedCurrency"
161
179
  fraction="2"
162
- :show-abbreviation="true"
163
180
  :suffix="suffix"
181
+ :locale="selectedLocale"
164
182
  />
165
183
  </span>
166
184
  `,
@@ -171,3 +189,35 @@ export const WithSuffix = {
171
189
  suffix: '/yr',
172
190
  },
173
191
  };
192
+
193
+ export const WithLocale = {
194
+ render: (args, { argTypes }) => {
195
+ return {
196
+ components: { Price },
197
+ props: Object.keys(argTypes),
198
+ setup() {
199
+ return { args };
200
+ },
201
+ computed: {
202
+ selectedCurrency() {
203
+ return currencies.find((x) => x.name === this.args.currencyName);
204
+ },
205
+ selectedLocale() {
206
+ return locales.find((x) => x === this.args.locale);
207
+ },
208
+ },
209
+ template: `
210
+ <span>
211
+ <price
212
+ v-bind="args"
213
+ :currency="selectedCurrency"
214
+ :locale="selectedLocale"
215
+ />
216
+ </span>
217
+ `,
218
+ };
219
+ },
220
+ args: {
221
+ amount: 22.0,
222
+ },
223
+ };
@@ -26,7 +26,7 @@ export default {
26
26
  required: false,
27
27
  default: null,
28
28
  },
29
- localeCurrency: {
29
+ locale: {
30
30
  type: String,
31
31
  required: false,
32
32
  default: null,
@@ -70,14 +70,15 @@ export default {
70
70
  return 'Free';
71
71
  }
72
72
 
73
- if (this.localeCurrency != null)
73
+ if (this.locale != null)
74
74
  {
75
75
  let amount = i18next.t('{{val, currency}}', {
76
76
  ns: 'fe-shared-lib',
77
77
  val: this.amount,
78
78
  currency: this.currency.iso4127Code,
79
- locale: this.localeCurrency,
80
- minimumFractionDigits: this.fraction
79
+ locale: this.locale,
80
+ maximumFractionDigits: this.fraction,
81
+ useGrouping: false,
81
82
  });
82
83
 
83
84
  return this.standardiseAmount(amount);
@@ -98,10 +99,10 @@ export default {
98
99
  return parsedAmount.toFixed(this.fraction);
99
100
  },
100
101
  currencyAbbreviation() {
101
- return this.showAbbreviation && this.amount > 0 ? this.currency?.abbreviation?.trim() : '';
102
+ return this.showAbbreviation && this.amount && !this.locale > 0 ? this.currency?.abbreviation?.trim() : '';
102
103
  },
103
104
  currencySymbol() {
104
- if (!this.amount || this.amount === 0 || this.localeCurrency) {
105
+ if (!this.amount || this.amount === 0 || this.locale) {
105
106
  return '';
106
107
  }
107
108
 
@@ -129,12 +130,27 @@ export default {
129
130
  },
130
131
  methods: {
131
132
  standardiseAmount(amount) {
133
+ // i18next always uses iso code for ZAR, prefer symbol over iso code
134
+ if (amount.includes(this.currency.iso4127Code)) {
135
+ return amount.replace(this.currency.iso4127Code, this.currency.symbol);
136
+ }
137
+
138
+ // show abbreviation locale logic
139
+ // note: showAbbreviaton is only passed as true for symbol = "$"
140
+ if (this.currency.symbol != '$') {
141
+ return amount
142
+ }
143
+
144
+ // AUD edge case for en_US
132
145
  if (this.currency.iso4127Code == 'AUD') {
133
- return amount.replace('A$', this.currency.symbol);
146
+ amount = amount.replace('A$', this.currency.symbol);
134
147
  }
135
148
 
136
- if (this.currency.iso4127Code == 'ZAR') {
137
- return amount.replace(this.currency.iso4127Code, this.currency.symbol);
149
+ if (this.showAbbreviation && !amount.includes(this.currency.abbreviation)) {
150
+ return `${this.currency?.abbreviation}${amount}`
151
+
152
+ } else if (!this.showAbbreviation && amount.includes(this.currency.abbreviation)) {
153
+ return amount.replace(this.currency.abbreviation, '');
138
154
  }
139
155
 
140
156
  return amount;