CountryFlag
Overviewimport { CountryCode, CountryFlag, FlagEntry } from '@nili/ui';This is the library’s own overview page, rendered live. Switch the language or the theme in the header and it follows.
Sizes
Six sizes, 16px to 48px. The artwork is served as a static SVG rather than inlined — 444 flags in the bundle would be about 320 KB of JavaScript every consumer parses whether they render a flag or not.
import { CountryFlag } from "@nili/ui"
export function Example() {
return (
<>
<CountryFlag code="ir" size="xs" />
<CountryFlag code="ir" size="sm" />
<CountryFlag code="ir" size="md" />
<CountryFlag code="ir" size="lg" />
<CountryFlag code="ir" size="xl" />
<CountryFlag code="ir" size="2xl" />
</>
)
}Bordered
bordered adds a hairline ring — worth it for flags that are mostly white and would otherwise dissolve into the page.
import { CountryFlag } from "@nili/ui"
export function Example() {
return (
<>
<CountryFlag code="jp" size="lg" />
<CountryFlag code="jp" size="lg" bordered />
</>
)
}Labels
Omit label and the flag is decorative — which is what you want whenever the country name is already on screen beside it. Pass one when the flag is the only thing identifying the row.
import { CountryFlag } from "@nili/ui"
export function Example() {
return (
<>
{/* decorative: the name is right there */}
<span>
<CountryFlag code="de" size="sm" /> Germany
</span>
{/* named: nothing else says which country this is */}
<CountryFlag code="de" size="sm" label="Germany" />
</>
)
}Subdivisions, regions and unknown codes
Codes are case-insensitive. Subdivisions and a few non-country flags use a longer slug. An unrecognised code renders a neutral disc rather than leaving a hole in the row.
import { CountryFlag } from "@nili/ui"
export function Example() {
return (
<>
<CountryFlag code="gb-eng" size="lg" label="England" />
<CountryFlag code="es-ct" size="lg" label="Catalonia" />
<CountryFlag code="x-un" size="lg" label="United Nations" />
{/* not a real code — renders the neutral disc */}
<CountryFlag code="zz" size="lg" />
</>
)
}CountryFlag
extends Omit<ComponentPropsWithoutRef<'span'>, 'children'>, CountryFlagVariantProps
Variant axes — from the component’s cva definition
| Prop | Type | Default | Notes |
|---|---|---|---|
| size | xs | sm | md | lg | xl | 2xl | md | |
| bordered | 'true' | 'false' | false |
Other props
| Prop | Type | Default | Notes |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| code* | CountryCode | (string & {}) | — | ISO 3166-1 alpha-2 code, case-insensitive. Subdivisions and a handful of non-country flags use a longer slug (`'gb-eng'`, `'x-un'`); `COUNTRY_CODES` is the full list. An unrecognised code renders a neutral disc rather than a gap. |
| label | string | — | Accessible name. Omit it and the flag is decorative, which is what you want whenever the country name is already on screen beside it. |
| basePath | string | — | Override where the SVG files are served from, for this one flag. Prefer `setAssetBasePath()` at startup; this is for the odd case of two asset origins in one app. |
| loading | lazy | eager | lazy | Defaults to `'lazy'`. Use `'eager'` for a flag above the fold. |