From b20459b326a917c64ad10da54d68905af5720042 Mon Sep 17 00:00:00 2001 From: Nikita Barsukov Date: Fri, 30 Aug 2024 18:20:50 +0300 Subject: [PATCH] feat(kit): `InputPhoneInternational` can be customized with `Icon` / `Tooltip` (#8750) Co-authored-by: taiga-family-bot --- projects/cdk/constants/used-icons.ts | 1 + .../examples/2/index.ts | 14 +++- .../examples/4/index.html | 14 ++++ .../examples/4/index.less | 3 + .../examples/4/index.ts | 40 +++++++++ .../input-phone-international/index.html | 83 ++++++++++++++----- .../input-phone-international/index.ts | 7 +- .../input-phone-international.template.html | 10 +++ 8 files changed, 147 insertions(+), 25 deletions(-) create mode 100644 projects/demo/src/modules/components/input-phone-international/examples/4/index.html create mode 100644 projects/demo/src/modules/components/input-phone-international/examples/4/index.less create mode 100644 projects/demo/src/modules/components/input-phone-international/examples/4/index.ts diff --git a/projects/cdk/constants/used-icons.ts b/projects/cdk/constants/used-icons.ts index ae89234fc55b..d91abea10d97 100644 --- a/projects/cdk/constants/used-icons.ts +++ b/projects/cdk/constants/used-icons.ts @@ -45,6 +45,7 @@ export const TUI_USED_ICONS = [ '@tui.minus', '@tui.file', '@tui.trash', + '@tui.phone', '@tui.star', '@tui.rotate-ccw-square', '@tui.arrow-left', diff --git a/projects/demo/src/modules/components/input-phone-international/examples/2/index.ts b/projects/demo/src/modules/components/input-phone-international/examples/2/index.ts index 37a246b5ee2c..534101162e11 100644 --- a/projects/demo/src/modules/components/input-phone-international/examples/2/index.ts +++ b/projects/demo/src/modules/components/input-phone-international/examples/2/index.ts @@ -4,8 +4,13 @@ import {FormsModule} from '@angular/forms'; import {changeDetection} from '@demo/emulate/change-detection'; import {encapsulation} from '@demo/emulate/encapsulation'; import type {TuiCountryIsoCode} from '@taiga-ui/i18n'; -import {TuiInputPhoneInternational, TuiSortCountriesPipe} from '@taiga-ui/kit'; +import { + TuiInputPhoneInternational, + tuiInputPhoneInternationalOptionsProvider, + TuiSortCountriesPipe, +} from '@taiga-ui/kit'; import {getCountries} from 'libphonenumber-js'; +import {defer} from 'rxjs'; @Component({ standalone: true, @@ -13,6 +18,13 @@ import {getCountries} from 'libphonenumber-js'; templateUrl: './index.html', encapsulation, changeDetection, + providers: [ + tuiInputPhoneInternationalOptionsProvider({ + metadata: defer(async () => + import('libphonenumber-js/max/metadata').then((m) => m.default), + ), + }), + ], }) export default class Example { protected readonly countries = getCountries(); diff --git a/projects/demo/src/modules/components/input-phone-international/examples/4/index.html b/projects/demo/src/modules/components/input-phone-international/examples/4/index.html new file mode 100644 index 000000000000..b5b633bb89dc --- /dev/null +++ b/projects/demo/src/modules/components/input-phone-international/examples/4/index.html @@ -0,0 +1,14 @@ + + Phone number + + + diff --git a/projects/demo/src/modules/components/input-phone-international/examples/4/index.less b/projects/demo/src/modules/components/input-phone-international/examples/4/index.less new file mode 100644 index 000000000000..2724b03b8733 --- /dev/null +++ b/projects/demo/src/modules/components/input-phone-international/examples/4/index.less @@ -0,0 +1,3 @@ +tui-input-phone-international { + min-width: min(20rem, 80vw); +} diff --git a/projects/demo/src/modules/components/input-phone-international/examples/4/index.ts b/projects/demo/src/modules/components/input-phone-international/examples/4/index.ts new file mode 100644 index 000000000000..119cb742e459 --- /dev/null +++ b/projects/demo/src/modules/components/input-phone-international/examples/4/index.ts @@ -0,0 +1,40 @@ +import {Component} from '@angular/core'; +import {FormsModule} from '@angular/forms'; +import {changeDetection} from '@demo/emulate/change-detection'; +import {encapsulation} from '@demo/emulate/encapsulation'; +import {TuiIcon} from '@taiga-ui/core'; +import type {TuiCountryIsoCode} from '@taiga-ui/i18n'; +import { + TuiInputPhoneInternational, + tuiInputPhoneInternationalOptionsProvider, + TuiTooltip, +} from '@taiga-ui/kit'; +import {defer} from 'rxjs'; + +@Component({ + standalone: true, + imports: [FormsModule, TuiInputPhoneInternational, TuiIcon, TuiTooltip], + templateUrl: './index.html', + styleUrls: ['./index.less'], + encapsulation, + changeDetection, + providers: [ + tuiInputPhoneInternationalOptionsProvider({ + metadata: defer(async () => + import('libphonenumber-js/max/metadata').then((m) => m.default), + ), + }), + ], +}) +export default class Example { + protected readonly countries: readonly TuiCountryIsoCode[] = [ + 'TR', + 'IR', + 'IQ', + 'SA', + 'YE', + ]; + + protected countryIsoCode: TuiCountryIsoCode = 'TR'; + protected value = ''; +} diff --git a/projects/demo/src/modules/components/input-phone-international/index.html b/projects/demo/src/modules/components/input-phone-international/index.html index 1ffc35d0e36f..161541ccfd3c 100644 --- a/projects/demo/src/modules/components/input-phone-international/index.html +++ b/projects/demo/src/modules/components/input-phone-international/index.html @@ -64,36 +64,47 @@ [description]="metadataDescription" > -

The first step is to choose the size of metadata.

+

+ The first step is to choose the size of + + metadata + - -

- Google - - uses - - the word - "metadata" - to refer to all information about phone numbering in a particular country - what the country - code, international and national dialling prefixes are, what carrier codes are operational, - which phone numbers are possible or valid for a particular country, how to optimally format - them, which prefixes represent a particular geographical area, etc. -
- + + Google + + uses + + the word + "metadata" + to refer to all information about phone numbering in a particular country - what the country + code, international and national dialling prefixes are, what carrier codes are operational, + which phone numbers are possible or valid for a particular country, how to optimally format + them, which prefixes represent a particular geographical area, etc. + + + . +

The complete list of all phone rules is huge, so libphonenumber-js provides different "metadata" sets to provides a way to optimize bundle size by choosing between - max + max , - min + min (default value) and - mobile + mobile sets.

@@ -155,6 +166,32 @@ Don't hesitate to use it too to manually format any phone number.
+ + + + You can put static + + Icon + + or even interactive + + Tooltip + + at the right side of the textfield. + + @@ -209,7 +246,7 @@ ISO-code of selected country - + diff --git a/projects/demo/src/modules/components/input-phone-international/index.ts b/projects/demo/src/modules/components/input-phone-international/index.ts index 16100c310c1c..e82f0eb1b157 100644 --- a/projects/demo/src/modules/components/input-phone-international/index.ts +++ b/projects/demo/src/modules/components/input-phone-international/index.ts @@ -1,13 +1,15 @@ import {Component} from '@angular/core'; import {FormControl, ReactiveFormsModule, Validators} from '@angular/forms'; import {changeDetection} from '@demo/emulate/change-detection'; +import {DemoRoute} from '@demo/routes'; import {TuiDemo} from '@demo/utils'; import {tuiProvide} from '@taiga-ui/cdk'; -import {TuiDropdown, TuiHint, TuiTextfield} from '@taiga-ui/core'; +import {TuiDropdown, TuiHint, TuiIcon, TuiTextfield} from '@taiga-ui/core'; import type {TuiCountryIsoCode} from '@taiga-ui/i18n'; import { TuiInputPhoneInternational, tuiInputPhoneInternationalOptionsProvider, + TuiTooltip, } from '@taiga-ui/kit'; import {getCountries} from 'libphonenumber-js'; @@ -25,6 +27,8 @@ import {InheritedDocumentation} from '../abstract/inherited-documentation'; TuiInputPhoneInternational, TuiTextfield, ReactiveFormsModule, + TuiIcon, + TuiTooltip, ], templateUrl: './index.html', changeDetection, @@ -36,6 +40,7 @@ import {InheritedDocumentation} from '../abstract/inherited-documentation'; ], }) export default class PageComponent extends AbstractExampleTuiControl { + protected readonly routes = DemoRoute; protected readonly countriesVariants: ReadonlyArray = [ ['RU', 'KZ', 'UA', 'BY'], getCountries(), diff --git a/projects/kit/components/input-phone-international/input-phone-international.template.html b/projects/kit/components/input-phone-international/input-phone-international.template.html index 6fe976f9c575..6fcded367050 100644 --- a/projects/kit/components/input-phone-international/input-phone-international.template.html +++ b/projects/kit/components/input-phone-international/input-phone-international.template.html @@ -37,6 +37,16 @@ (ngModelChange)="onValueChange($event)" /> + + +