CountryFlag
عرض شاملimport { CountryCode, CountryFlag, FlagEntry } from '@nili/ui';هذه صفحة العرض الشامل الخاصة بالمكتبة، معروضة حيّة. غيّر اللغة أو السمة من الأعلى وسَتتبعك.
الأحجام
ستة أحجام، من ١٦ إلى ٤٨ بكسل. تُقدَّم الرسوم كملفات SVG ساكنة لا مضمّنة — فـ٤٤٤ علمًا داخل الحزمة تعني نحو ٣٢٠ كيلوبايت من الجافاسكربت يحلّلها كل مستهلك سواء رسم علمًا أم لا.
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 حلقة رفيعة — وهي مفيدة للأعلام البيضاء في معظمها التي تذوب في الصفحة بدونها.
import { CountryFlag } from "@nili/ui"
export function Example() {
return (
<>
<CountryFlag code="jp" size="lg" />
<CountryFlag code="jp" size="lg" bordered />
</>
)
}التسميات
إن حذفت label صار العلم زخرفيًا — وهو المطلوب كلما كان اسم البلد مكتوبًا بجواره. ومرِّرها حين يكون العلم وحده ما يعرّف الصف.
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" />
</>
)
}التقسيمات والمناطق والرموز المجهولة
الرموز غير حسّاسة لحالة الأحرف. وتستخدم التقسيمات وبعض الأعلام غير الوطنية رمزًا أطول. ويرسم الرمز غير المعروف قرصًا محايدًا بدل أن يترك فجوة في الصف.
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
محاور التنويع — من تعريف cva للمكوّن
| الخاصيّة | النوع | الافتراضي | ملاحظات |
|---|---|---|---|
| size | xs | sm | md | lg | xl | 2xl | md | |
| bordered | 'true' | 'false' | false |
باقي الخصائص
| الخاصيّة | النوع | الافتراضي | ملاحظات |
|---|---|---|---|
| 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. |