@lion/ui 0.13.1 → 0.14.1
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/components/input-amount-dropdown/src/LionInputAmountDropdown.js +554 -0
- package/components/input-amount-dropdown/src/currencyUtil.js +324 -0
- package/components/input-amount-dropdown/src/formatters.js +24 -0
- package/components/input-amount-dropdown/src/localizeNamespaceLoader.js +7 -0
- package/components/input-amount-dropdown/src/parsers.js +23 -0
- package/components/input-amount-dropdown/src/serializers.js +24 -0
- package/components/input-amount-dropdown/src/validators.js +22 -0
- package/components/input-amount-dropdown/test/LionInputAmountDropdown.test.js +200 -0
- package/components/input-amount-dropdown/test-helpers/mimicUserChangingDropdown.js +22 -0
- package/components/input-amount-dropdown/test-suites/LionInputAmountDropdown.suite.js +321 -0
- package/components/input-amount-dropdown/translations/en.js +5 -0
- package/components/input-amount-dropdown/types/index.ts +234 -0
- package/components/input-tel/types/index.ts +6 -0
- package/components/localize/src/number/getFractionDigits.js +1 -1
- package/custom-elements.json +5479 -1421
- package/dist-types/components/input-amount-dropdown/src/LionInputAmountDropdown.d.ts +221 -0
- package/dist-types/components/input-amount-dropdown/src/LionInputAmountDropdown.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/src/currencyUtil.d.ts +24 -0
- package/dist-types/components/input-amount-dropdown/src/currencyUtil.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/src/formatters.d.ts +4 -0
- package/dist-types/components/input-amount-dropdown/src/formatters.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/src/localizeNamespaceLoader.d.ts +2 -0
- package/dist-types/components/input-amount-dropdown/src/localizeNamespaceLoader.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/src/parsers.d.ts +2 -0
- package/dist-types/components/input-amount-dropdown/src/parsers.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/src/serializers.d.ts +3 -0
- package/dist-types/components/input-amount-dropdown/src/serializers.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/src/validators.d.ts +12 -0
- package/dist-types/components/input-amount-dropdown/src/validators.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/test/LionInputAmountDropdown.test.d.ts +7 -0
- package/dist-types/components/input-amount-dropdown/test/LionInputAmountDropdown.test.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/test-helpers/mimicUserChangingDropdown.d.ts +12 -0
- package/dist-types/components/input-amount-dropdown/test-helpers/mimicUserChangingDropdown.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/test-suites/LionInputAmountDropdown.suite.d.ts +13 -0
- package/dist-types/components/input-amount-dropdown/test-suites/LionInputAmountDropdown.suite.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/translations/en.d.ts +7 -0
- package/dist-types/components/input-amount-dropdown/translations/en.d.ts.map +1 -0
- package/dist-types/components/input-amount-dropdown/types/index.d.ts +86 -0
- package/dist-types/components/input-amount-dropdown/types/index.d.ts.map +1 -0
- package/dist-types/components/input-tel/types/index.d.ts +1 -1
- package/dist-types/components/input-tel/types/index.d.ts.map +1 -1
- package/dist-types/components/localize/src/number/getFractionDigits.d.ts +1 -1
- package/dist-types/exports/define/lion-input-amount-dropdown.d.ts +2 -0
- package/dist-types/exports/define/lion-input-amount-dropdown.d.ts.map +1 -0
- package/dist-types/exports/input-amount-dropdown-test-helpers.d.ts +2 -0
- package/dist-types/exports/input-amount-dropdown-test-helpers.d.ts.map +1 -0
- package/dist-types/exports/input-amount-dropdown-test-suites.d.ts +2 -0
- package/dist-types/exports/input-amount-dropdown-test-suites.d.ts.map +1 -0
- package/dist-types/exports/input-amount-dropdown.d.ts +2 -0
- package/dist-types/exports/input-amount-dropdown.d.ts.map +1 -0
- package/dist-types/exports/types/input-amount-dropdown.d.ts +2 -0
- package/dist-types/exports/types/input-amount-dropdown.d.ts.map +1 -0
- package/dist-types/tsconfig.tsbuildinfo +1 -1
- package/docs/components/checkbox-group/overview.md +2 -2
- package/docs/components/collapsible/overview.md +1 -1
- package/docs/components/combobox/overview.md +1 -1
- package/docs/components/combobox/use-cases.md +1 -1
- package/docs/components/dialog/overview.md +1 -1
- package/docs/components/fieldset/overview.md +5 -5
- package/docs/components/form/overview.md +3 -3
- package/docs/components/form/use-cases.md +2 -2
- package/docs/components/icon/use-cases.md +1 -1
- package/docs/components/input/overview.md +1 -1
- package/docs/components/input-amount/overview.md +3 -3
- package/docs/components/input-amount-dropdown/api-table.md +210 -0
- package/docs/components/input-amount-dropdown/index.md +13 -0
- package/docs/components/input-amount-dropdown/use-cases.md +103 -0
- package/docs/components/input-date/overview.md +3 -3
- package/docs/components/input-datepicker/overview.md +5 -5
- package/docs/components/input-email/overview.md +2 -2
- package/docs/components/input-file/overview.md +1 -1
- package/docs/components/input-iban/overview.md +2 -2
- package/docs/components/input-range/overview.md +2 -2
- package/docs/components/input-stepper/overview.md +1 -1
- package/docs/components/input-tel/overview.md +1 -1
- package/docs/components/input-tel/use-cases.md +6 -6
- package/docs/components/input-tel-dropdown/overview.md +1 -1
- package/docs/components/listbox/use-cases.md +1 -1
- package/docs/components/radio-group/overview.md +3 -3
- package/docs/components/select/use-cases.md +1 -1
- package/docs/components/select-rich/use-cases.md +1 -1
- package/docs/components/tabs/examples.md +1 -1
- package/docs/fundamentals/index.md +4 -4
- package/docs/fundamentals/node-tools/publish-docs/overview.md +3 -3
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/overview.md +2 -2
- package/docs/fundamentals/rationales/accessibility.md +1 -1
- package/docs/fundamentals/systems/core/SlotMixin.md +1 -1
- package/docs/fundamentals/systems/core/overview.md +1 -1
- package/docs/fundamentals/systems/form/formatting-and-parsing.md +4 -4
- package/docs/fundamentals/systems/form/model-value.md +1 -1
- package/docs/fundamentals/systems/form/overview.md +28 -28
- package/docs/fundamentals/systems/form/validate.md +2 -2
- package/docs/fundamentals/systems/localize/overview.md +4 -4
- package/docs/fundamentals/systems/overlays/configuration.md +2 -2
- package/docs/fundamentals/systems/overlays/overview.md +5 -5
- package/docs/fundamentals/systems/overlays/use-cases.md +2 -2
- package/docs/fundamentals/tools/helpers/overview.md +1 -1
- package/docs/fundamentals/tools/singleton-manager/overview.md +4 -4
- package/docs/guides/how-to/create-a-custom-field.md +5 -5
- package/docs/guides/how-to/create-a-form.md +4 -4
- package/docs/guides/how-to/extend-a-native-input.md +2 -2
- package/docs/guides/index.md +8 -8
- package/docs/guides/principles/index.md +5 -5
- package/docs/guides/principles/styling.md +1 -1
- package/exports/define/lion-input-amount-dropdown.js +3 -0
- package/exports/input-amount-dropdown-test-helpers.js +1 -0
- package/exports/input-amount-dropdown-test-suites.js +1 -0
- package/exports/input-amount-dropdown.js +1 -0
- package/exports/types/input-amount-dropdown.ts +9 -0
- package/input-amount-dropdown-test-helpers.js +1 -0
- package/input-amount-dropdown-test-suites.js +1 -0
- package/input-amount-dropdown.js +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { LionInputAmountDropdown } from '@lion/ui/input-amount-dropdown.js';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import {
|
|
4
|
+
fixtureSync as _fixtureSync,
|
|
5
|
+
fixture as _fixture,
|
|
6
|
+
unsafeStatic,
|
|
7
|
+
aTimeout,
|
|
8
|
+
defineCE,
|
|
9
|
+
expect,
|
|
10
|
+
html,
|
|
11
|
+
} from '@open-wc/testing';
|
|
12
|
+
|
|
13
|
+
import { isActiveElement } from '../../core/test-helpers/isActiveElement.js';
|
|
14
|
+
import { mimicUserChangingDropdown } from '../test-helpers/mimicUserChangingDropdown.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {import('../types/index.js').TemplateDataForDropdownInputAmount} TemplateDataForDropdownInputAmount
|
|
18
|
+
* @typedef {HTMLSelectElement|HTMLElement & {modelValue:string}} DropdownElement
|
|
19
|
+
* @typedef {import('lit').TemplateResult} TemplateResult
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const fixture = /** @type {(arg: string | TemplateResult) => Promise<LionInputAmountDropdown>} */ (
|
|
23
|
+
_fixture
|
|
24
|
+
);
|
|
25
|
+
const fixtureSync = /** @type {(arg: string | TemplateResult) => LionInputAmountDropdown} */ (
|
|
26
|
+
_fixtureSync
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {DropdownElement | HTMLSelectElement} dropdownEl
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
function getDropdownValue(dropdownEl) {
|
|
34
|
+
if ('modelValue' in dropdownEl) {
|
|
35
|
+
return dropdownEl.modelValue;
|
|
36
|
+
}
|
|
37
|
+
return dropdownEl.value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {{ klass:LionInputAmountDropdown }} config
|
|
42
|
+
*/
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
export function runInputAmountDropdownSuite({ klass } = { klass: LionInputAmountDropdown }) {
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
const tagName = defineCE(/** @type {* & HTMLElement} */ (class extends klass {}));
|
|
47
|
+
const tag = unsafeStatic(tagName);
|
|
48
|
+
|
|
49
|
+
describe('LionInputAmountDropdown', () => {
|
|
50
|
+
it('syncs value of dropdown on init if input has no value', async () => {
|
|
51
|
+
const el = await fixture(html` <${tag}></${tag}> `);
|
|
52
|
+
expect(el.value).to.equal('');
|
|
53
|
+
expect(getDropdownValue(/** @type {DropdownElement} */ (el.refs.dropdown.value))).to.equal(
|
|
54
|
+
'GBP',
|
|
55
|
+
);
|
|
56
|
+
expect(el.modelValue).to.eql({ currency: 'GBP' });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('syncs value of dropdown on reset if input has no value', async () => {
|
|
60
|
+
const el = await fixture(html` <${tag}></${tag}> `);
|
|
61
|
+
el.modelValue = { currency: 'EUR', amount: 123 };
|
|
62
|
+
await el.updateComplete;
|
|
63
|
+
el.reset();
|
|
64
|
+
await el.updateComplete;
|
|
65
|
+
expect(el.modelValue).to.eql({ currency: 'GBP' });
|
|
66
|
+
expect(el.value).to.equal('');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('syncs value of dropdown on init if input has no value does not influence interaction states', async () => {
|
|
70
|
+
const el = await fixture(html` <${tag}></${tag}> `);
|
|
71
|
+
expect(el.dirty).to.be.false;
|
|
72
|
+
expect(el.prefilled).to.be.false;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('syncs value of dropdown on reset also resets interaction states', async () => {
|
|
76
|
+
const el = await fixture(html` <${tag}></${tag}> `);
|
|
77
|
+
el.modelValue = { currency: 'EUR', amount: 123 };
|
|
78
|
+
await el.updateComplete;
|
|
79
|
+
|
|
80
|
+
expect(el.dirty).to.be.true;
|
|
81
|
+
expect(el.prefilled).to.be.false;
|
|
82
|
+
el.reset();
|
|
83
|
+
await el.updateComplete;
|
|
84
|
+
expect(el.dirty).to.be.false;
|
|
85
|
+
expect(el.prefilled).to.be.false;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('syncs value of dropdown when preferredCurrency is set', async () => {
|
|
89
|
+
const el = await fixture(html` <${tag}
|
|
90
|
+
.preferredCurrencies="${['JPY', 'EUR']}"
|
|
91
|
+
></${tag}> `);
|
|
92
|
+
expect(el.modelValue).to.eql({ currency: 'JPY' });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('sets correct interaction states on init if input has a value', async () => {
|
|
96
|
+
const el = await fixture(
|
|
97
|
+
html` <${tag} .modelValue="${{ currency: 'EUR', amount: 123 }}"></${tag}> `,
|
|
98
|
+
);
|
|
99
|
+
expect(el.dirty).to.be.false;
|
|
100
|
+
expect(el.prefilled).to.be.true;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('Dropdown display', () => {
|
|
104
|
+
it('calls `templates.dropdown` with TemplateDataForDropdownInputAmount object', async () => {
|
|
105
|
+
const modelValue = { currency: 'EUR', amount: 123 };
|
|
106
|
+
const el = fixtureSync(html` <${tag}
|
|
107
|
+
.modelValue="${modelValue}"
|
|
108
|
+
.allowedCurrencies="${['EUR', 'GBP']}"
|
|
109
|
+
.preferredCurrencies="${['GBP']}"
|
|
110
|
+
></${tag}> `);
|
|
111
|
+
const spy = sinon.spy(
|
|
112
|
+
/** @type {typeof LionInputAmountDropdown} */ (el.constructor).templates,
|
|
113
|
+
'dropdown',
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
await el.updateComplete;
|
|
117
|
+
const dropdownNode = el.refs.dropdown.value;
|
|
118
|
+
const templateDataForDropdown = /** @type {TemplateDataForDropdownInputAmount} */ (
|
|
119
|
+
spy.args[0][0]
|
|
120
|
+
);
|
|
121
|
+
expect(templateDataForDropdown).to.eql(
|
|
122
|
+
/** @type {TemplateDataForDropdownInputAmount} */ ({
|
|
123
|
+
data: {
|
|
124
|
+
currency: 'EUR',
|
|
125
|
+
regionMetaList: [
|
|
126
|
+
{
|
|
127
|
+
currencyCode: 'EUR',
|
|
128
|
+
currencySymbol: '€',
|
|
129
|
+
nameForLocale: 'Euro',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
regionMetaListPreferred: [
|
|
133
|
+
{
|
|
134
|
+
currencyCode: 'GBP',
|
|
135
|
+
currencySymbol: '£',
|
|
136
|
+
nameForLocale: 'British Pound',
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
refs: {
|
|
141
|
+
dropdown: {
|
|
142
|
+
labels: {
|
|
143
|
+
selectCurrency: 'Select currency',
|
|
144
|
+
allCurrencies: 'All currencies',
|
|
145
|
+
preferredCurrencies: 'Suggested currencies',
|
|
146
|
+
},
|
|
147
|
+
listeners: {
|
|
148
|
+
// @ts-expect-error [allow-protected]
|
|
149
|
+
change: el._onDropdownValueChange,
|
|
150
|
+
// @ts-expect-error [allow-protected]
|
|
151
|
+
'model-value-changed': el._onDropdownValueChange,
|
|
152
|
+
},
|
|
153
|
+
ref: {
|
|
154
|
+
value: dropdownNode,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
// @ts-expect-error [allow-protected]
|
|
158
|
+
input: el._inputNode,
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
spy.restore();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('can override "all-currencies-label"', async () => {
|
|
166
|
+
const el = fixtureSync(html` <${tag}
|
|
167
|
+
.preferredCurrencies="${['GBP']}"
|
|
168
|
+
></${tag}> `);
|
|
169
|
+
const spy = sinon.spy(
|
|
170
|
+
/** @type {typeof LionInputAmountDropdown} */ (el.constructor).templates,
|
|
171
|
+
'dropdown',
|
|
172
|
+
);
|
|
173
|
+
// @ts-expect-error [allow-protected]
|
|
174
|
+
el._allCurrenciesLabel = 'foo';
|
|
175
|
+
await el.updateComplete;
|
|
176
|
+
const templateDataForDropdown = /** @type {TemplateDataForDropdownInputAmount} */ (
|
|
177
|
+
spy.args[0][0]
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
expect(templateDataForDropdown.refs.dropdown.labels.allCurrencies).to.eql('foo');
|
|
181
|
+
spy.restore();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('can override "preferred-currencies-label"', async () => {
|
|
185
|
+
const el = fixtureSync(html` <${tag}
|
|
186
|
+
.preferredCurrencies="${['GBP']}"
|
|
187
|
+
></${tag}> `);
|
|
188
|
+
const spy = sinon.spy(
|
|
189
|
+
/** @type {typeof LionInputAmountDropdown} */ (el.constructor).templates,
|
|
190
|
+
'dropdown',
|
|
191
|
+
);
|
|
192
|
+
// @ts-expect-error [allow-protected]
|
|
193
|
+
el._preferredCurrenciesLabel = 'foo';
|
|
194
|
+
await el.updateComplete;
|
|
195
|
+
const templateDataForDropdown = /** @type {TemplateDataForDropdownInputAmount} */ (
|
|
196
|
+
spy.args[0][0]
|
|
197
|
+
);
|
|
198
|
+
expect(templateDataForDropdown.refs.dropdown.labels.preferredCurrencies).to.eql('foo');
|
|
199
|
+
spy.restore();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('syncs dropdown value initially from locale', async () => {
|
|
203
|
+
const el = await fixture(html` <${tag} .allowedCurrencies="${['GBP']}"></${tag}> `);
|
|
204
|
+
expect(getDropdownValue(/** @type {DropdownElement} */ (el.refs.dropdown.value))).to.equal(
|
|
205
|
+
'GBP',
|
|
206
|
+
);
|
|
207
|
+
expect(el.modelValue).to.eql({
|
|
208
|
+
currency: 'GBP',
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('syncs disabled attribute to dropdown', async () => {
|
|
213
|
+
const el = await fixture(html` <${tag} disabled></${tag}> `);
|
|
214
|
+
expect(/** @type {HTMLElement} */ (el.refs.dropdown.value)?.hasAttribute('disabled')).to.be
|
|
215
|
+
.true;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('disables dropdown on readonly', async () => {
|
|
219
|
+
const el = await fixture(html` <${tag} readonly></${tag}> `);
|
|
220
|
+
expect(/** @type {HTMLElement} */ (el.refs.dropdown.value)?.hasAttribute('disabled')).to.be
|
|
221
|
+
.true;
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('renders to prefix slot in light dom', async () => {
|
|
225
|
+
const el = await fixture(html` <${tag} .allowedCurrencies="${['GBP']}"></${tag}> `);
|
|
226
|
+
const prefixSlot = /** @type {HTMLElement} */ (
|
|
227
|
+
/** @type {HTMLElement} */ (el.refs.dropdown.value)
|
|
228
|
+
);
|
|
229
|
+
expect(prefixSlot.getAttribute('slot')).to.equal('prefix');
|
|
230
|
+
expect(prefixSlot.slot).to.equal('prefix');
|
|
231
|
+
expect(prefixSlot.parentElement).to.equal(el);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('renders to suffix slot in light dom', async () => {
|
|
235
|
+
class WithSuffixRenderInputAmountDropdown extends LionInputAmountDropdown {
|
|
236
|
+
constructor() {
|
|
237
|
+
super();
|
|
238
|
+
|
|
239
|
+
this._dropdownSlot = 'suffix';
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const suffixTagName = defineCE(WithSuffixRenderInputAmountDropdown);
|
|
244
|
+
const suffixTag = unsafeStatic(suffixTagName);
|
|
245
|
+
|
|
246
|
+
const el = await fixture(html`
|
|
247
|
+
<${suffixTag}
|
|
248
|
+
.allowedCurrencies="${['GBP']}"
|
|
249
|
+
></${suffixTag}>
|
|
250
|
+
`);
|
|
251
|
+
const prefixSlot = /** @type {HTMLElement} */ (
|
|
252
|
+
/** @type {HTMLElement} */ (el.refs.dropdown.value)
|
|
253
|
+
);
|
|
254
|
+
expect(prefixSlot.getAttribute('slot')).to.equal('suffix');
|
|
255
|
+
expect(prefixSlot.slot).to.equal('suffix');
|
|
256
|
+
expect(prefixSlot.parentElement).to.equal(el);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('rerenders light dom when CurrencyUtil loaded', async () => {
|
|
260
|
+
const el = await fixture(html` <${tag} .allowedCurrencies="${['GBP']}"></${tag}> `);
|
|
261
|
+
// @ts-ignore
|
|
262
|
+
const spy = sinon.spy(el, '__rerenderSlot');
|
|
263
|
+
await aTimeout(0);
|
|
264
|
+
expect(spy).to.have.been.calledWith('prefix');
|
|
265
|
+
spy.restore();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('On dropdown value change', () => {
|
|
270
|
+
it('changes the currently active currency code in the textbox', async () => {
|
|
271
|
+
const el = await fixture(html`
|
|
272
|
+
<${tag}
|
|
273
|
+
.allowedCurrencies="${['GBP', 'EUR']}"
|
|
274
|
+
.modelValue="${{ currency: 'GBP', amount: 123 }}"
|
|
275
|
+
></${tag}>
|
|
276
|
+
`);
|
|
277
|
+
// @ts-ignore
|
|
278
|
+
mimicUserChangingDropdown(el.refs.dropdown.value, 'EUR');
|
|
279
|
+
await el.updateComplete;
|
|
280
|
+
expect(el.currency).to.equal('EUR');
|
|
281
|
+
expect(el.modelValue).to.eql({ amount: 123, currency: 'EUR' });
|
|
282
|
+
await el.updateComplete;
|
|
283
|
+
expect(el.value).to.equal('123.00');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('changes the currently active country code in the textbox when empty', async () => {
|
|
287
|
+
const el = await fixture(html` <${tag} .allowedCurrencies="${['GBP', 'EUR']}"></${tag}> `);
|
|
288
|
+
el.value = '';
|
|
289
|
+
// @ts-ignore
|
|
290
|
+
mimicUserChangingDropdown(el.refs.dropdown.value, 'EUR');
|
|
291
|
+
await el.updateComplete;
|
|
292
|
+
await el.updateComplete;
|
|
293
|
+
|
|
294
|
+
expect(el.modelValue).to.eql({ currency: 'EUR', amount: '' });
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('keeps focus on dropdownElement after selection if selected via unopened dropdown', async () => {
|
|
298
|
+
const el = await fixture(
|
|
299
|
+
html` <${tag} .allowedCurrencies="${[
|
|
300
|
+
'GBP',
|
|
301
|
+
'EUR',
|
|
302
|
+
]}" .modelValue="${{ currency: 'GBP', amount: 123 }}"></${tag}> `,
|
|
303
|
+
);
|
|
304
|
+
const dropdownElement = el.refs.dropdown.value;
|
|
305
|
+
// @ts-ignore
|
|
306
|
+
mimicUserChangingDropdown(dropdownElement, 'EUR');
|
|
307
|
+
await el.updateComplete;
|
|
308
|
+
// @ts-expect-error [allow-protected-in-tests]
|
|
309
|
+
expect(isActiveElement(el._inputNode)).to.be.false;
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe('is empty', () => {
|
|
315
|
+
it('ignores initial currencyCode', async () => {
|
|
316
|
+
const el = await fixture(html` <${tag}></${tag}> `);
|
|
317
|
+
// @ts-ignore
|
|
318
|
+
expect(el._isEmpty(), 'empty').to.be.true;
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { LionSelectRich } from '@lion/ui/select-rich.js';
|
|
2
|
+
import { LionCombobox } from '@lion/ui/combobox.js';
|
|
3
|
+
import { OverlayController } from '../../overlays/src/OverlayController.js';
|
|
4
|
+
|
|
5
|
+
type RefTemplateData = {
|
|
6
|
+
ref?: { value?: HTMLElement };
|
|
7
|
+
props?: { [key: string]: any };
|
|
8
|
+
listeners?: { [key: string]: any };
|
|
9
|
+
labels?: { [key: string]: any };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type RegionMeta = {
|
|
13
|
+
currencyCode: CurrencyCode;
|
|
14
|
+
nameForLocale?: string;
|
|
15
|
+
currencySymbol?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type OnDropdownChangeEvent = Event & {
|
|
19
|
+
target: { value?: string; modelValue?: string; _overlayCtrl?: OverlayController };
|
|
20
|
+
detail?: { initialize: boolean };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type DropdownRef = { value: HTMLSelectElement | LionSelectRich | LionCombobox | undefined };
|
|
24
|
+
|
|
25
|
+
export type TemplateDataForDropdownInputAmount = {
|
|
26
|
+
refs: {
|
|
27
|
+
dropdown: RefTemplateData & {
|
|
28
|
+
ref: DropdownRef;
|
|
29
|
+
props?: { style?: string };
|
|
30
|
+
listeners: {
|
|
31
|
+
change: (event: OnDropdownChangeEvent) => void;
|
|
32
|
+
'model-value-changed': (event: OnDropdownChangeEvent) => void;
|
|
33
|
+
};
|
|
34
|
+
labels: { selectCurrency: string };
|
|
35
|
+
};
|
|
36
|
+
input: HTMLInputElement;
|
|
37
|
+
};
|
|
38
|
+
data: {
|
|
39
|
+
currency: CurrencyCode | string;
|
|
40
|
+
regionMetaList: RegionMeta[];
|
|
41
|
+
regionMetaListPreferred: RegionMeta[];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type AmountDropdownModelValue = {
|
|
46
|
+
currency?: CurrencyCode | string;
|
|
47
|
+
amount?: number | string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* All currency codes according to i18n
|
|
52
|
+
*/
|
|
53
|
+
export type CurrencyCode =
|
|
54
|
+
| 'EUR'
|
|
55
|
+
| 'AED'
|
|
56
|
+
| 'AFN'
|
|
57
|
+
| 'XCD'
|
|
58
|
+
| 'ALL'
|
|
59
|
+
| 'AMD'
|
|
60
|
+
| 'AOA'
|
|
61
|
+
| 'ARS'
|
|
62
|
+
| 'USD'
|
|
63
|
+
| 'AUD'
|
|
64
|
+
| 'AWG'
|
|
65
|
+
| 'AZN'
|
|
66
|
+
| 'BAM'
|
|
67
|
+
| 'BBD'
|
|
68
|
+
| 'BDT'
|
|
69
|
+
| 'XOF'
|
|
70
|
+
| 'BGN'
|
|
71
|
+
| 'BHD'
|
|
72
|
+
| 'BIF'
|
|
73
|
+
| 'BMD'
|
|
74
|
+
| 'BND'
|
|
75
|
+
| 'BOB'
|
|
76
|
+
| 'BRL'
|
|
77
|
+
| 'BSD'
|
|
78
|
+
| 'BTN'
|
|
79
|
+
| 'NOK'
|
|
80
|
+
| 'BWP'
|
|
81
|
+
| 'BYN'
|
|
82
|
+
| 'BZD'
|
|
83
|
+
| 'CAD'
|
|
84
|
+
| 'CDF'
|
|
85
|
+
| 'XAF'
|
|
86
|
+
| 'CHF'
|
|
87
|
+
| 'NZD'
|
|
88
|
+
| 'CLP'
|
|
89
|
+
| 'CNY'
|
|
90
|
+
| 'COP'
|
|
91
|
+
| 'CRC'
|
|
92
|
+
| 'CUP'
|
|
93
|
+
| 'CVE'
|
|
94
|
+
| 'ANG'
|
|
95
|
+
| 'CZK'
|
|
96
|
+
| 'DJF'
|
|
97
|
+
| 'DKK'
|
|
98
|
+
| 'DOP'
|
|
99
|
+
| 'DZD'
|
|
100
|
+
| 'EGP'
|
|
101
|
+
| 'MAD'
|
|
102
|
+
| 'ERN'
|
|
103
|
+
| 'ETB'
|
|
104
|
+
| 'FJD'
|
|
105
|
+
| 'FKP'
|
|
106
|
+
| 'GBP'
|
|
107
|
+
| 'GEL'
|
|
108
|
+
| 'GHS'
|
|
109
|
+
| 'GIP'
|
|
110
|
+
| 'GMD'
|
|
111
|
+
| 'GNF'
|
|
112
|
+
| 'GTQ'
|
|
113
|
+
| 'GYD'
|
|
114
|
+
| 'HKD'
|
|
115
|
+
| 'HNL'
|
|
116
|
+
| 'HTG'
|
|
117
|
+
| 'HUF'
|
|
118
|
+
| 'IDR'
|
|
119
|
+
| 'ILS'
|
|
120
|
+
| 'INR'
|
|
121
|
+
| 'IQD'
|
|
122
|
+
| 'IRR'
|
|
123
|
+
| 'ISK'
|
|
124
|
+
| 'JMD'
|
|
125
|
+
| 'JOD'
|
|
126
|
+
| 'JPY'
|
|
127
|
+
| 'KES'
|
|
128
|
+
| 'KGS'
|
|
129
|
+
| 'KHR'
|
|
130
|
+
| 'KMF'
|
|
131
|
+
| 'KPW'
|
|
132
|
+
| 'KRW'
|
|
133
|
+
| 'KWD'
|
|
134
|
+
| 'KYD'
|
|
135
|
+
| 'KZT'
|
|
136
|
+
| 'LAK'
|
|
137
|
+
| 'LBP'
|
|
138
|
+
| 'LKR'
|
|
139
|
+
| 'LRD'
|
|
140
|
+
| 'LSL'
|
|
141
|
+
| 'LYD'
|
|
142
|
+
| 'MDL'
|
|
143
|
+
| 'MGA'
|
|
144
|
+
| 'MKD'
|
|
145
|
+
| 'MMK'
|
|
146
|
+
| 'MNT'
|
|
147
|
+
| 'MOP'
|
|
148
|
+
| 'MRU'
|
|
149
|
+
| 'MUR'
|
|
150
|
+
| 'MVR'
|
|
151
|
+
| 'MWK'
|
|
152
|
+
| 'MXN'
|
|
153
|
+
| 'MYR'
|
|
154
|
+
| 'MZN'
|
|
155
|
+
| 'NAD'
|
|
156
|
+
| 'XPF'
|
|
157
|
+
| 'NGN'
|
|
158
|
+
| 'NIO'
|
|
159
|
+
| 'NPR'
|
|
160
|
+
| 'OMR'
|
|
161
|
+
| 'PAB'
|
|
162
|
+
| 'PEN'
|
|
163
|
+
| 'PGK'
|
|
164
|
+
| 'PHP'
|
|
165
|
+
| 'PKR'
|
|
166
|
+
| 'PLN'
|
|
167
|
+
| 'PYG'
|
|
168
|
+
| 'QAR'
|
|
169
|
+
| 'RON'
|
|
170
|
+
| 'RSD'
|
|
171
|
+
| 'RUB'
|
|
172
|
+
| 'RWF'
|
|
173
|
+
| 'SAR'
|
|
174
|
+
| 'SBD'
|
|
175
|
+
| 'SCR'
|
|
176
|
+
| 'SDG'
|
|
177
|
+
| 'SEK'
|
|
178
|
+
| 'SGD'
|
|
179
|
+
| 'SHP'
|
|
180
|
+
| 'SLE'
|
|
181
|
+
| 'SOS'
|
|
182
|
+
| 'SRD'
|
|
183
|
+
| 'SSP'
|
|
184
|
+
| 'STN'
|
|
185
|
+
| 'SVC'
|
|
186
|
+
| 'SYP'
|
|
187
|
+
| 'SZL'
|
|
188
|
+
| 'THB'
|
|
189
|
+
| 'TJS'
|
|
190
|
+
| 'TMT'
|
|
191
|
+
| 'TND'
|
|
192
|
+
| 'TOP'
|
|
193
|
+
| 'TRY'
|
|
194
|
+
| 'TTD'
|
|
195
|
+
| 'TWD'
|
|
196
|
+
| 'TZS'
|
|
197
|
+
| 'UAH'
|
|
198
|
+
| 'UGX'
|
|
199
|
+
| 'UYU'
|
|
200
|
+
| 'UZS'
|
|
201
|
+
| 'VED'
|
|
202
|
+
| 'VES'
|
|
203
|
+
| 'VND'
|
|
204
|
+
| 'VUV'
|
|
205
|
+
| 'WST'
|
|
206
|
+
| 'XCG'
|
|
207
|
+
| 'YER'
|
|
208
|
+
| 'ZAR'
|
|
209
|
+
| 'ZMW'
|
|
210
|
+
| 'ZWG';
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Type for country to currency list.
|
|
214
|
+
* The type is set to Partial as there are some islands that don't have a corresponding
|
|
215
|
+
* currencyCode as a standard (at the time of writing at least).
|
|
216
|
+
*
|
|
217
|
+
* Said missing countries code: AC, TA, XK
|
|
218
|
+
*/
|
|
219
|
+
export type countryToCurrencyList = Partial<{
|
|
220
|
+
[key in import('../../input-tel/types/index.js').RegionCode]: CurrencyCode;
|
|
221
|
+
}>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Represents a mapping of region codes to currency codes using a Map.
|
|
225
|
+
*/
|
|
226
|
+
export type RegionToCurrencyMap = Map<
|
|
227
|
+
import('../../input-tel/types/index.js').RegionCode,
|
|
228
|
+
CurrencyCode
|
|
229
|
+
>;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Represents a set of all unique currency codes derived from the RegionToCurrencyMap values.
|
|
233
|
+
*/
|
|
234
|
+
export type AllCurrenciesSet = Set<CurrencyCode>;
|
|
@@ -36,6 +36,7 @@ export type RegionCode =
|
|
|
36
36
|
| 'BR'
|
|
37
37
|
| 'BS'
|
|
38
38
|
| 'BT'
|
|
39
|
+
| 'BV'
|
|
39
40
|
| 'BW'
|
|
40
41
|
| 'BY'
|
|
41
42
|
| 'BZ'
|
|
@@ -91,11 +92,13 @@ export type RegionCode =
|
|
|
91
92
|
| 'GP'
|
|
92
93
|
| 'GQ'
|
|
93
94
|
| 'GR'
|
|
95
|
+
| 'GS'
|
|
94
96
|
| 'GT'
|
|
95
97
|
| 'GU'
|
|
96
98
|
| 'GW'
|
|
97
99
|
| 'GY'
|
|
98
100
|
| 'HK'
|
|
101
|
+
| 'HM'
|
|
99
102
|
| 'HN'
|
|
100
103
|
| 'HR'
|
|
101
104
|
| 'HT'
|
|
@@ -180,6 +183,7 @@ export type RegionCode =
|
|
|
180
183
|
| 'PK'
|
|
181
184
|
| 'PL'
|
|
182
185
|
| 'PM'
|
|
186
|
+
| 'PN'
|
|
183
187
|
| 'PR'
|
|
184
188
|
| 'PS'
|
|
185
189
|
| 'PT'
|
|
@@ -215,6 +219,7 @@ export type RegionCode =
|
|
|
215
219
|
| 'TA'
|
|
216
220
|
| 'TC'
|
|
217
221
|
| 'TD'
|
|
222
|
+
| 'TF'
|
|
218
223
|
| 'TG'
|
|
219
224
|
| 'TH'
|
|
220
225
|
| 'TJ'
|
|
@@ -230,6 +235,7 @@ export type RegionCode =
|
|
|
230
235
|
| 'TZ'
|
|
231
236
|
| 'UA'
|
|
232
237
|
| 'UG'
|
|
238
|
+
| 'UM'
|
|
233
239
|
| 'US'
|
|
234
240
|
| 'UY'
|
|
235
241
|
| 'UZ'
|
|
@@ -5,7 +5,7 @@ import { formatNumberToParts } from './formatNumberToParts.js';
|
|
|
5
5
|
* getFractionDigits('JOD'); // return 3
|
|
6
6
|
*
|
|
7
7
|
* @typedef {import('../../types/LocalizeMixinTypes.js').FormatNumberPart} FormatNumberPart
|
|
8
|
-
* @param {string} [currency="EUR"] Currency code e.g. EUR
|
|
8
|
+
* @param {import('../../../input-amount-dropdown/types/index.js').CurrencyCode | string} [currency="EUR"] Currency code e.g. EUR
|
|
9
9
|
* @returns {number} fraction for the given currency
|
|
10
10
|
*/
|
|
11
11
|
export function getFractionDigits(currency = 'EUR') {
|