@lion/ui 0.0.14 → 0.1.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/calendar/src/LionCalendar.js +2 -3
- package/components/calendar/test/lion-calendar.test.js +5 -3
- package/components/form-core/src/validate/ValidateMixin.js +7 -3
- package/components/form-core/src/validate/validators/DateValidators.js +1 -1
- package/components/form-core/test/lion-field.test.js +4 -2
- package/components/form-core/test/validate/DateValidators.test.js +1 -1
- package/components/form-core/test-suites/FormatMixin.suite.js +1 -1
- package/components/form-core/test-suites/ValidateMixinFeedbackPart.suite.js +6 -4
- package/components/form-integrations/test/form-validation-integrations.test.js +11 -10
- package/components/input-amount/src/LionInputAmount.js +2 -2
- package/components/input-amount/src/formatters.js +5 -1
- package/components/input-amount/src/parsers.js +1 -1
- package/components/input-amount/test/formatters.test.js +5 -3
- package/components/input-date/src/LionInputDate.js +1 -1
- package/components/input-date/test/lion-input-date.test.js +91 -43
- package/components/input-datepicker/src/LionInputDatepicker.js +1 -1
- package/components/input-email/src/LionInputEmail.js +1 -1
- package/components/input-iban/src/LionInputIban.js +1 -1
- package/components/input-iban/src/validators.js +14 -8
- package/components/input-range/src/LionInputRange.js +1 -1
- package/components/input-tel/src/LionInputTel.js +3 -3
- package/components/input-tel/test-suites/LionInputTel.suite.js +3 -2
- package/components/input-tel-dropdown/src/LionInputTelDropdown.js +7 -4
- package/components/localize/src/LocalizeMixin.js +24 -9
- package/components/localize/src/date/formatDate.js +4 -3
- package/components/localize/src/date/parseDate.js +5 -3
- package/components/localize/src/getLocalizeManager.js +74 -0
- package/components/localize/src/number/formatNumber.js +5 -4
- package/components/localize/src/number/getCurrencyName.js +3 -2
- package/components/localize/src/number/parseNumber.js +3 -2
- package/components/localize/src/number/utils/emptyStringWhenNumberNan.js +3 -2
- package/components/localize/src/singleton.js +6 -9
- package/components/localize/src/utils/getLocale.js +3 -8
- package/components/localize/test/LocalizeManager.test.js +1 -1
- package/components/localize/test/LocalizeMixin.test.js +17 -15
- package/components/localize/test/date/formatDate.test.js +25 -24
- package/components/localize/test/date/getDateFormatBasedOnLocale.test.js +8 -3
- package/components/localize/test/date/parseDate.test.js +22 -7
- package/components/localize/test/getLocalizeManager.test.js +31 -0
- package/components/localize/test/localize.test.js +5 -4
- package/components/localize/test/number/formatNumber.test.js +31 -29
- package/components/localize/test/number/formatNumberToParts.test.js +5 -3
- package/components/localize/test/number/getCurrencyName.test.js +1 -1
- package/components/localize/test/number/parseNumber.test.js +37 -19
- package/components/localize/test/side-effect-free-entrypoint.test.js +38 -0
- package/components/localize/test-helpers/localizeTearDown.js +5 -4
- package/components/localize/types/LocalizeMixinTypes.ts +9 -1
- package/components/pagination/src/LionPagination.js +1 -1
- package/components/progress-indicator/src/LionProgressIndicator.js +3 -2
- package/components/select/src/LionSelect.js +15 -0
- package/components/select/test/lion-select.test.js +25 -0
- package/components/validate-messages/src/loadDefaultFeedbackMessages.js +2 -2
- package/components/validate-messages/test/loadDefaultFeedbackMessagesNoSideEffects.js +6 -4
- package/custom-elements.json +395 -17
- package/dist-types/components/calendar/src/LionCalendar.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/input-amount/src/formatters.d.ts.map +1 -1
- package/dist-types/components/input-date/src/LionInputDate.d.ts +1 -1
- package/dist-types/components/input-iban/src/validators.d.ts.map +1 -1
- package/dist-types/components/input-tel/test-suites/LionInputTel.suite.d.ts.map +1 -1
- package/dist-types/components/input-tel-dropdown/src/LionInputTelDropdown.d.ts.map +1 -1
- package/dist-types/components/localize/src/LocalizeMixin.d.ts.map +1 -1
- package/dist-types/components/localize/src/date/formatDate.d.ts.map +1 -1
- package/dist-types/components/localize/src/date/parseDate.d.ts.map +1 -1
- package/dist-types/components/localize/src/getLocalizeManager.d.ts +60 -0
- package/dist-types/components/localize/src/getLocalizeManager.d.ts.map +1 -0
- package/dist-types/components/localize/src/number/formatNumber.d.ts.map +1 -1
- package/dist-types/components/localize/src/number/getCurrencyName.d.ts.map +1 -1
- package/dist-types/components/localize/src/number/parseNumber.d.ts.map +1 -1
- package/dist-types/components/localize/src/number/utils/emptyStringWhenNumberNan.d.ts.map +1 -1
- package/dist-types/components/localize/src/singleton.d.ts +5 -3
- package/dist-types/components/localize/src/singleton.d.ts.map +1 -1
- package/dist-types/components/localize/src/utils/getLocale.d.ts.map +1 -1
- package/dist-types/components/localize/test/getLocalizeManager.test.d.ts +2 -0
- package/dist-types/components/localize/test/getLocalizeManager.test.d.ts.map +1 -0
- package/dist-types/components/localize/test/side-effect-free-entrypoint.test.d.ts +2 -0
- package/dist-types/components/localize/test/side-effect-free-entrypoint.test.d.ts.map +1 -0
- package/dist-types/components/localize/test-helpers/localizeTearDown.d.ts.map +1 -1
- package/dist-types/components/localize/types/LocalizeMixinTypes.d.ts +4 -1
- package/dist-types/components/localize/types/LocalizeMixinTypes.d.ts.map +1 -1
- package/dist-types/components/progress-indicator/src/LionProgressIndicator.d.ts.map +1 -1
- package/dist-types/components/select/src/LionSelect.d.ts +1 -0
- package/dist-types/components/select/src/LionSelect.d.ts.map +1 -1
- package/dist-types/exports/localize-no-side-effects.d.ts +18 -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/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-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-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/radio-group/overview.md +3 -3
- 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/providence-analytics/LocalConfiguration.md +1 -1
- package/docs/fundamentals/node-tools/providence-analytics/QueryResult.md +1 -1
- package/docs/fundamentals/node-tools/providence-analytics/analyzer.md +1 -1
- package/docs/fundamentals/node-tools/providence-analytics/dashboard.md +1 -1
- package/docs/fundamentals/node-tools/providence-analytics/overview.md +3 -3
- 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/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 +1 -1
- 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/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/localize-no-side-effects.js +19 -0
- package/package.json +1 -1
|
@@ -3,10 +3,9 @@ import { html, LitElement } from 'lit';
|
|
|
3
3
|
import {
|
|
4
4
|
getMonthNames,
|
|
5
5
|
getWeekdayNames,
|
|
6
|
-
localize,
|
|
7
6
|
LocalizeMixin,
|
|
8
7
|
normalizeDateTime,
|
|
9
|
-
} from '@lion/ui/localize.js';
|
|
8
|
+
} from '@lion/ui/localize-no-side-effects.js';
|
|
10
9
|
|
|
11
10
|
import { calendarStyle } from './calendarStyle.js';
|
|
12
11
|
import { createDay } from './utils/createDay.js';
|
|
@@ -862,6 +861,6 @@ export class LionCalendar extends LocalizeMixin(LitElement) {
|
|
|
862
861
|
* @private
|
|
863
862
|
*/
|
|
864
863
|
__getLocale() {
|
|
865
|
-
return this.locale ||
|
|
864
|
+
return this.locale || this._localizeManager.locale;
|
|
866
865
|
}
|
|
867
866
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { html } from 'lit';
|
|
2
|
-
import {
|
|
2
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
3
3
|
import { localizeTearDown } from '@lion/ui/localize-test-helpers.js';
|
|
4
4
|
import { expect, fixture as _fixture } from '@open-wc/testing';
|
|
5
5
|
import sinon from 'sinon';
|
|
@@ -15,6 +15,8 @@ import { CalendarObject, DayObject } from '@lion/ui/calendar-test-helpers.js';
|
|
|
15
15
|
const fixture = /** @type {(arg: TemplateResult) => Promise<LionCalendar>} */ (_fixture);
|
|
16
16
|
|
|
17
17
|
describe('<lion-calendar>', () => {
|
|
18
|
+
const localizeManager = getLocalizeManager();
|
|
19
|
+
|
|
18
20
|
beforeEach(() => {
|
|
19
21
|
localizeTearDown();
|
|
20
22
|
});
|
|
@@ -1348,7 +1350,7 @@ describe('<lion-calendar>', () => {
|
|
|
1348
1350
|
await el.updateComplete;
|
|
1349
1351
|
expect(elObj.activeMonth).to.equal('décembre');
|
|
1350
1352
|
|
|
1351
|
-
|
|
1353
|
+
localizeManager.locale = 'cs-CZ';
|
|
1352
1354
|
await el.updateComplete;
|
|
1353
1355
|
expect(elObj.activeMonth).to.equal('décembre');
|
|
1354
1356
|
|
|
@@ -1391,7 +1393,7 @@ describe('<lion-calendar>', () => {
|
|
|
1391
1393
|
'Sat',
|
|
1392
1394
|
]);
|
|
1393
1395
|
|
|
1394
|
-
|
|
1396
|
+
localizeManager.locale = 'nl-NL';
|
|
1395
1397
|
await el.localizeNamespacesLoaded;
|
|
1396
1398
|
await el.updateComplete;
|
|
1397
1399
|
expect(elObj.nextMonthButtonEl?.getAttribute('aria-label')).to.equal(
|
|
@@ -3,7 +3,7 @@ import { SlotMixin, DisabledMixin } from '@lion/ui/core.js';
|
|
|
3
3
|
import { ScopedElementsMixin } from '@open-wc/scoped-elements';
|
|
4
4
|
import { dedupeMixin } from '@open-wc/dedupe-mixin';
|
|
5
5
|
// TODO: make form-core independent from localize
|
|
6
|
-
import {
|
|
6
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
7
7
|
import { AsyncQueue } from '../utils/AsyncQueue.js';
|
|
8
8
|
import { pascalCase } from '../utils/pascalCase.js';
|
|
9
9
|
import { SyncUpdatableMixin } from '../utils/SyncUpdatableMixin.js';
|
|
@@ -262,12 +262,16 @@ export const ValidateMixinImplementation = superclass =>
|
|
|
262
262
|
|
|
263
263
|
connectedCallback() {
|
|
264
264
|
super.connectedCallback();
|
|
265
|
-
|
|
265
|
+
|
|
266
|
+
const localizeManager = getLocalizeManager();
|
|
267
|
+
localizeManager.addEventListener('localeChanged', this._updateFeedbackComponent);
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
disconnectedCallback() {
|
|
269
271
|
super.disconnectedCallback();
|
|
270
|
-
|
|
272
|
+
|
|
273
|
+
const localizeManager = getLocalizeManager();
|
|
274
|
+
localizeManager.removeEventListener('localeChanged', this._updateFeedbackComponent);
|
|
271
275
|
}
|
|
272
276
|
|
|
273
277
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file */
|
|
2
2
|
// TODO: move to input-datepicker?
|
|
3
|
-
import { normalizeDateTime } from '@lion/ui/localize.js';
|
|
3
|
+
import { normalizeDateTime } from '@lion/ui/localize-no-side-effects.js';
|
|
4
4
|
import { Validator } from '../Validator.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -2,7 +2,7 @@ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
|
2
2
|
import { Required, Validator } from '@lion/ui/form-core.js';
|
|
3
3
|
import '@lion/ui/define/lion-field.js';
|
|
4
4
|
import { getFormControlMembers } from '@lion/ui/form-core-test-helpers.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
6
6
|
import { localizeTearDown } from '@lion/ui/localize-test-helpers.js';
|
|
7
7
|
import {
|
|
8
8
|
expect,
|
|
@@ -52,6 +52,8 @@ function getSlot(el, slot) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
describe('<lion-field>', () => {
|
|
55
|
+
const localizeManager = getLocalizeManager();
|
|
56
|
+
|
|
55
57
|
it(`puts a unique id "${tagString}-[hash]" on the native input`, async () => {
|
|
56
58
|
const el = /** @type {LionField} */ (await fixture(html`<${tag}>${inputSlot}</${tag}>`));
|
|
57
59
|
// @ts-ignore allow protected accessors in tests
|
|
@@ -219,7 +221,7 @@ describe('<lion-field>', () => {
|
|
|
219
221
|
beforeEach(() => {
|
|
220
222
|
// Reset and preload validation translations
|
|
221
223
|
localizeTearDown();
|
|
222
|
-
|
|
224
|
+
localizeManager.addData('en-GB', 'lion-validate', {
|
|
223
225
|
error: {
|
|
224
226
|
hasX: 'This is error message for hasX',
|
|
225
227
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from '@open-wc/testing';
|
|
2
2
|
|
|
3
|
-
import { normalizeDateTime } from '@lion/ui/localize.js';
|
|
3
|
+
import { normalizeDateTime } from '@lion/ui/localize-no-side-effects.js';
|
|
4
4
|
import { IsDate, MinDate, MaxDate, MinMaxDate, IsDateDisabled } from '@lion/ui/form-core.js';
|
|
5
5
|
|
|
6
6
|
describe('Date Validation', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import { parseDate } from '@lion/ui/localize.js';
|
|
2
|
+
import { parseDate } from '@lion/ui/localize-no-side-effects.js';
|
|
3
3
|
import { aTimeout, defineCE, expect, fixture, html, unsafeStatic } from '@open-wc/testing';
|
|
4
4
|
import sinon from 'sinon';
|
|
5
5
|
import { Unparseable, Validator, FormatMixin } from '@lion/ui/form-core.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import {
|
|
2
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
3
3
|
import { localizeTearDown } from '@lion/ui/localize-test-helpers.js';
|
|
4
4
|
import { defineCE, expect, fixture, html, unsafeStatic } from '@open-wc/testing';
|
|
5
5
|
import { getFormControlMembers, AlwaysInvalid } from '@lion/ui/form-core-test-helpers.js';
|
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
export function runValidateMixinFeedbackPart() {
|
|
21
|
+
const localizeManager = getLocalizeManager();
|
|
22
|
+
|
|
21
23
|
describe('Validity Feedback', () => {
|
|
22
24
|
beforeEach(() => {
|
|
23
25
|
localizeTearDown();
|
|
@@ -65,7 +67,7 @@ export function runValidateMixinFeedbackPart() {
|
|
|
65
67
|
|
|
66
68
|
AlwaysInvalid.getMessage = async () => 'Message for AlwaysInvalid';
|
|
67
69
|
MinLength.getMessage = async () =>
|
|
68
|
-
|
|
70
|
+
localizeManager.locale === 'de-DE' ? 'Nachricht für MinLength' : 'Message for MinLength';
|
|
69
71
|
ContainsLowercaseA.getMessage = async () => 'Message for ContainsLowercaseA';
|
|
70
72
|
ContainsCat.getMessage = async () => 'Message for ContainsCat';
|
|
71
73
|
|
|
@@ -341,8 +343,8 @@ export function runValidateMixinFeedbackPart() {
|
|
|
341
343
|
expect(_feedbackNode.feedbackData?.length).to.equal(1);
|
|
342
344
|
expect(_feedbackNode.feedbackData?.[0].message).to.equal('Message for MinLength');
|
|
343
345
|
|
|
344
|
-
|
|
345
|
-
await
|
|
346
|
+
localizeManager.locale = 'de-DE';
|
|
347
|
+
await localizeManager.loadingComplete;
|
|
346
348
|
await el.feedbackComplete;
|
|
347
349
|
expect(_feedbackNode.feedbackData?.[0].message).to.equal('Nachricht für MinLength');
|
|
348
350
|
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { DefaultSuccess, Required, Validator } from '@lion/ui/form-core.js';
|
|
2
2
|
import { getFormControlMembers } from '@lion/ui/form-core-test-helpers.js';
|
|
3
3
|
import { LionInput } from '@lion/ui/input.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
5
5
|
import { loadDefaultFeedbackMessages } from '@lion/ui/validate-messages.js';
|
|
6
6
|
import { defineCE, expect, fixture, html, unsafeStatic } from '@open-wc/testing';
|
|
7
7
|
import sinon from 'sinon';
|
|
8
8
|
|
|
9
9
|
describe('Form Validation Integrations', () => {
|
|
10
|
+
const localizeManager = getLocalizeManager();
|
|
10
11
|
const lightDom = '';
|
|
11
12
|
before(() => {
|
|
12
13
|
loadDefaultFeedbackMessages();
|
|
@@ -126,11 +127,11 @@ describe('Form Validation Integrations', () => {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
async updateLabel() {
|
|
129
|
-
this.label =
|
|
130
|
+
this.label = localizeManager.msg('test-default-label:label');
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
async setDefaultLabel() {
|
|
133
|
-
|
|
134
|
+
localizeManager.loadNamespace({
|
|
134
135
|
'test-default-label': /** @param {string} locale */ async locale => {
|
|
135
136
|
switch (locale) {
|
|
136
137
|
case 'nl-NL':
|
|
@@ -143,11 +144,11 @@ describe('Form Validation Integrations', () => {
|
|
|
143
144
|
this.boundUpdateLabel = this.updateLabel.bind(this);
|
|
144
145
|
|
|
145
146
|
// localeChanged is fired AFTER localize has finished loading missing translations
|
|
146
|
-
// so no need to await
|
|
147
|
-
|
|
147
|
+
// so no need to await localizeManager.loadingComplete
|
|
148
|
+
localizeManager.addEventListener('localeChanged', this.boundUpdateLabel);
|
|
148
149
|
|
|
149
150
|
// Wait for it to complete when updating the label for the first time
|
|
150
|
-
await
|
|
151
|
+
await localizeManager.loadingComplete;
|
|
151
152
|
this.boundUpdateLabel();
|
|
152
153
|
}
|
|
153
154
|
}
|
|
@@ -167,15 +168,15 @@ describe('Form Validation Integrations', () => {
|
|
|
167
168
|
const { _feedbackNode } = getFormControlMembers(el);
|
|
168
169
|
expect(_feedbackNode.feedbackData?.[0].message).to.equal('Please enter a(n) Text.');
|
|
169
170
|
|
|
170
|
-
|
|
171
|
-
await
|
|
171
|
+
localizeManager.locale = 'nl-NL';
|
|
172
|
+
await localizeManager.loadingComplete;
|
|
172
173
|
await el.updateComplete;
|
|
173
174
|
await el.feedbackComplete;
|
|
174
175
|
expect(el.label).to.equal('Tekst');
|
|
175
176
|
expect(_feedbackNode.feedbackData?.[0].message).to.equal('Vul een Tekst in.');
|
|
176
177
|
|
|
177
|
-
|
|
178
|
-
await
|
|
178
|
+
localizeManager.locale = 'en-GB';
|
|
179
|
+
await localizeManager.loadingComplete;
|
|
179
180
|
await el.updateComplete;
|
|
180
181
|
await el.feedbackComplete;
|
|
181
182
|
expect(el.label).to.equal('Text');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { css } from 'lit';
|
|
2
2
|
import { LionInput } from '@lion/ui/input.js';
|
|
3
|
-
import { getCurrencyName,
|
|
3
|
+
import { getCurrencyName, LocalizeMixin } from '@lion/ui/localize-no-side-effects.js';
|
|
4
4
|
import { IsNumber } from '@lion/ui/form-core.js';
|
|
5
5
|
import { formatAmount, formatCurrencyLabel } from './formatters.js';
|
|
6
6
|
import { parseAmount } from './parsers.js';
|
|
@@ -201,7 +201,7 @@ export class LionInputAmount extends LocalizeMixin(LionInput) {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
get __currencyLabel() {
|
|
204
|
-
return this.currency ? formatCurrencyLabel(this.currency,
|
|
204
|
+
return this.currency ? formatCurrencyLabel(this.currency, this._localizeManager.locale) : '';
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
__reformat() {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
formatNumber,
|
|
3
|
+
getFractionDigits,
|
|
4
|
+
normalizeCurrencyLabel,
|
|
5
|
+
} from '@lion/ui/localize-no-side-effects.js';
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* @typedef {import('../../localize/types/LocalizeMixinTypes.js').FormatNumberOptions} FormatOptions
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { expect } from '@open-wc/testing';
|
|
2
|
-
import {
|
|
2
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
3
3
|
import { localizeTearDown } from '@lion/ui/localize-test-helpers.js';
|
|
4
4
|
|
|
5
5
|
import { formatAmount } from '@lion/ui/input-amount.js';
|
|
6
6
|
|
|
7
7
|
describe('formatAmount()', () => {
|
|
8
|
+
const localizeManager = getLocalizeManager();
|
|
9
|
+
|
|
8
10
|
afterEach(() => {
|
|
9
11
|
localizeTearDown();
|
|
10
12
|
});
|
|
@@ -67,9 +69,9 @@ describe('formatAmount()', () => {
|
|
|
67
69
|
});
|
|
68
70
|
|
|
69
71
|
it('fallbacks to global locale and EUR by default', async () => {
|
|
70
|
-
|
|
72
|
+
localizeManager.locale = 'en-GB';
|
|
71
73
|
expect(formatAmount(12345678)).to.equal('12,345,678.00');
|
|
72
|
-
|
|
74
|
+
localizeManager.locale = 'nl-NL';
|
|
73
75
|
expect(formatAmount(12345678)).to.equal('12.345.678,00');
|
|
74
76
|
});
|
|
75
77
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IsDate } from '@lion/ui/form-core.js';
|
|
2
2
|
import { LionInput } from '@lion/ui/input.js';
|
|
3
|
-
import { formatDate, LocalizeMixin, parseDate } from '@lion/ui/localize.js';
|
|
3
|
+
import { formatDate, LocalizeMixin, parseDate } from '@lion/ui/localize-no-side-effects.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {Date|number} date
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { html } from 'lit';
|
|
2
|
-
import {
|
|
2
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
3
3
|
import { localizeTearDown } from '@lion/ui/localize-test-helpers.js';
|
|
4
|
-
import { MaxDate } from '@lion/ui/form-core.js';
|
|
4
|
+
import { MinDate, MaxDate } from '@lion/ui/form-core.js';
|
|
5
5
|
import { expect, fixture as _fixture } from '@open-wc/testing';
|
|
6
6
|
import { getInputMembers } from '@lion/ui/input-test-helpers.js';
|
|
7
7
|
import '@lion/ui/define/lion-input-date.js';
|
|
@@ -13,6 +13,8 @@ import '@lion/ui/define/lion-input-date.js';
|
|
|
13
13
|
const fixture = /** @type {(arg: TemplateResult) => Promise<LionInputDate>} */ (_fixture);
|
|
14
14
|
|
|
15
15
|
describe('<lion-input-date>', () => {
|
|
16
|
+
const localizeManager = getLocalizeManager();
|
|
17
|
+
|
|
16
18
|
beforeEach(() => {
|
|
17
19
|
localizeTearDown();
|
|
18
20
|
});
|
|
@@ -65,49 +67,95 @@ describe('<lion-input-date>', () => {
|
|
|
65
67
|
expect(el.validationStates.error).not.to.have.property('MaxDate');
|
|
66
68
|
});
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
70
|
+
describe('locale', () => {
|
|
71
|
+
it('uses formatOptions.locale', async () => {
|
|
72
|
+
const el = await fixture(html`
|
|
73
|
+
<lion-input-date
|
|
74
|
+
.formatOptions="${{ locale: 'en-GB' }}"
|
|
75
|
+
.modelValue=${new Date('2017/06/15')}
|
|
76
|
+
></lion-input-date>
|
|
77
|
+
`);
|
|
78
|
+
expect(el.formattedValue).to.equal('15/06/2017');
|
|
79
|
+
|
|
80
|
+
const el2 = await fixture(html`
|
|
81
|
+
<lion-input-date
|
|
82
|
+
.formatOptions="${{ locale: 'en-US' }}"
|
|
83
|
+
.modelValue=${new Date('2017/06/15')}
|
|
84
|
+
></lion-input-date>
|
|
85
|
+
`);
|
|
86
|
+
expect(el2.formattedValue).to.equal('06/15/2017');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('uses global locale when formatOptions.locale is not defined', async () => {
|
|
90
|
+
localizeManager.locale = 'fr-FR';
|
|
91
|
+
const el = await fixture(html`
|
|
92
|
+
<lion-input-date .modelValue=${new Date('2017/06/15')}></lion-input-date>
|
|
93
|
+
`);
|
|
94
|
+
expect(el.formattedValue).to.equal('15/06/2017');
|
|
95
|
+
|
|
96
|
+
localizeManager.locale = 'en-US';
|
|
97
|
+
const el2 = await fixture(html`
|
|
98
|
+
<lion-input-date .modelValue=${new Date('2017/06/15')}></lion-input-date>
|
|
99
|
+
`);
|
|
100
|
+
expect(el2.formattedValue).to.equal('06/15/2017');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('ignores global locale change if formatOptions.locale is provided', async () => {
|
|
104
|
+
const el = await fixture(html`
|
|
105
|
+
<lion-input-date
|
|
106
|
+
.modelValue=${new Date('2017/06/15')}
|
|
107
|
+
.formatOptions="${{ locale: 'en-GB' }}"
|
|
108
|
+
></lion-input-date>
|
|
109
|
+
`);
|
|
110
|
+
expect(el.formattedValue).to.equal('15/06/2017'); // british
|
|
111
|
+
localizeManager.locale = 'en-US';
|
|
112
|
+
await el.updateComplete;
|
|
113
|
+
expect(el.formattedValue).to.equal('15/06/2017'); // should stay british
|
|
114
|
+
});
|
|
98
115
|
});
|
|
99
116
|
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
describe('timezones', async () => {
|
|
118
|
+
const dateAmsterdam = new Date(
|
|
119
|
+
new Date('2017/06/15').toLocaleString('en-US', { timeZone: 'Europe/Amsterdam' }),
|
|
120
|
+
);
|
|
121
|
+
const dateManila = new Date(
|
|
122
|
+
new Date('2017/06/15').toLocaleString('en-US', { timeZone: 'Asia/Manila' }),
|
|
123
|
+
);
|
|
124
|
+
const dateNewYork = new Date(
|
|
125
|
+
new Date('2017/06/15').toLocaleString('en-US', { timeZone: 'America/New_York' }),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
it('works with different timezones', async () => {
|
|
129
|
+
const el = await fixture(html`
|
|
130
|
+
<lion-input-date .modelValue=${dateAmsterdam}></lion-input-date>
|
|
131
|
+
`);
|
|
132
|
+
expect(el.formattedValue).to.equal('15/06/2017', 'Europe/Amsterdam');
|
|
133
|
+
|
|
134
|
+
el.modelValue = dateManila;
|
|
135
|
+
expect(el.formattedValue).to.equal('15/06/2017', 'Asia/Manila');
|
|
136
|
+
|
|
137
|
+
el.modelValue = dateNewYork;
|
|
138
|
+
expect(el.formattedValue).to.equal('14/06/2017', 'America/New_York');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('validators work with different timezones', async () => {
|
|
142
|
+
const el = await fixture(html`
|
|
143
|
+
<lion-input-date
|
|
144
|
+
.modelValue=${new Date('2017/06/15')}
|
|
145
|
+
.validators=${[new MinDate(new Date('2017/06/14'))]}
|
|
146
|
+
></lion-input-date>
|
|
147
|
+
`);
|
|
148
|
+
expect(el.formattedValue).to.equal('15/06/2017', 'Europe/Amsterdam');
|
|
149
|
+
expect(el.hasFeedbackFor).not.to.include('error', 'Europe/Amsterdam');
|
|
150
|
+
|
|
151
|
+
el.modelValue = dateManila;
|
|
152
|
+
expect(el.formattedValue).to.equal('15/06/2017', 'Asia/Manila');
|
|
153
|
+
expect(el.hasFeedbackFor).not.to.include('error', 'Asia/Manila');
|
|
154
|
+
|
|
155
|
+
el.modelValue = dateNewYork;
|
|
156
|
+
expect(el.formattedValue).to.equal('14/06/2017', 'America/New_York');
|
|
157
|
+
expect(el.hasFeedbackFor).not.to.include('error', 'America/New_York');
|
|
158
|
+
});
|
|
111
159
|
});
|
|
112
160
|
|
|
113
161
|
it('is accessible', async () => {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
withModalDialogConfig,
|
|
11
11
|
ArrowMixin,
|
|
12
12
|
} from '@lion/ui/overlays.js';
|
|
13
|
-
import { LocalizeMixin } from '@lion/ui/localize.js';
|
|
13
|
+
import { LocalizeMixin } from '@lion/ui/localize-no-side-effects.js';
|
|
14
14
|
import { localizeNamespaceLoader } from './localizeNamespaceLoader.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IsEmail } from '@lion/ui/form-core.js';
|
|
2
2
|
import { LionInput } from '@lion/ui/input.js';
|
|
3
|
-
import { LocalizeMixin } from '@lion/ui/localize.js';
|
|
3
|
+
import { LocalizeMixin } from '@lion/ui/localize-no-side-effects.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* LionInputEmail: extension of lion-input
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file, import/no-extraneous-dependencies */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
4
4
|
import { Unparseable, Validator } from '@lion/ui/form-core.js';
|
|
5
5
|
import { isValidIBAN } from 'ibantools';
|
|
6
6
|
|
|
7
7
|
let loaded = false;
|
|
8
8
|
const loadTranslations = async () => {
|
|
9
|
+
const localizeManager = getLocalizeManager();
|
|
9
10
|
if (loaded) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
|
-
await
|
|
13
|
+
await localizeManager.loadNamespace(
|
|
13
14
|
{
|
|
14
15
|
'lion-validate+iban': /** @param {string} locale */ locale => {
|
|
15
16
|
switch (locale) {
|
|
@@ -86,7 +87,7 @@ const loadTranslations = async () => {
|
|
|
86
87
|
}
|
|
87
88
|
},
|
|
88
89
|
},
|
|
89
|
-
{ locale:
|
|
90
|
+
{ locale: localizeManager.locale },
|
|
90
91
|
);
|
|
91
92
|
loaded = true;
|
|
92
93
|
};
|
|
@@ -113,8 +114,9 @@ export class IsIBAN extends Validator {
|
|
|
113
114
|
* @returns {Promise<string|Element>}
|
|
114
115
|
*/
|
|
115
116
|
static async getMessage(data) {
|
|
117
|
+
const localizeManager = getLocalizeManager();
|
|
116
118
|
await loadTranslations();
|
|
117
|
-
return
|
|
119
|
+
return localizeManager.msg('lion-validate+iban:error.IsIBAN', data);
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
|
|
@@ -156,11 +158,13 @@ export class IsCountryIBAN extends IsIBAN {
|
|
|
156
158
|
* @returns {Promise<string|Element>}
|
|
157
159
|
*/
|
|
158
160
|
static async getMessage(data) {
|
|
161
|
+
const localizeManager = getLocalizeManager();
|
|
162
|
+
|
|
159
163
|
await loadTranslations();
|
|
160
164
|
// If modelValue is Unparseable, the IsIBAN message is the more appropriate feedback
|
|
161
165
|
return data?.modelValue instanceof Unparseable
|
|
162
|
-
?
|
|
163
|
-
:
|
|
166
|
+
? localizeManager.msg('lion-validate+iban:error.IsIBAN', data)
|
|
167
|
+
: localizeManager.msg('lion-validate+iban:error.IsCountryIBAN', data);
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
|
|
@@ -203,6 +207,8 @@ export class IsNotCountryIBAN extends IsIBAN {
|
|
|
203
207
|
* @returns {Promise<string|Element>}
|
|
204
208
|
*/
|
|
205
209
|
static async getMessage(data) {
|
|
210
|
+
const localizeManager = getLocalizeManager();
|
|
211
|
+
|
|
206
212
|
await loadTranslations();
|
|
207
213
|
const _data = {
|
|
208
214
|
...data,
|
|
@@ -211,7 +217,7 @@ export class IsNotCountryIBAN extends IsIBAN {
|
|
|
211
217
|
};
|
|
212
218
|
// If modelValue is Unparseable, the IsIBAN message is the more appropriate feedback
|
|
213
219
|
return data?.modelValue instanceof Unparseable
|
|
214
|
-
?
|
|
215
|
-
:
|
|
220
|
+
? localizeManager.msg('lion-validate+iban:error.IsIBAN', _data)
|
|
221
|
+
: localizeManager.msg('lion-validate+iban:error.IsNotCountryIBAN', _data);
|
|
216
222
|
}
|
|
217
223
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { ScopedStylesController } from '@lion/ui/core.js';
|
|
4
4
|
import { LionInput } from '@lion/ui/input.js';
|
|
5
|
-
import { formatNumber } from '@lion/ui/localize.js';
|
|
5
|
+
import { formatNumber } from '@lion/ui/localize-no-side-effects.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {import('lit').CSSResult} CSSResult
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Unparseable } from '@lion/ui/form-core.js';
|
|
2
|
-
import { LocalizeMixin
|
|
2
|
+
import { LocalizeMixin } from '@lion/ui/localize-no-side-effects.js';
|
|
3
3
|
import { LionInput } from '@lion/ui/input.js';
|
|
4
4
|
|
|
5
5
|
import { PhoneUtilManager } from './PhoneUtilManager.js';
|
|
@@ -125,7 +125,7 @@ export class LionInputTel extends LocalizeMixin(LionInput) {
|
|
|
125
125
|
// @ts-expect-error
|
|
126
126
|
// eslint-disable-next-line class-methods-use-this
|
|
127
127
|
get fieldName() {
|
|
128
|
-
return
|
|
128
|
+
return this._localizeManager.msg('lion-input-tel:phoneNumber');
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
@@ -227,7 +227,7 @@ export class LionInputTel extends LocalizeMixin(LionInput) {
|
|
|
227
227
|
onLocaleUpdated() {
|
|
228
228
|
super.onLocaleUpdated();
|
|
229
229
|
|
|
230
|
-
const localeSplitted =
|
|
230
|
+
const localeSplitted = this._localizeManager.locale.split('-');
|
|
231
231
|
/**
|
|
232
232
|
* @protected
|
|
233
233
|
* @type {RegionCode}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '@open-wc/testing';
|
|
10
10
|
import sinon from 'sinon';
|
|
11
11
|
import { mimicUserInput } from '@lion/ui/form-core-test-helpers.js';
|
|
12
|
-
import {
|
|
12
|
+
import { getLocalizeManager } from '@lion/ui/localize-no-side-effects.js';
|
|
13
13
|
import { Unparseable } from '@lion/ui/form-core.js';
|
|
14
14
|
import { LionInputTel, PhoneNumber, PhoneUtilManager } from '@lion/ui/input-tel.js';
|
|
15
15
|
import { mockPhoneUtilManager, restorePhoneUtilManager } from '@lion/ui/input-tel-test-helpers.js';
|
|
@@ -23,7 +23,8 @@ const fixture = /** @type {(arg: string | TemplateResult) => Promise<LionInputTe
|
|
|
23
23
|
const fixtureSync = /** @type {(arg: string | TemplateResult) => LionInputTel} */ (_fixtureSync);
|
|
24
24
|
|
|
25
25
|
const getRegionCodeBasedOnLocale = () => {
|
|
26
|
-
const
|
|
26
|
+
const localizeManager = getLocalizeManager();
|
|
27
|
+
const localeSplitted = localizeManager.locale.split('-');
|
|
27
28
|
return /** @type {RegionCode} */ (localeSplitted[localeSplitted.length - 1]).toUpperCase();
|
|
28
29
|
};
|
|
29
30
|
|