@lion/ui 0.13.0 → 0.14.0
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/accordion/src/LionAccordion.js +3 -2
- package/components/button/src/LionButton.js +6 -10
- package/components/button/src/LionButtonReset.js +2 -0
- package/components/button/src/LionButtonSubmit.js +2 -0
- package/components/button/test-suites/LionButton.suite.js +0 -14
- package/components/checkbox-group/src/LionCheckbox.js +3 -0
- package/components/checkbox-group/src/LionCheckboxGroup.js +2 -0
- package/components/checkbox-group/src/LionCheckboxIndeterminate.js +3 -0
- package/components/collapsible/src/LionCollapsible.js +4 -1
- package/components/combobox/src/LionCombobox.js +5 -0
- package/components/dialog/src/LionDialog.js +3 -0
- package/components/drawer/src/LionDrawer.js +9 -0
- package/components/fieldset/src/LionFieldset.js +1 -1
- package/components/form/src/LionForm.js +0 -1
- package/components/form-core/src/FormControlMixin.js +10 -0
- package/components/form-core/src/FormatMixin.js +1 -1
- package/components/form-core/src/validate/LionValidationFeedback.js +8 -10
- package/components/form-core/src/validate/ValidateMixin.js +23 -3
- package/components/form-core/test/validate/lion-validation-feedback.test.js +0 -22
- package/components/form-core/test-suites/ValidateMixinFeedbackPart.suite.js +119 -0
- package/components/form-core/types/validate/validate.ts +1 -0
- package/components/icon/src/LionIcon.js +2 -0
- package/components/input-amount-dropdown/src/LionInputAmountDropdown.js +557 -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 +199 -0
- package/components/input-amount-dropdown/test-helpers/mimicUserChangingDropdown.js +22 -0
- package/components/input-amount-dropdown/test-suites/LionInputAmountDropdown.suite.js +322 -0
- package/components/input-amount-dropdown/translations/en.js +5 -0
- package/components/input-amount-dropdown/types/index.ts +234 -0
- package/components/input-file/src/LionInputFile.js +9 -0
- package/components/input-tel/src/LionInputTel.js +3 -0
- package/components/input-tel/types/index.ts +6 -0
- package/components/input-tel-dropdown/src/LionInputTelDropdown.js +2 -0
- package/components/listbox/src/LionListbox.js +2 -0
- package/components/localize/src/number/getFractionDigits.js +1 -1
- package/components/overlays/src/OverlayMixin.js +4 -0
- package/components/progress-indicator/src/LionProgressIndicator.js +4 -0
- package/components/radio-group/src/LionRadioGroup.js +3 -1
- package/components/select/src/LionSelect.js +4 -0
- package/components/select-rich/src/LionSelectInvoker.js +2 -0
- package/components/select-rich/src/LionSelectRich.js +2 -0
- package/components/steps/src/LionStep.js +0 -1
- package/components/steps/src/LionSteps.js +0 -1
- package/components/switch/src/LionSwitch.js +3 -0
- package/components/switch/src/LionSwitchButton.js +5 -0
- package/components/tabs/src/LionTabs.js +8 -0
- package/custom-elements.json +5581 -1475
- package/dist-types/components/accordion/src/LionAccordion.d.ts +3 -2
- package/dist-types/components/accordion/src/LionAccordion.d.ts.map +1 -1
- package/dist-types/components/button/src/LionButton.d.ts +2 -1
- package/dist-types/components/button/src/LionButton.d.ts.map +1 -1
- package/dist-types/components/button/src/LionButtonReset.d.ts +2 -0
- package/dist-types/components/button/src/LionButtonReset.d.ts.map +1 -1
- package/dist-types/components/button/src/LionButtonSubmit.d.ts +2 -0
- package/dist-types/components/button/src/LionButtonSubmit.d.ts.map +1 -1
- package/dist-types/components/button/test-suites/LionButton.suite.d.ts.map +1 -1
- package/dist-types/components/checkbox-group/src/LionCheckbox.d.ts +3 -0
- package/dist-types/components/checkbox-group/src/LionCheckbox.d.ts.map +1 -1
- package/dist-types/components/checkbox-group/src/LionCheckboxGroup.d.ts +2 -0
- package/dist-types/components/checkbox-group/src/LionCheckboxGroup.d.ts.map +1 -1
- package/dist-types/components/checkbox-group/src/LionCheckboxIndeterminate.d.ts +3 -0
- package/dist-types/components/checkbox-group/src/LionCheckboxIndeterminate.d.ts.map +1 -1
- package/dist-types/components/collapsible/src/LionCollapsible.d.ts +3 -1
- package/dist-types/components/collapsible/src/LionCollapsible.d.ts.map +1 -1
- package/dist-types/components/combobox/src/LionCombobox.d.ts +5 -0
- package/dist-types/components/combobox/src/LionCombobox.d.ts.map +1 -1
- package/dist-types/components/dialog/src/LionDialog.d.ts +3 -0
- package/dist-types/components/dialog/src/LionDialog.d.ts.map +1 -1
- package/dist-types/components/drawer/src/LionDrawer.d.ts +9 -0
- package/dist-types/components/drawer/src/LionDrawer.d.ts.map +1 -1
- package/dist-types/components/fieldset/src/LionFieldset.d.ts +1 -1
- package/dist-types/components/form/src/LionForm.d.ts.map +1 -1
- package/dist-types/components/form-core/src/FormControlMixin.d.ts.map +1 -1
- package/dist-types/components/form-core/src/validate/LionValidationFeedback.d.ts +4 -3
- package/dist-types/components/form-core/src/validate/LionValidationFeedback.d.ts.map +1 -1
- package/dist-types/components/form-core/src/validate/ValidateMixin.d.ts.map +1 -1
- package/dist-types/components/form-core/test-suites/ValidateMixinFeedbackPart.suite.d.ts.map +1 -1
- package/dist-types/components/form-core/types/validate/validate.d.ts +1 -0
- package/dist-types/components/form-core/types/validate/validate.d.ts.map +1 -1
- package/dist-types/components/icon/src/LionIcon.d.ts +2 -0
- package/dist-types/components/icon/src/LionIcon.d.ts.map +1 -1
- 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-file/src/LionInputFile.d.ts +9 -0
- package/dist-types/components/input-file/src/LionInputFile.d.ts.map +1 -1
- package/dist-types/components/input-tel/src/LionInputTel.d.ts +3 -0
- package/dist-types/components/input-tel/src/LionInputTel.d.ts.map +1 -1
- 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/input-tel-dropdown/src/LionInputTelDropdown.d.ts +2 -0
- package/dist-types/components/input-tel-dropdown/src/LionInputTelDropdown.d.ts.map +1 -1
- package/dist-types/components/listbox/src/LionListbox.d.ts +2 -0
- package/dist-types/components/listbox/src/LionListbox.d.ts.map +1 -1
- package/dist-types/components/localize/src/number/getFractionDigits.d.ts +1 -1
- package/dist-types/components/overlays/src/OverlayMixin.d.ts +4 -0
- package/dist-types/components/overlays/src/OverlayMixin.d.ts.map +1 -1
- package/dist-types/components/progress-indicator/src/LionProgressIndicator.d.ts +3 -0
- package/dist-types/components/progress-indicator/src/LionProgressIndicator.d.ts.map +1 -1
- package/dist-types/components/radio-group/src/LionRadioGroup.d.ts +3 -1
- package/dist-types/components/radio-group/src/LionRadioGroup.d.ts.map +1 -1
- package/dist-types/components/select/src/LionSelect.d.ts +3 -0
- package/dist-types/components/select/src/LionSelect.d.ts.map +1 -1
- package/dist-types/components/select-rich/src/LionSelectInvoker.d.ts +2 -0
- package/dist-types/components/select-rich/src/LionSelectInvoker.d.ts.map +1 -1
- package/dist-types/components/select-rich/src/LionSelectRich.d.ts +3 -1
- package/dist-types/components/select-rich/src/LionSelectRich.d.ts.map +1 -1
- package/dist-types/components/steps/src/LionStep.d.ts +0 -1
- package/dist-types/components/steps/src/LionStep.d.ts.map +1 -1
- package/dist-types/components/steps/src/LionSteps.d.ts +0 -1
- package/dist-types/components/steps/src/LionSteps.d.ts.map +1 -1
- package/dist-types/components/switch/src/LionSwitch.d.ts +3 -0
- package/dist-types/components/switch/src/LionSwitch.d.ts.map +1 -1
- package/dist-types/components/switch/src/LionSwitchButton.d.ts +5 -0
- package/dist-types/components/switch/src/LionSwitchButton.d.ts.map +1 -1
- package/dist-types/components/tabs/src/LionTabs.d.ts +8 -0
- package/dist-types/components/tabs/src/LionTabs.d.ts.map +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/tsconfig.tsbuildinfo +1 -1
- package/docs/components/accordion/api-table.md +8 -0
- package/docs/components/button/api-table.md +0 -3
- package/docs/components/checkbox-group/overview.md +2 -2
- package/docs/components/collapsible/api-table.md +7 -0
- package/docs/components/collapsible/overview.md +1 -1
- package/docs/components/combobox/api-table.md +7 -0
- 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/drawer/api-table.md +8 -0
- 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/api-table.md +7 -0
- 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/api-table.md +0 -1
- package/docs/components/select-rich/use-cases.md +1 -1
- package/docs/components/tabs/api-table.md +7 -0
- 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 +19 -3
- 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/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,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This country to currency list was exported from Java.
|
|
3
|
+
* Java contains a country:currency map according to the i18n spec, but JS does not.
|
|
4
|
+
*
|
|
5
|
+
* @type {import("../types/index.js").countryToCurrencyList}
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // The following Java code can be used to export the countryToCurrencyList
|
|
9
|
+
*
|
|
10
|
+
* import java.util.Currency;
|
|
11
|
+
* import java.util.Locale;
|
|
12
|
+
*
|
|
13
|
+
* public class Main {
|
|
14
|
+
* public static void main(String[] args) {
|
|
15
|
+
* // get all ISO countries
|
|
16
|
+
* String[] ISOCountryCodes = Locale.getISOCountries();
|
|
17
|
+
*
|
|
18
|
+
* // loop over all the countries.
|
|
19
|
+
* for (String country : ISOCountryCodes) {
|
|
20
|
+
* try {
|
|
21
|
+
* // get the locale for said country
|
|
22
|
+
* Locale locale = new Locale("", country);
|
|
23
|
+
*
|
|
24
|
+
* // creates a Currency instance which has a bunch of standardized information.
|
|
25
|
+
* // from that class we can get the currency linked to the country.
|
|
26
|
+
* String currencyCode = Currency.getInstance(locale).getCurrencyCode();
|
|
27
|
+
*
|
|
28
|
+
* // prints to the console, which can be copied to update the map if changes occurred
|
|
29
|
+
* String output = country + ": '" + currencyCode + "',\n";
|
|
30
|
+
* System.out.print(output);
|
|
31
|
+
* } catch (Exception e) {
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
const countryToCurrencyList = {
|
|
38
|
+
AD: 'EUR',
|
|
39
|
+
AE: 'AED',
|
|
40
|
+
AF: 'AFN',
|
|
41
|
+
AG: 'XCD',
|
|
42
|
+
AI: 'XCD',
|
|
43
|
+
AL: 'ALL',
|
|
44
|
+
AM: 'AMD',
|
|
45
|
+
AO: 'AOA',
|
|
46
|
+
AR: 'ARS',
|
|
47
|
+
AS: 'USD',
|
|
48
|
+
AT: 'EUR',
|
|
49
|
+
AU: 'AUD',
|
|
50
|
+
AW: 'AWG',
|
|
51
|
+
AX: 'EUR',
|
|
52
|
+
AZ: 'AZN',
|
|
53
|
+
BA: 'BAM',
|
|
54
|
+
BB: 'BBD',
|
|
55
|
+
BD: 'BDT',
|
|
56
|
+
BE: 'EUR',
|
|
57
|
+
BF: 'XOF',
|
|
58
|
+
BG: 'BGN',
|
|
59
|
+
BH: 'BHD',
|
|
60
|
+
BI: 'BIF',
|
|
61
|
+
BJ: 'XOF',
|
|
62
|
+
BL: 'EUR',
|
|
63
|
+
BM: 'BMD',
|
|
64
|
+
BN: 'BND',
|
|
65
|
+
BO: 'BOB',
|
|
66
|
+
BQ: 'USD',
|
|
67
|
+
BR: 'BRL',
|
|
68
|
+
BS: 'BSD',
|
|
69
|
+
BT: 'BTN',
|
|
70
|
+
BV: 'NOK',
|
|
71
|
+
BW: 'BWP',
|
|
72
|
+
BY: 'BYN',
|
|
73
|
+
BZ: 'BZD',
|
|
74
|
+
CA: 'CAD',
|
|
75
|
+
CC: 'AUD',
|
|
76
|
+
CD: 'CDF',
|
|
77
|
+
CF: 'XAF',
|
|
78
|
+
CG: 'XAF',
|
|
79
|
+
CH: 'CHF',
|
|
80
|
+
CI: 'XOF',
|
|
81
|
+
CK: 'NZD',
|
|
82
|
+
CL: 'CLP',
|
|
83
|
+
CM: 'XAF',
|
|
84
|
+
CN: 'CNY',
|
|
85
|
+
CO: 'COP',
|
|
86
|
+
CR: 'CRC',
|
|
87
|
+
CU: 'CUP',
|
|
88
|
+
CV: 'CVE',
|
|
89
|
+
CW: 'XCG',
|
|
90
|
+
CX: 'AUD',
|
|
91
|
+
CY: 'EUR',
|
|
92
|
+
CZ: 'CZK',
|
|
93
|
+
DE: 'EUR',
|
|
94
|
+
DJ: 'DJF',
|
|
95
|
+
DK: 'DKK',
|
|
96
|
+
DM: 'XCD',
|
|
97
|
+
DO: 'DOP',
|
|
98
|
+
DZ: 'DZD',
|
|
99
|
+
EC: 'USD',
|
|
100
|
+
EE: 'EUR',
|
|
101
|
+
EG: 'EGP',
|
|
102
|
+
EH: 'MAD',
|
|
103
|
+
ER: 'ERN',
|
|
104
|
+
ES: 'EUR',
|
|
105
|
+
ET: 'ETB',
|
|
106
|
+
FI: 'EUR',
|
|
107
|
+
FJ: 'FJD',
|
|
108
|
+
FK: 'FKP',
|
|
109
|
+
FM: 'USD',
|
|
110
|
+
FO: 'DKK',
|
|
111
|
+
FR: 'EUR',
|
|
112
|
+
GA: 'XAF',
|
|
113
|
+
GB: 'GBP',
|
|
114
|
+
GD: 'XCD',
|
|
115
|
+
GE: 'GEL',
|
|
116
|
+
GF: 'EUR',
|
|
117
|
+
GG: 'GBP',
|
|
118
|
+
GH: 'GHS',
|
|
119
|
+
GI: 'GIP',
|
|
120
|
+
GL: 'DKK',
|
|
121
|
+
GM: 'GMD',
|
|
122
|
+
GN: 'GNF',
|
|
123
|
+
GP: 'EUR',
|
|
124
|
+
GQ: 'XAF',
|
|
125
|
+
GR: 'EUR',
|
|
126
|
+
GS: 'GBP',
|
|
127
|
+
GT: 'GTQ',
|
|
128
|
+
GU: 'USD',
|
|
129
|
+
GW: 'XOF',
|
|
130
|
+
GY: 'GYD',
|
|
131
|
+
HK: 'HKD',
|
|
132
|
+
HM: 'AUD',
|
|
133
|
+
HN: 'HNL',
|
|
134
|
+
HR: 'EUR',
|
|
135
|
+
HT: 'HTG',
|
|
136
|
+
HU: 'HUF',
|
|
137
|
+
ID: 'IDR',
|
|
138
|
+
IE: 'EUR',
|
|
139
|
+
IL: 'ILS',
|
|
140
|
+
IM: 'GBP',
|
|
141
|
+
IN: 'INR',
|
|
142
|
+
IO: 'USD',
|
|
143
|
+
IQ: 'IQD',
|
|
144
|
+
IR: 'IRR',
|
|
145
|
+
IS: 'ISK',
|
|
146
|
+
IT: 'EUR',
|
|
147
|
+
JE: 'GBP',
|
|
148
|
+
JM: 'JMD',
|
|
149
|
+
JO: 'JOD',
|
|
150
|
+
JP: 'JPY',
|
|
151
|
+
KE: 'KES',
|
|
152
|
+
KG: 'KGS',
|
|
153
|
+
KH: 'KHR',
|
|
154
|
+
KI: 'AUD',
|
|
155
|
+
KM: 'KMF',
|
|
156
|
+
KN: 'XCD',
|
|
157
|
+
KP: 'KPW',
|
|
158
|
+
KR: 'KRW',
|
|
159
|
+
KW: 'KWD',
|
|
160
|
+
KY: 'KYD',
|
|
161
|
+
KZ: 'KZT',
|
|
162
|
+
LA: 'LAK',
|
|
163
|
+
LB: 'LBP',
|
|
164
|
+
LC: 'XCD',
|
|
165
|
+
LI: 'CHF',
|
|
166
|
+
LK: 'LKR',
|
|
167
|
+
LR: 'LRD',
|
|
168
|
+
LS: 'LSL',
|
|
169
|
+
LT: 'EUR',
|
|
170
|
+
LU: 'EUR',
|
|
171
|
+
LV: 'EUR',
|
|
172
|
+
LY: 'LYD',
|
|
173
|
+
MA: 'MAD',
|
|
174
|
+
MC: 'EUR',
|
|
175
|
+
MD: 'MDL',
|
|
176
|
+
ME: 'EUR',
|
|
177
|
+
MF: 'EUR',
|
|
178
|
+
MG: 'MGA',
|
|
179
|
+
MH: 'USD',
|
|
180
|
+
MK: 'MKD',
|
|
181
|
+
ML: 'XOF',
|
|
182
|
+
MM: 'MMK',
|
|
183
|
+
MN: 'MNT',
|
|
184
|
+
MO: 'MOP',
|
|
185
|
+
MP: 'USD',
|
|
186
|
+
MQ: 'EUR',
|
|
187
|
+
MR: 'MRU',
|
|
188
|
+
MS: 'XCD',
|
|
189
|
+
MT: 'EUR',
|
|
190
|
+
MU: 'MUR',
|
|
191
|
+
MV: 'MVR',
|
|
192
|
+
MW: 'MWK',
|
|
193
|
+
MX: 'MXN',
|
|
194
|
+
MY: 'MYR',
|
|
195
|
+
MZ: 'MZN',
|
|
196
|
+
NA: 'NAD',
|
|
197
|
+
NC: 'XPF',
|
|
198
|
+
NE: 'XOF',
|
|
199
|
+
NF: 'AUD',
|
|
200
|
+
NG: 'NGN',
|
|
201
|
+
NI: 'NIO',
|
|
202
|
+
NL: 'EUR',
|
|
203
|
+
NO: 'NOK',
|
|
204
|
+
NP: 'NPR',
|
|
205
|
+
NR: 'AUD',
|
|
206
|
+
NU: 'NZD',
|
|
207
|
+
NZ: 'NZD',
|
|
208
|
+
OM: 'OMR',
|
|
209
|
+
PA: 'PAB',
|
|
210
|
+
PE: 'PEN',
|
|
211
|
+
PF: 'XPF',
|
|
212
|
+
PG: 'PGK',
|
|
213
|
+
PH: 'PHP',
|
|
214
|
+
PK: 'PKR',
|
|
215
|
+
PL: 'PLN',
|
|
216
|
+
PM: 'EUR',
|
|
217
|
+
PN: 'NZD',
|
|
218
|
+
PR: 'USD',
|
|
219
|
+
PS: 'ILS',
|
|
220
|
+
PT: 'EUR',
|
|
221
|
+
PW: 'USD',
|
|
222
|
+
PY: 'PYG',
|
|
223
|
+
QA: 'QAR',
|
|
224
|
+
RE: 'EUR',
|
|
225
|
+
RO: 'RON',
|
|
226
|
+
RS: 'RSD',
|
|
227
|
+
RU: 'RUB',
|
|
228
|
+
RW: 'RWF',
|
|
229
|
+
SA: 'SAR',
|
|
230
|
+
SB: 'SBD',
|
|
231
|
+
SC: 'SCR',
|
|
232
|
+
SD: 'SDG',
|
|
233
|
+
SE: 'SEK',
|
|
234
|
+
SG: 'SGD',
|
|
235
|
+
SH: 'SHP',
|
|
236
|
+
SI: 'EUR',
|
|
237
|
+
SJ: 'NOK',
|
|
238
|
+
SK: 'EUR',
|
|
239
|
+
SL: 'SLE',
|
|
240
|
+
SM: 'EUR',
|
|
241
|
+
SN: 'XOF',
|
|
242
|
+
SO: 'SOS',
|
|
243
|
+
SR: 'SRD',
|
|
244
|
+
SS: 'SSP',
|
|
245
|
+
ST: 'STN',
|
|
246
|
+
SV: 'SVC',
|
|
247
|
+
SX: 'XCG',
|
|
248
|
+
SY: 'SYP',
|
|
249
|
+
SZ: 'SZL',
|
|
250
|
+
TC: 'USD',
|
|
251
|
+
TD: 'XAF',
|
|
252
|
+
TF: 'EUR',
|
|
253
|
+
TG: 'XOF',
|
|
254
|
+
TH: 'THB',
|
|
255
|
+
TJ: 'TJS',
|
|
256
|
+
TK: 'NZD',
|
|
257
|
+
TL: 'USD',
|
|
258
|
+
TM: 'TMT',
|
|
259
|
+
TN: 'TND',
|
|
260
|
+
TO: 'TOP',
|
|
261
|
+
TR: 'TRY',
|
|
262
|
+
TT: 'TTD',
|
|
263
|
+
TV: 'AUD',
|
|
264
|
+
TW: 'TWD',
|
|
265
|
+
TZ: 'TZS',
|
|
266
|
+
UA: 'UAH',
|
|
267
|
+
UG: 'UGX',
|
|
268
|
+
UM: 'USD',
|
|
269
|
+
US: 'USD',
|
|
270
|
+
UY: 'UYU',
|
|
271
|
+
UZ: 'UZS',
|
|
272
|
+
VA: 'EUR',
|
|
273
|
+
VC: 'XCD',
|
|
274
|
+
VE: 'VES',
|
|
275
|
+
VG: 'USD',
|
|
276
|
+
VI: 'USD',
|
|
277
|
+
VN: 'VND',
|
|
278
|
+
VU: 'VUV',
|
|
279
|
+
WF: 'XPF',
|
|
280
|
+
WS: 'WST',
|
|
281
|
+
YE: 'YER',
|
|
282
|
+
YT: 'EUR',
|
|
283
|
+
ZA: 'ZAR',
|
|
284
|
+
ZM: 'ZMW',
|
|
285
|
+
ZW: 'ZWG',
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Map containing all countries and its corresponding currency, following the i18n standard.
|
|
290
|
+
* @type {import("../types/index.js").RegionToCurrencyMap}
|
|
291
|
+
*/
|
|
292
|
+
const countryToCurrencyMap = /** @type {import("../types/index.js").RegionToCurrencyMap} */ (
|
|
293
|
+
new Map(Object.entries(countryToCurrencyList))
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Set with all possible currencies derived from the i18n standard.
|
|
298
|
+
* @type {import("../types/index.js").AllCurrenciesSet}
|
|
299
|
+
*/
|
|
300
|
+
const allCurrencies = new Set(Object.values(countryToCurrencyList).sort());
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Matches a currency symbol to a currency code, with a given locale based on Intl.numberFormat.
|
|
304
|
+
* @param {import("./LionInputAmountDropdown.js").CurrencyCode} currency
|
|
305
|
+
* @param {string} locale
|
|
306
|
+
* @returns {string}
|
|
307
|
+
*/
|
|
308
|
+
const getCurrencySymbol = (currency, locale) => {
|
|
309
|
+
if (!locale || !currency) {
|
|
310
|
+
return '';
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
new Intl.NumberFormat(locale, { style: 'currency', currency })
|
|
315
|
+
.formatToParts(1)
|
|
316
|
+
.find(x => x.type === 'currency')?.value || ''
|
|
317
|
+
);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export const currencyUtil = {
|
|
321
|
+
countryToCurrencyMap,
|
|
322
|
+
allCurrencies,
|
|
323
|
+
getCurrencySymbol,
|
|
324
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { formatAmount as _formatAmount } from '@lion/ui/input-amount.js';
|
|
2
|
+
import { currencyUtil } from './currencyUtil.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../localize/types/LocalizeMixinTypes.js').FormatNumberOptions} FormatOptions
|
|
6
|
+
* @typedef {import('../types/index.js').AmountDropdownModelValue} AmountDropdownModelValue
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Formats a number considering the default fraction digits provided by Intl.
|
|
11
|
+
*
|
|
12
|
+
* @param {import('../types/index.js').AmountDropdownModelValue} modelValue to format
|
|
13
|
+
* @param {FormatOptions} [givenOptions]
|
|
14
|
+
* @param {AmountDropdownModelValue|undefined} [context]
|
|
15
|
+
*/
|
|
16
|
+
export const formatAmount = (modelValue, givenOptions, context) => {
|
|
17
|
+
// @ts-expect-error - cannot cast string to CurrencyCode outside a TS file
|
|
18
|
+
if (currencyUtil.allCurrencies.has(modelValue?.currency) && context) {
|
|
19
|
+
// TODO: better way of setting parent currency
|
|
20
|
+
context.currency = modelValue?.currency;
|
|
21
|
+
}
|
|
22
|
+
// @ts-expect-error - cannot cast string to CurrencyCode outside a TS file
|
|
23
|
+
return _formatAmount(modelValue?.amount, givenOptions);
|
|
24
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseAmount as _parseAmount } from '@lion/ui/input-amount.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Uses `parseAmount()` to parse a number string and return the best possible javascript number.
|
|
5
|
+
* Rounds up the number with the correct amount of decimals according to the currency.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* parseAmount('1,234.56', {currency: 'EUR'}); => { amount: 1234.56, currency: 'EUR' }
|
|
9
|
+
* parseAmount('1,234.56', {currency: 'JPY'}); => { amount: 1235, currency: 'JPY' }
|
|
10
|
+
* parseAmount('1,234.56', {currency: 'JOD'}); => { amount: 1234.560, currency: 'JOD' }
|
|
11
|
+
*
|
|
12
|
+
* @param {string} value Number to be parsed
|
|
13
|
+
* @param {import('../../localize/types/LocalizeMixinTypes.js').FormatNumberOptions} [givenOptions] Locale Options
|
|
14
|
+
* @returns {import('../types/index.js').AmountDropdownModelValue}
|
|
15
|
+
*/
|
|
16
|
+
export const parseAmount = (value, givenOptions) => {
|
|
17
|
+
const parsedAmount = _parseAmount(value, givenOptions);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
amount: parsedAmount,
|
|
21
|
+
currency: givenOptions?.currency,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes the modelValue to the international standard notation.
|
|
3
|
+
* @param {import("../types/index.js").AmountDropdownModelValue} modelValue
|
|
4
|
+
* @returns {string}
|
|
5
|
+
*/
|
|
6
|
+
export const serializer = modelValue =>
|
|
7
|
+
/**
|
|
8
|
+
* There seems to be some debate on a common international notation vs localization.
|
|
9
|
+
* The unwritten standard is, e.g: EUR 123
|
|
10
|
+
*/
|
|
11
|
+
`${modelValue?.currency} ${modelValue?.amount}`;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Deserializes the serializedValue back to modelValue.
|
|
15
|
+
* @param {string} serializedValue
|
|
16
|
+
* @returns {import("../types/index.js").AmountDropdownModelValue}
|
|
17
|
+
*/
|
|
18
|
+
export const deserializer = serializedValue => {
|
|
19
|
+
const [currency, amount] = serializedValue.split(' ');
|
|
20
|
+
return {
|
|
21
|
+
currency,
|
|
22
|
+
amount,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IsNumber, Validator } from '@lion/ui/form-core.js';
|
|
2
|
+
import { currencyUtil } from './currencyUtil.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../form-core/types/validate/validate.js').FeedbackMessageData} FeedbackMessageData
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class CurrencyAndAmount extends Validator {
|
|
9
|
+
static validatorName = 'CurrencyAndAmount';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {import('../types/index.js').AmountDropdownModelValue} modelValue amount and currency symbol
|
|
13
|
+
*/
|
|
14
|
+
// eslint-disable-next-line class-methods-use-this
|
|
15
|
+
execute(modelValue) {
|
|
16
|
+
// @ts-expect-error - cannot cast string to CurrencyCode outside a TS file
|
|
17
|
+
const validCurrencyCode = currencyUtil.allCurrencies.has(modelValue?.currency);
|
|
18
|
+
const isNumber = new IsNumber().execute(modelValue.amount);
|
|
19
|
+
|
|
20
|
+
return validCurrencyCode && isNumber;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { mimicUserChangingDropdown } from '@lion/ui/input-amount-dropdown-test-helpers.js';
|
|
2
|
+
import { runInputAmountDropdownSuite } from '@lion/ui/input-amount-dropdown-test-suites.js';
|
|
3
|
+
import { LionInputAmountDropdown } from '@lion/ui/input-amount-dropdown.js';
|
|
4
|
+
import { aTimeout, expect, fixture } from '@open-wc/testing';
|
|
5
|
+
import { LionSelectRich } from '@lion/ui/select-rich.js';
|
|
6
|
+
import { repeat } from 'lit/directives/repeat.js';
|
|
7
|
+
import { LionOption } from '@lion/ui/listbox.js';
|
|
8
|
+
import { ref } from 'lit/directives/ref.js';
|
|
9
|
+
import { html } from 'lit';
|
|
10
|
+
|
|
11
|
+
import { isActiveElement } from '../../core/test-helpers/isActiveElement.js';
|
|
12
|
+
import { ScopedElementsMixin } from '../../core/src/ScopedElementsMixin.js';
|
|
13
|
+
import '@lion/ui/define/lion-input-amount-dropdown.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {import('../types/index.js').TemplateDataForDropdownInputAmount} TemplateDataForDropdownInputAmount
|
|
17
|
+
* @typedef {HTMLSelectElement|HTMLElement & {modelValue:string}} DropdownElement
|
|
18
|
+
* @typedef {import('../types/index.js').RegionMeta} RegionMeta
|
|
19
|
+
* @typedef {import('lit').TemplateResult} TemplateResult
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
class WithFormControlInputAmountDropdown extends ScopedElementsMixin(LionInputAmountDropdown) {
|
|
23
|
+
/**
|
|
24
|
+
* @configure ScopedElementsMixin
|
|
25
|
+
*/
|
|
26
|
+
static scopedElements = {
|
|
27
|
+
...super.scopedElements,
|
|
28
|
+
'lion-select-rich': LionSelectRich,
|
|
29
|
+
'lion-option': LionOption,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
static templates = {
|
|
33
|
+
...(super.templates || {}),
|
|
34
|
+
/**
|
|
35
|
+
* @param {TemplateDataForDropdownInputAmount} templateDataForDropdown
|
|
36
|
+
*/
|
|
37
|
+
dropdown: templateDataForDropdown => {
|
|
38
|
+
const { refs, data } = templateDataForDropdown;
|
|
39
|
+
// TODO: once spread directive available, use it per ref (like ref(refs?.dropdown?.ref))
|
|
40
|
+
return html`
|
|
41
|
+
<lion-select-rich
|
|
42
|
+
${ref(refs?.dropdown?.ref)}
|
|
43
|
+
label="${refs?.dropdown?.labels?.country}"
|
|
44
|
+
label-sr-only
|
|
45
|
+
@model-value-changed="${refs?.dropdown?.listeners['model-value-changed']}"
|
|
46
|
+
style="${refs?.dropdown?.props?.style}"
|
|
47
|
+
>
|
|
48
|
+
${repeat(
|
|
49
|
+
data.regionMetaList,
|
|
50
|
+
regionMeta => regionMeta.currencyCode,
|
|
51
|
+
regionMeta => html`
|
|
52
|
+
<lion-option .choiceValue="${regionMeta.currencyCode}"> </lion-option>
|
|
53
|
+
`,
|
|
54
|
+
)}
|
|
55
|
+
</lion-select-rich>
|
|
56
|
+
`;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
runInputAmountDropdownSuite();
|
|
62
|
+
|
|
63
|
+
describe('WithFormControlInputAmountDropdown', () => {
|
|
64
|
+
// @ts-expect-error
|
|
65
|
+
// Runs it for LionSelectRich, which uses .modelValue/@model-value-changed instead of .value/@change
|
|
66
|
+
runInputAmountDropdownSuite({ klass: WithFormControlInputAmountDropdown });
|
|
67
|
+
|
|
68
|
+
it('focuses the textbox right after selection if selected via opened dropdown if interaction-mode is mac', async () => {
|
|
69
|
+
class InputAmountDropdownMac extends LionInputAmountDropdown {
|
|
70
|
+
static templates = {
|
|
71
|
+
...(super.templates || {}),
|
|
72
|
+
/**
|
|
73
|
+
* @param {TemplateDataForDropdownInputAmount} templateDataForDropdown
|
|
74
|
+
*/
|
|
75
|
+
dropdown: templateDataForDropdown => {
|
|
76
|
+
const { refs, data } = templateDataForDropdown;
|
|
77
|
+
// TODO: once spread directive available, use it per ref (like ref(refs?.dropdown?.ref))
|
|
78
|
+
return html`
|
|
79
|
+
<lion-select-rich
|
|
80
|
+
${ref(refs?.dropdown?.ref)}
|
|
81
|
+
label="${refs?.dropdown?.labels?.country}"
|
|
82
|
+
label-sr-only
|
|
83
|
+
@model-value-changed="${refs?.dropdown?.listeners['model-value-changed']}"
|
|
84
|
+
style="${refs?.dropdown?.props?.style}"
|
|
85
|
+
interaction-mode="mac"
|
|
86
|
+
>
|
|
87
|
+
${repeat(
|
|
88
|
+
data.regionMetaList,
|
|
89
|
+
regionMeta => regionMeta.currencyCode,
|
|
90
|
+
regionMeta => html`
|
|
91
|
+
<lion-option .choiceValue="${regionMeta.currencyCode}"> </lion-option>
|
|
92
|
+
`,
|
|
93
|
+
)}
|
|
94
|
+
</lion-select-rich>
|
|
95
|
+
`;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
customElements.define('input-amount-dropdown-mac', InputAmountDropdownMac);
|
|
100
|
+
const el = /** @type {LionInputAmountDropdown} */ (
|
|
101
|
+
await fixture(html`
|
|
102
|
+
<input-amount-dropdown-mac
|
|
103
|
+
.allowedCurrencies="${['GBP', 'EUR']}"
|
|
104
|
+
.modelValue="{ currency: 'GBP', amount: '123' }"
|
|
105
|
+
></input-amount-dropdown-mac>
|
|
106
|
+
`)
|
|
107
|
+
);
|
|
108
|
+
const dropdownElement = el.refs.dropdown.value;
|
|
109
|
+
// @ts-expect-error [allow-protected-in-tests]
|
|
110
|
+
if (dropdownElement?._overlayCtrl) {
|
|
111
|
+
// @ts-expect-error [allow-protected-in-tests]
|
|
112
|
+
dropdownElement._overlayCtrl.show();
|
|
113
|
+
mimicUserChangingDropdown(dropdownElement, 'EUR');
|
|
114
|
+
await el.updateComplete;
|
|
115
|
+
await aTimeout(0);
|
|
116
|
+
// @ts-expect-error [allow-protected-in-tests]
|
|
117
|
+
expect(isActiveElement(el._inputNode)).to.be.true;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('does not focus the textbox right after selection if selected via opened dropdown if interaction-mode is windows/linux', async () => {
|
|
122
|
+
class InputAmountDropdownWindows extends LionInputAmountDropdown {
|
|
123
|
+
static templates = {
|
|
124
|
+
...(super.templates || {}),
|
|
125
|
+
/**
|
|
126
|
+
* @param {TemplateDataForDropdownInputAmount} templateDataForDropdown
|
|
127
|
+
*/
|
|
128
|
+
dropdown: templateDataForDropdown => {
|
|
129
|
+
const { refs, data } = templateDataForDropdown;
|
|
130
|
+
// TODO: once spread directive available, use it per ref (like ref(refs?.dropdown?.ref))
|
|
131
|
+
return html`
|
|
132
|
+
<lion-select-rich
|
|
133
|
+
${ref(refs?.dropdown?.ref)}
|
|
134
|
+
label="${refs?.dropdown?.labels?.country}"
|
|
135
|
+
label-sr-only
|
|
136
|
+
@model-value-changed="${refs?.dropdown?.listeners['model-value-changed']}"
|
|
137
|
+
style="${refs?.dropdown?.props?.style}"
|
|
138
|
+
interaction-mode="windows/linux"
|
|
139
|
+
>
|
|
140
|
+
${repeat(
|
|
141
|
+
data.regionMetaList,
|
|
142
|
+
regionMeta => regionMeta.currencyCode,
|
|
143
|
+
regionMeta => html`
|
|
144
|
+
<lion-option .choiceValue="${regionMeta.currencyCode}"> </lion-option>
|
|
145
|
+
`,
|
|
146
|
+
)}
|
|
147
|
+
</lion-select-rich>
|
|
148
|
+
`;
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
customElements.define('input-amount-dropdown-windows', InputAmountDropdownWindows);
|
|
153
|
+
const el = /** @type {LionInputAmountDropdown} */ (
|
|
154
|
+
await fixture(html`
|
|
155
|
+
<input-amount-dropdown-windows
|
|
156
|
+
.allowedCurrencies="${['GBP', 'EUR']}"
|
|
157
|
+
.modelValue="{ currency: 'GBP', amount: '123' }"
|
|
158
|
+
></input-amount-dropdown-windows>
|
|
159
|
+
`)
|
|
160
|
+
);
|
|
161
|
+
const dropdownElement = el.refs.dropdown.value;
|
|
162
|
+
// @ts-expect-error [allow-protected-in-tests]
|
|
163
|
+
if (dropdownElement?._overlayCtrl) {
|
|
164
|
+
// @ts-expect-error [allow-protected-in-tests]
|
|
165
|
+
dropdownElement._overlayCtrl.show();
|
|
166
|
+
mimicUserChangingDropdown(dropdownElement, 'EUR');
|
|
167
|
+
await el.updateComplete;
|
|
168
|
+
await aTimeout(0);
|
|
169
|
+
// @ts-expect-error [allow-protected-in-tests]
|
|
170
|
+
expect(isActiveElement(el._inputNode)).to.be.false;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('defaultValidators', () => {
|
|
175
|
+
it('without interaction are not called', async () => {
|
|
176
|
+
const el = /** @type {LionInputAmountDropdown} */ (
|
|
177
|
+
await fixture(html`
|
|
178
|
+
<lion-input-amount-dropdown .allowedCurrencies="${['EUR']}"></lion-input-amount-dropdown>
|
|
179
|
+
`)
|
|
180
|
+
);
|
|
181
|
+
await aTimeout(0);
|
|
182
|
+
expect(el.hasFeedbackFor).to.deep.equal([]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('with interaction are called', async () => {
|
|
186
|
+
const el = /** @type {LionInputAmountDropdown} */ (
|
|
187
|
+
await fixture(html`
|
|
188
|
+
<lion-input-amount-dropdown
|
|
189
|
+
.allowedCurrencies="${['GBP', 'EUR']}"
|
|
190
|
+
></lion-input-amount-dropdown>
|
|
191
|
+
`)
|
|
192
|
+
);
|
|
193
|
+
el.modelValue = { currency: 'EUR' };
|
|
194
|
+
await aTimeout(0);
|
|
195
|
+
el.modelValue = { currency: 'EUR', amount: '' };
|
|
196
|
+
expect(el.hasFeedbackFor).to.deep.equal(['error']);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {HTMLSelectElement|HTMLElement & {modelValue:string}} DropdownElement
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {DropdownElement} dropdownEl
|
|
7
|
+
* @param {string} value
|
|
8
|
+
*/
|
|
9
|
+
export function mimicUserChangingDropdown(dropdownEl, value) {
|
|
10
|
+
if ('modelValue' in dropdownEl) {
|
|
11
|
+
// eslint-disable-next-line no-param-reassign
|
|
12
|
+
dropdownEl.modelValue = value;
|
|
13
|
+
dropdownEl.dispatchEvent(
|
|
14
|
+
new CustomEvent('model-value-changed', { detail: { isTriggeredByUser: true } }),
|
|
15
|
+
);
|
|
16
|
+
} else {
|
|
17
|
+
// eslint-disable-next-line no-param-reassign
|
|
18
|
+
dropdownEl.value = value;
|
|
19
|
+
dropdownEl.dispatchEvent(new Event('change'));
|
|
20
|
+
dropdownEl.dispatchEvent(new Event('input'));
|
|
21
|
+
}
|
|
22
|
+
}
|