@drobinetm/react-countries-flags
v1.0.4
Published
React 18+ component to display a country selector with flag icons
Maintainers
Readme
@drobinetm/react-countries-flags
@drobinetm/react-countries-flags provides a country selector component with
flag icons for React applications.
It shares data and contracts with the Angular and Vue packages through
@drobinetm/countries-flags-core.
Install
Install the package and required peer dependencies.
pnpm add @drobinetm/react-countries-flags react react-dom flag-iconsImport the flag-icons CSS once in your app entry point.
import 'flag-icons/css/flag-icons.min.css'Basic usage
import { useState } from 'react'
import { CountriesFlags } from '@drobinetm/react-countries-flags'
export function Example() {
const [country, setCountry] = useState<string | null>(null)
return (
<CountriesFlags
value={country}
onChange={(event) => setCountry(event.code)}
placeholder="Select a country"
/>
)
}Props
CountriesFlags accepts:
value?: string | nullonChange?: (event: CountryChangeEvent) => voidmax?: numberfilter?: string[]placeholder?: stringdisabled?: booleanunstyled?: booleanclassNames?: CountriesFlagsClassNamesstyles?: CountriesFlagsStylesclassName?: string
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 {
CountriesFlags,
type CountriesFlagsReactProps,
type Country,
type CountriesFlagsProps,
type CountryChangeEvent,
type CountriesFlagsClassNames,
type CountriesFlagsStyles,
} from '@drobinetm/react-countries-flags'Docs
Project docs:
- https://drm-countries-flags.netlify.app/docs/react/
License
MIT © Diovi Robinet Morales
