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

الشريط الجانبي

شريط جانبي روابطه تُعرض على الخادم، وينطوي إلى عمود من الأيقونات. الشريط وزرّه وحدهما يعملان في المتصفح.

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

الشريط الجانبي

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

شريط جانبي روابطه تُعرض على الخادم، وينطوي إلى عمود من الأيقونات. الشريط وزرّه وحدهما يعملان في المتصفح.

تثبيت

جرّبه

defaultOpen
open
current

الشيفرة

sidebar.tsx
import { folder } from 'topclassui/icons/folder'
import { gear } from 'topclassui/icons/gear'
import { house } from 'topclassui/icons/house'
import { Svg } from 'topclassui/svg'
import { SidebarBody, SidebarGroup, SidebarHeader, SidebarLink, SidebarRoot } from 'topclassui/sidebar'

<div className="h-96">
  <SidebarRoot>
    <SidebarHeader>Workspace</SidebarHeader>
    <SidebarBody>
      <SidebarGroup>
        <SidebarLink href="#home" icon={<Svg icon={house} />}>Home</SidebarLink>
        <SidebarLink href="#projects" icon={<Svg icon={folder} />}>Projects</SidebarLink>
        <SidebarLink href="#settings" icon={<Svg icon={gear} />}>Settings</SidebarLink>
      </SidebarGroup>
    </SidebarBody>
  </SidebarRoot>
</div>

مع defaultOpen={false} يرسل الخادم الشريط مطويًّا، فلا يتحرك شيء عند الترطيب.

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

حالتان

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

topclassui/sidebar
import { SidebarRoot, SidebarTrigger, SidebarHeader, SidebarBody, SidebarGroup, SidebarLink } from 'topclassui/sidebar'

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

أمثلة

  • ستة أجزاء بأسماء مسطّحة، ولا يوجد Sidebar وحده. SidebarRoot وSidebarTrigger يعملان في المتصفح، وSidebarHeader وSidebarBody وSidebarGroup وSidebarLink HTML من الخادم. SidebarHeader يرسم زر الطي بنفسه.
  • أعطِ العنصر الأب للشريط ارتفاعًا، مثل h-dvh. عندها تمرّر القائمة الطويلة داخل SidebarBody، ولا تتحرك الصفحة.
  • في صف flex يحافظ الشريط على عرضه 220 px، أو 60 وهو مطوي. أعطِ العمود المجاور له min-w-0 flex-1.
  • الرابط يأخذ href، أو render={<Link href="/docs" />} في Next.js. كل خاصية أخرى تذهب إلى الرابط، لا إلى عنصر القائمة حوله.
  • أعطِ كل رابط icon إن كان الشريط ينطوي: وهو مطوي، الأيقونة هي كل ما يُرسم.
  • open مع onOpenChange يحتاجان ملفًا فيه 'use client'، كما في المثال المتحكَّم به. عندها يستطيع زر خارج الشريط أن يطويه.
  • لعرض آخر: className="data-open:w-72" على SidebarRoot، ويبقى عرض الشريط المطوي كما هو. على الهاتف ابدأ به مطويًّا: صيغة الدرج لم تُبنَ بعد.
basic
groups
collapsed
controlled

The rail asked to change 0 times.

in-a-layout

Orders

Orders
OrderCustomerPlacedStatusTotal
ORD-5521Northwind Traders12 Mar 2026Awaiting payment$1,250.00
ORD-5520Contoso Ltd11 Mar 2026Shipped$480.00
ORD-5519Fabrikam Inc11 Mar 2026Awaiting payment$9,120.50
long-list
بالعربية، من اليمين إلى اليسار

الخصائص

SidebarRoot

خصائص SidebarRoot
الخاصيةالنوعالافتراضيالحدودالوصف
childrenReactNode--A SidebarHeader, then a SidebarBody holding the groups and their links.
defaultOpenbooleantrue-SidebarRoot: whether the rail starts expanded. false starts it as a column of icons, in the server HTML too.
onOpenChange((open: boolean) => void)--Called with the state the trigger asks for, once a press. A function: pass it from a client file.
openboolean--SidebarRoot: the state, held by the caller. Pair it with onOpenChange, in a client file.

SidebarTrigger

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

SidebarHeader

خصائص SidebarHeader
الخاصيةالنوعالافتراضيالحدودالوصف
childrenReactNode--The title beside the trigger. It is hidden, and still read out, while the rail is collapsed.

SidebarBody

خصائص SidebarBody
الخاصيةالنوعالافتراضيالحدودالوصف
childrenReactNode--The groups. A list longer than the rail scrolls here, under the header.

SidebarGroup

خصائص SidebarGroup
الخاصيةالنوعالافتراضيالحدودالوصف
childrenReactNode--The SidebarLink rows of the group.
labelReactNode--The heading of the group, which names its list. Hidden, and still read out, while the rail is collapsed.

SidebarLink

خصائص SidebarLink
الخاصيةالنوعالافتراضيالحدودالوصف
aria-labelstring--
childrenReactNode--The label. It ends in an ellipsis when the rail is too narrow, and is cut at 100 characters.
hrefstring--Where the row goes.
renderReactElement--The link as another element, such as render={<Link href="/docs" />}, which carries its own href.
currentbooleanfalse-SidebarLink: the page being read. It sets aria-current="page" and draws the row filled, bold and marked.
iconReactNode--Drawn before the label, and all that is drawn while the rail is collapsed. Decorative: the label names the row.

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

لوحة مفاتيح Sidebar
المفاتيحما يفعله
Tabينتقل إلى زر الطي، ثم إلى كل رابط.
Enterعلى زر الطي يوسّع الشريط أو يطويه، وعلى رابط يتبعه.
Spaceعلى زر الطي يوسّع الشريط أو يطويه.
  • زر الطي زر حقيقي عليه aria-expanded، واسمه ما ستفعله الضغطة: «طي الشريط الجانبي» أو «توسيع الشريط الجانبي».
  • current على رابط SidebarLink واحد يضع aria-current="page" ويرسم الصف معبّأً وعريض الخط وبشريط عند بدايته.
  • وهو مطوي، يختفي العنوان واسم كل مجموعة وتسمية كل رابط عن الشاشة، ويبقى قارئ الشاشة يقرؤها.

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

مع dir="rtl" يكون خط الشريط على يساره وزر الطي على يمينه، وأيقونته معكوسة. TopClassProvider مع locale="ar" يسمّي الاثنين بالعربية.

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

يُعرض على الخادم، والجزء التفاعلي مكوّن متصفح لا يُرسل إلا عند استخدامه.

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

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