انتقل إلى المحتوى
TopClass UI

قائمة منسدلة

قائمة إجراءات وروابط خلف زر واحد. صفوف الروابط روابط حقيقية، فيعمل الفتح في علامة تبويب جديدة والنقر بالزر الأوسط.

client - الحجم لم يُقَس بعد

قائمة منسدلة

client - الحجم لم يُقَس بعد

قائمة إجراءات وروابط خلف زر واحد. صفوف الروابط روابط حقيقية، فيعمل الفتح في علامة تبويب جديدة والنقر بالزر الأوسط.

تثبيت

جرّبه

placement
tone
delay
closeDelay

الشيفرة

dropdown.tsx
import { copy } from 'topclassui/icons/copy'
import { gear } from 'topclassui/icons/gear'
import { trash } from 'topclassui/icons/trash'
import { user } from 'topclassui/icons/user'
import { Button } from 'topclassui/button'
import { Svg } from 'topclassui/svg'
import { DropdownItem, DropdownPopup, DropdownRoot, DropdownSeparator, DropdownTrigger } from 'topclassui/dropdown'

<DropdownRoot>
  <DropdownTrigger openOnHover render={<Button variant="outline">Actions</Button>} />
  <DropdownPopup>
    <DropdownItem icon={<Svg icon={user} />} shortcut="Ctrl P">Profile</DropdownItem>
    <DropdownItem icon={<Svg icon={gear} />}>Settings</DropdownItem>
    <DropdownItem icon={<Svg icon={copy} />}>Duplicate</DropdownItem>
    <DropdownSeparator />
    <DropdownItem icon={<Svg icon={trash} />}>Delete</DropdownItem>
  </DropdownPopup>
</DropdownRoot>

عناصر href وإجراء الخادم تعمل من صفحة خادم؛ أما onSelect فدالة عادية تحتاج ملف عميل.

كل الحالات، بدون تمرير الفأرة

4 حالات

أو استورده من الحزمة

topclassui/dropdown
import { DropdownRoot, DropdownGroup, DropdownGroupLabel, DropdownItem, DropdownLinkItem, DropdownMenu, DropdownPopup, DropdownSeparator, DropdownTrigger } from 'topclassui/dropdown'

ثبّت مرة واحدة:npm i topclassui@beta zod

أمثلة

  • لقائمة قصيرة من الإجراءات أو الروابط خلف زر واحد. كل ما ليس صفًا يوضع في نافذة منبثقة.
  • أجزاء بأسماء مسطّحة ولا يوجد Dropdown وحده: DropdownRoot وDropdownTrigger وDropdownPopup وDropdownItem وDropdownLinkItem وDropdownGroup وDropdownGroupLabel وDropdownSeparator.
  • DropdownMenu يبني القائمة نفسها من items: كل عنصر رابط href أو إجراء خادم action أو دالة onSelect. مرّر Link إطار عملك إلى link.
  • يأخذ الصف icon قبل التسمية وshortcut بعدها، والتسمية الطويلة تنتهي بعلامة حذف.
  • عرض القائمة بعرض أطول صف، من 192 إلى 320 بكسل، وتعرض نحو سبعة صفوف قبل أن تتمرّر داخلها.
  • كل الصفوف مركّبة: أبقِ القائمة في حدود عشرات الصفوف.
basic
groups
danger-item
with-links
data-driven
placements
sixty-items
in-dialog
بالعربية، من اليمين إلى اليسار

الخصائص

DropdownRoot

خصائص DropdownRoot
الخاصيةالنوعالافتراضيالحدودالوصف
childrenReactNode--The trigger and the popup. With no trigger, hold open in a client file.

DropdownGroup

لا خصائص خاصة به: يأخذ سمات العنصر الذي يعرضه.

DropdownGroupLabel

لا خصائص خاصة به: يأخذ سمات العنصر الذي يعرضه.

DropdownItem

خصائص DropdownItem
الخاصيةالنوعالافتراضيالحدودالوصف
aria-labelstring--
childrenReactNode--
iconReactNode--Drawn before the label. An element, such as <Svg icon={trash} />: it is not a name.
shortcutstring--Shown at the end of the row, such as Ctrl P. It is read out after the label.
toneneutral | danger"neutral"-DropdownItem, DropdownLinkItem: danger colours a destructive row; its label still has to say so.

DropdownLinkItem

خصائص DropdownLinkItem
الخاصيةالنوعالافتراضيالحدودالوصف
aria-labelstring--
childrenReactNode--
iconReactNode--Drawn before the label. An element, such as <Svg icon={trash} />: it is not a name.
shortcutstring--Shown at the end of the row, such as Ctrl P. It is read out after the label.
toneneutral | danger"neutral"-DropdownItem, DropdownLinkItem: danger colours a destructive row; its label still has to say so.

DropdownMenu

خصائص DropdownMenu
الخاصيةالنوعالافتراضيالحدودالوصف
items*readonly MenuItem[]--
title*string--The name of the menu, which labels its group of items.
trigger*ReactElement--The element that opens the menu, such as a Button.
defaultOpenboolean--
linkReactElement--The element every href item is cloned from, such as link={<Link href="" />}; its href is replaced with the item's.
onOpenChange((open: boolean) => void)--Client only, like onSelect.
openboolean--
placementtop | top-start | top-end | bottom | bottom-start | bottom-end | start | start-top | start-bottom | end | end-top | end-bottom"bottom-start"-DropdownPopup, DropdownMenu: the side and alignment it opens at; start and end mirror in Arabic.

DropdownPopup

خصائص DropdownPopup
الخاصيةالنوعالافتراضيالحدودالوصف
placementtop | top-start | top-end | bottom | bottom-start | bottom-end | start | start-top | start-bottom | end | end-top | end-bottom"bottom-start"-DropdownPopup, DropdownMenu: the side and alignment it opens at; start and end mirror in Arabic.

DropdownSeparator

لا خصائص خاصة به: يأخذ سمات العنصر الذي يعرضه.

DropdownTrigger

خصائص DropdownTrigger
الخاصيةالنوعالافتراضيالحدودالوصف
closeDelaynumber, min 0, max 100000min 0, max 10000DropdownTrigger, with openOnHover: milliseconds it stays open after the pointer leaves, clamped.
delaynumber, min 0, max 10000100min 0, max 10000DropdownTrigger, with openOnHover: milliseconds of hover before it opens, clamped.

لوحة المفاتيح وإمكانية الوصول

لوحة مفاتيح Dropdown
المفاتيحما يفعله
EnterSpaceArrowDownعلى المشغّل، يفتح القائمة على الصف الأول.
ArrowUpعلى المشغّل، يفتح القائمة على الصف الأخير.
ArrowDownArrowUpيتنقّلان بين الصفوف، ويدوران عند الطرفين.
HomeEndيقفزان إلى الصف الأول أو الأخير.
A-Zالحرف ينقل إلى الصف الذي يبدأ به.
EnterSpaceينفّذ الصف ويغلق القائمة.
Escapeيغلق القائمة. يعود التركيز إلى المشغّل.
Tabيغلق القائمة وينتقل إلى عنصر التحكم التالي في الصفحة.
  • tone="danger" يلوّن الصف فقط: اكتب ما يفعله في التسمية، وأضف أيقونة، وضع فاصلًا فوقه.
  • الصف الذي يحمل أيقونة فقط يحتاج aria-label، والأنواع تطلبه.
  • الصف المعطّل يُعلن أنه غير متاح، وتتوقف عنده مفاتيح الأسهم مع ذلك.

من اليمين إلى اليسار

bottom-start تحاذي الحواف اليمنى، وتقع الأيقونة على اليمين والاختصار على اليسار. تأخذ القائمة اتجاهها من أقرب TopClassProvider.

الخادم والمتصفح

مكوّن متصفح: يُعرض على الخادم ثم يُرطَّب في المتصفح.

الملفات: index.tsx, client.tsx.

على الشارة: client - الحجم لم يُقَس بعد.