Skip to content

Commit

Permalink
fix(kit): improve tree-shakeability of InputPhoneInternational (#8603)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Aug 19, 2024
1 parent ff06f79 commit abfba9e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
12 changes: 10 additions & 2 deletions projects/demo-cypress/src/tests/input-phone-international.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {provideAnimations} from '@angular/platform-browser/animations';
import {TuiRoot} from '@taiga-ui/core';
import type {TuiCountryIsoCode} from '@taiga-ui/i18n';
import {TuiInputPhoneInternational} from '@taiga-ui/kit';
import {
TuiInputPhoneInternational,
tuiInputPhoneInternationalOptionsProvider,
} from '@taiga-ui/kit';
import {createOutputSpy} from 'cypress/angular';

@Component({
Expand All @@ -20,7 +23,12 @@ import {createOutputSpy} from 'cypress/angular';
></tui-input-phone-international>
</tui-root>
`,
providers: [provideAnimations()],
providers: [
provideAnimations(),
tuiInputPhoneInternationalOptionsProvider({
metadata: import('libphonenumber-js/max/metadata').then((m) => m.default),
}),
],
})
export class Test implements OnInit {
private readonly destroyRef = inject(DestroyRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {TuiDemo} from '@demo/utils';
import {tuiProvide} from '@taiga-ui/cdk';
import {TuiDropdown, TuiHint, TuiTextfield} from '@taiga-ui/core';
import type {TuiCountryIsoCode} from '@taiga-ui/i18n';
import {TuiInputPhoneInternational} from '@taiga-ui/kit';
import {
TuiInputPhoneInternational,
tuiInputPhoneInternationalOptionsProvider,
} from '@taiga-ui/kit';
import {getCountries} from 'libphonenumber-js';

import {ABSTRACT_PROPS_ACCESSOR} from '../abstract/abstract-props-accessor';
Expand All @@ -25,7 +28,12 @@ import {InheritedDocumentation} from '../abstract/inherited-documentation';
],
templateUrl: './index.html',
changeDetection,
providers: [tuiProvide(ABSTRACT_PROPS_ACCESSOR, PageComponent)],
providers: [
tuiProvide(ABSTRACT_PROPS_ACCESSOR, PageComponent),
tuiInputPhoneInternationalOptionsProvider({
metadata: import('libphonenumber-js/max/metadata').then((m) => m.default),
}),
],
})
export default class PageComponent extends AbstractExampleTuiControl {
protected readonly countriesVariants: ReadonlyArray<readonly TuiCountryIsoCode[]> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type {Provider} from '@angular/core';
import {tuiCreateToken, tuiProvideOptions} from '@taiga-ui/cdk/utils/miscellaneous';
import type {TuiCountryIsoCode} from '@taiga-ui/i18n/types';
import type {MetadataJson} from 'libphonenumber-js/core';
import type {Observable} from 'rxjs';
import {defer} from 'rxjs';
import {type Observable, of} from 'rxjs';

export interface TuiInputPhoneInternationalOptions {
readonly countries: readonly TuiCountryIsoCode[];
Expand All @@ -15,9 +14,7 @@ export const TUI_INPUT_PHONE_INTERNATIONAL_DEFAULT_OPTIONS: TuiInputPhoneInterna
{
countries: [],
countryIsoCode: 'RU',
metadata: defer(async () =>
import('libphonenumber-js/min/metadata').then((m) => m.default),
),
metadata: of({countries: {}, country_calling_codes: {}}),
};

/**
Expand Down

0 comments on commit abfba9e

Please sign in to comment.