CountryFlag
Genel görünümimport { CountryCode, CountryFlag, FlagEntry } from '@nili/ui';Bu, kütüphanenin kendi genel görünüm sayfası — canlı olarak render ediliyor. Üstten dili veya temayı değiştirin, o da değişir.
Boyutlar
On altı pikselden kırk sekize altı boyut. Görseller satır içi değil, durağan SVG olarak sunulur — pakete konan 444 bayrak, bayrak çizsin çizmesin her tüketicinin ayrıştırdığı yaklaşık 320 KB JavaScript demektir.
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" />
</>
)
}Kenarlıklı
bordered ince bir halka ekler — çoğu beyaz olan ve aksi hâlde sayfaya karışan bayraklar için değer.
import { CountryFlag } from "@nili/ui"
export function Example() {
return (
<>
<CountryFlag code="jp" size="lg" />
<CountryFlag code="jp" size="lg" bordered />
</>
)
}Etiketler
label vermezseniz bayrak süs olur — ülke adı zaten yanındaysa istediğiniz budur. Satırı tanımlayan tek şey bayraksa bir ad verin.
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" />
</>
)
}Alt bölümler, bölgeler ve bilinmeyen kodlar
Kodlar büyük/küçük harfe duyarsızdır. Alt bölümler ve birkaç ülke dışı bayrak daha uzun bir kod kullanır. Tanınmayan bir kod, satırda boşluk bırakmak yerine nötr bir disk çizer.
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
Varyant eksenleri — bileşenin cva tanımından
| Prop | Tip | Varsayılan | Notlar |
|---|---|---|---|
| size | xs | sm | md | lg | xl | 2xl | md | |
| bordered | 'true' | 'false' | false |
Diğer proplar
| Prop | Tip | Varsayılan | Notlar |
|---|---|---|---|
| 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. |