@drobinetm/angular-countries-flags
v1.0.4
Published
Angular 17+ standalone component to display a country selector with flag icons
Maintainers
Readme
@drobinetm/angular-countries-flags
@drobinetm/angular-countries-flags provides a standalone country selector
component with flag icons for Angular applications.
It shares data and contracts with the React and Vue packages through
@drobinetm/countries-flags-core.
Install
Install the package and required peer dependencies.
pnpm add @drobinetm/angular-countries-flags @angular/common @angular/core @angular/forms flag-iconsImport the flag-icons CSS once in your global styles.
@import 'flag-icons/css/flag-icons.min.css';Basic usage
import { Component } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { CountriesFlagsComponent } from '@drobinetm/angular-countries-flags'
@Component({
selector: 'app-root',
standalone: true,
imports: [FormsModule, CountriesFlagsComponent],
template: `
<drm-countries-flags
[(ngModel)]="country"
placeholder="Select a country"
(valueChange)="onCountryChange($event)"
/>
`,
})
export class AppComponent {
country: string | null = null
onCountryChange(event: { code: string | null }) {
console.log(event.code)
}
}Inputs
CountriesFlagsComponent supports:
max?: numberfilter?: string[]placeholder?: stringdisabled?: booleanunstyled?: booleanclassNames?: CountriesFlagsClassNamesstyles?: CountriesFlagsStyles
It also supports Angular forms via ControlValueAccessor (ngModel and
reactive forms).
Output
valueChange: EventEmitter<CountryChangeEvent>
Styling
By default, the package includes its own styles.
- Set
unstyledtotrueif you want to style every slot yourself. - Use
classNamesfor class-based overrides per slot. - Use
stylesfor inline style-object overrides per slot.
Available slots:
roottriggertriggerContentplaceholderlabelchevronbackdroplistemptyoptionoptionSelectedoptionActiveflagoptionName
Accessibility
The component includes keyboard and ARIA support:
Enter/Space: open or selectArrowUp/ArrowDown: move active optionHome/End: jump to first or last optionEscape: close dropdown
Exports
import {
CountriesFlagsComponent,
type Country,
type CountriesFlagsProps,
type CountryChangeEvent,
type CountriesFlagsClassNames,
type CountriesFlagsStyles,
} from '@drobinetm/angular-countries-flags'Docs
Project docs:
- https://drm-countries-flags.netlify.app/docs/angular/
License
MIT © Diovi Robinet Morales
