Dropdown
نمای کلیimport { Dropdown, DropdownOption } from '@nili/ui';این همان صفحهی نمای کلیِ خود کتابخانه است که زنده رندر میشود. زبان یا تم را از هدر عوض کنید، همراهش میآید.
انواع
چهار الگوی اسلات پیشرو از اورویوی فیگما. پراپ type وجود ندارد — هر نودی را از startAdornment بدهید. هر نمونه زیربرچسب اختیاری، آیکون اطلاعات و راهنما را هم دارد.
This is a hint text to help user.
This is a hint text to help user.
This is a hint text to help user.
This is a hint text to help user.
import {
Dropdown,
Icon,
Avatar,
CountryFlag,
PlaceholderLogo,
} from "@nili/ui"
import { RiFlashlightLine } from "@remixicon/react"
// Icon
const iconOptions = [
{
value: "design",
label: "Design",
startAdornment: <Icon icon={RiFlashlightLine} />,
},
]
// Country
const countryOptions = [
{
value: "ir",
label: "Iran",
startAdornment: <CountryFlag code="ir" size="sm" />,
},
]
// User
const userOptions = [
{
value: "sophia",
label: "Sophia Williams",
description: "Product design",
startAdornment: <Avatar size="3xs" name="Sophia Williams" />,
},
]
// Company
const companyOptions = [
{
value: "apex",
label: "Apex Financial",
description: "Finance & Banking",
startAdornment: (
<PlaceholderLogo company="apex-financial" size="xs" label="" />
),
},
]
export function Example() {
return (
<Dropdown
label="Label"
sublabel="(Optional)"
information
hint="This is a hint text to help user."
placeholder="Select…"
options={iconOptions}
/>
)
}اندازهها
اندازهٔ md (۴۰ پیکسل) پیشفرض است. sm و xs با مقیاس Text Input میخوانند.
import { Dropdown } from "@nili/ui"
export function Example() {
return (
<>
<Dropdown size="md" label="Medium" options={options} />
<Dropdown size="sm" label="Small" options={options} />
<Dropdown size="xs" label="X-Small" options={options} />
</>
)
}ظاهرها
default همان فیلد کامل است. compact برای نوار ابزارهای فشردهتر حاشیه را برمیدارد. inline فقط متن است.
import { Dropdown } from "@nili/ui"
export function Example() {
return (
<>
<Dropdown appearance="default" options={options} />
<Dropdown appearance="compact" options={options} />
<Dropdown appearance="inline" options={options} />
</>
)
}قابلجستوجو
برای فهرستهای بلند searchable را روشن کنید. فیلد جستوجو فوکوس را نگه میدارد در حالی که با کیبورد در فهرست حرکت میکنید.
import { Dropdown, Avatar } from "@nili/ui"
export function Example() {
return (
<Dropdown
label="Assignee"
placeholder="Search people…"
options={userOptions}
itemSize="lg"
searchable
searchPlaceholder="Search people…"
/>
)
}غیرفعال و خطا
برای نمایش پیام اعتبارسنجی error بدهید؛ فیلد خودکار نامعتبر علامت میخورد. disabled واقعاً همان صفت disabled است.
Please select an option
import { Dropdown } from "@nili/ui"
export function Example() {
return (
<>
<Dropdown disabled label="Disabled" options={options} />
<Dropdown
label="Required field"
options={options}
error="Please select an option"
/>
</>
)
}Dropdown
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' | 'defaultValue' | 'children' >
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| options* | DropdownOption[] | — | |
| value | string | null | — | |
| defaultValue | string | null | — | |
| onChange | (value: string) => void | — | |
| placeholder | ReactNode | Select… | |
| size | md | sm | xs | md | |
| itemSize | lg | sm | sm | |
| appearance | default | compact | inline | default | |
| disabled | boolean | false | |
| invalid | boolean | false | |
| searchable | boolean | false | Figma misc. item "Search". |
| searchPlaceholder | string | Search… | |
| emptyMessage | ReactNode | No results | |
| footer | ReactNode | — | Figma misc. items "Button" / "Button Group", pinned under the list. |
| label | ReactNode | — | Figma `🔖 Label` — the visible label above the field, drawn with the same `Label` component the Text Input page uses. |
| sublabel | ReactNode | — | Figma Label's `💬 Sublabel` — the muted "(Optional)". |
| information | boolean | ReactNode | false | Figma Label's `ℹ️ Information` glyph. `true` uses the default icon. |
| informationLabel | string | — | Accessible name for that glyph. |
| labelAction | ReactNode | — | Figma Label's `🌟 Button` — trailing slot on the label row. |
| hint | ReactNode | — | Figma `💡 Hint Text` — the line under the field. |
| error | ReactNode | — | Validation message. Its presence is what marks the field invalid. |
| badge | ReactNode | — | Figma `🎖️ Badge` — inside the trigger, after the value. |
| ariaLabel | string | — | Accessible name when no visible `label` is rendered. |
| required | boolean | — | |
| rootClassName | string | — | Applied to the outer wrapper rather than to the field. |
| triggerClassName | string | — | |
| menuClassName | string | — |
DropdownCaption
داخلیDropdownItem
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| size | sm | lg | sm | |
| selected | 'true' | 'false' | false | |
| active | 'true' | 'false' | false |
DropdownMenu
داخلیDropdownSearch
داخلیDropdownTrigger
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| size | md | sm | xs | md | |
| filled | 'true' | 'false' | false | |
| invalid | 'true' | 'false' | false | |
| appearance | default | compact | inline | default |