UNPKG

@wlucha/ng-country-select

Version:

A smart, multilingual country search with flags and codes

169 lines (168 loc) 5.92 kB
import { EventEmitter, OnInit } from '@angular/core'; import { FormControl } from '@angular/forms'; import { Observable } from 'rxjs'; import { Country } from './country.interface'; import { ThemePalette } from '@angular/material/core'; import * as i0 from "@angular/core"; export declare class CountrySelectComponent implements OnInit { /** * Set initial default country * @example { alpha2: 'de', alpha3: 'deu', translations: { de: 'Deutschland', en: 'Germany', fr: 'Allemagne', es: 'Alemania', it: 'Germania' } } */ defaultCountry: Country | null; /** * Default language for displaying country names * Currently supported: 'en', 'de', 'fr', 'es', 'it', 'ar', 'zh', 'hi', 'bn', 'pt' and 'ru' * @default 'en' */ private _lang; set lang(value: string); get lang(): string; /** * Search in all available languages or only in the selected language * @default false */ searchAllLanguages: boolean; /** * Placeholder text for the input field * @default 'Search country' */ placeholder: string; /** * Set a country programmatically */ set selectedCountry(country: Country | null); /** * Form control for the country select */ formControl: FormControl<Country | null>; /** * Debounce time for search input in milliseconds * @default 100 */ debounceTime: number; /** * Appearance style of the form field * @default 'fill' */ appearance: 'fill' | 'outline'; /** * Angular Material color palette (primary, accent, warn) * @default 'primary' */ color: ThemePalette; /** * Disables the component * @default false */ disabled: boolean; /** * Marks the field as required * @default false */ required: boolean; /** * Shows alpha2/alpha3 codes in the results * @default false */ showCodes: boolean; /** * List of country alpha2 codes to include in the filter * @default [] */ includeCountries: string[]; /** * List of country alpha2 codes to exclude from the filter * @default [] */ excludeCountries: string[]; /** * Show only alpha2 codes in the results * @default false */ alpha2Only: boolean; /** * Show only alpha3 codes in the results * @default false */ alpha3Only: boolean; /** * Whether the flag should be displayed * @default true */ showFlag: boolean; /** * Emits when a country is selected * @emits Country - Selected country object */ countrySelected: EventEmitter<Country>; /** * Emits when the input value changes * @emits string - Current search term */ inputChanged: EventEmitter<string>; /** * Emits when the autocomplete panel is closed * @emits void */ closed: EventEmitter<void>; filteredCountries$: Observable<Country[]> | undefined; private countries; height: string; private onChange; private onTouched; ngOnInit(): void; writeValue(country: Country | null): void; registerOnChange(fn: any): void; registerOnTouched(fn: any): void; /** * Handle option selection */ onOptionSelected(country: Country): void; /** * Displays the alpha2- or alpha3 code or country name in selected language * @public * @param country - Country object or null * @returns Display name string */ displayFn(country: Country | null): string; /** * Handles autocomplete panel close event * @public * @returns void */ onAutocompleteClosed(): void; /** * TrackBy function for country list optimization * @public * @param index - Array index * @param country - Country object * @returns Unique alpha2 code */ trackByAlpha2(index: number, country: Country): string; /** * Update the displayed language for countries */ private updateLanguage; /** * Initializes the filter stream with debounce * @private * @returns void */ private setupFilter; /** * Filters the list of countries based on include and exclude lists * @private * @returns void */ private filterCountryList; /** * Filters countries based on search value * @private * @param value - Search value (string or Country object) * @returns Filtered array of countries */ private filterCountries; static ɵfac: i0.ɵɵFactoryDeclaration<CountrySelectComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<CountrySelectComponent, "ng-country-select", never, { "defaultCountry": { "alias": "defaultCountry"; "required": false; }; "lang": { "alias": "lang"; "required": false; }; "searchAllLanguages": { "alias": "searchAllLanguages"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; "selectedCountry": { "alias": "selectedCountry"; "required": false; }; "formControl": { "alias": "formControl"; "required": false; }; "debounceTime": { "alias": "debounceTime"; "required": false; }; "appearance": { "alias": "appearance"; "required": false; }; "color": { "alias": "color"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "required": { "alias": "required"; "required": false; }; "showCodes": { "alias": "showCodes"; "required": false; }; "includeCountries": { "alias": "includeCountries"; "required": false; }; "excludeCountries": { "alias": "excludeCountries"; "required": false; }; "alpha2Only": { "alias": "alpha2Only"; "required": false; }; "alpha3Only": { "alias": "alpha3Only"; "required": false; }; "showFlag": { "alias": "showFlag"; "required": false; }; }, { "countrySelected": "countrySelected"; "inputChanged": "inputChanged"; "closed": "closed"; }, never, never, true, never>; }