تخطّي إلى المحتوى الرئيسي

IndexBar

شريط فهرس بأسلوب جهات الاتصال: فهرس أبجدي جانبي + مجموعات مثبتة. يتم استهلاك تنشيط scroll-spy (resolveActiveIndex) واكتشاف اللمس (hitIndexBar) كدوال نقية من @lh-ui/share/core/index-bar.

الاستخدام الأساسي​

شريط الفهرس (نقر / لمس للانتقال إلى المجموعة)

الفهرس الحالي: —

import { useState } from 'react'
import { LhIndexBar, LhIndexBarGroup, LhIndexBarItem } from '@lh-ui/react'

export default function Demo() {
const [current, setCurrent] = useState('')

const groups: Record<string, string[]> = {
A: ['阿白', '阿黄'],
B: ['柏舟', '薄荷'],
C: ['春日', '椿'],
}

return (
<LhIndexBar indexList={['A', 'B', 'C']} onSelect={setCurrent}>
{(['A', 'B', 'C'] as const).map((key) => (
<LhIndexBarGroup key={key} index={key}>
{groups[key].map((name) => (
<LhIndexBarItem key={name}>{name}</LhIndexBarItem>
))}
</LhIndexBarGroup>
))}
</LhIndexBar>
)
}

رأس لاصق وتمييز مخصص​

يثبت sticky رأس المجموعة (مفعّل افتراضيًا)، ويريح stickyOffsetTop مساحة لشريط التنقل، ويتجاوز highlightColor اللون النشط:

<LhIndexBar indexList={['甲', '乙', '丙']} stickyOffsetTop={0} highlightColor="#c0392b">
<LhIndexBarGroup index="甲"><LhIndexBarItem>甲一</LhIndexBarItem></LhIndexBarGroup>
<LhIndexBarGroup index="乙"><LhIndexBarItem>乙一</LhIndexBarItem></LhIndexBarGroup>
<LhIndexBarGroup index="丙"><LhIndexBarItem>丙一</LhIndexBarItem></LhIndexBarGroup>
</LhIndexBar>

عرض مخصص للعنصر​

يستبدل itemSlot عنصر الفهرس الافتراضي (من جانب Vue: فتحة #item):

<LhIndexBar indexList={['A', 'B']} itemSlot={(index) => <b>项{index}</b>} />

IndexBar API​

الخصائص​

الخصائصالوصفالنوعالافتراضي
indexListstring[]string[]A-Z
stickybooleanbooleantrue
stickyOffsetTopnumbernumber0
highlightColorstringstring—
sxLhSxPropsLhSxProps—
childrenReactNodeReactNode—
itemSlot(index) => ReactNode(index: string) => ReactNode—
onSelect(index) => void(index: string) => void—

IndexBarGroup​

الخصائصالوصفالنوع
indexمفتاح المجموعة (مطابق لـ indexList)string
sxLhSxPropsLhSxProps
childrenLhIndexBarItemReactNode

IndexBarItem​

الخصائصالوصفالنوعالافتراضي
disabledمعطّل (تباين مخفّض)booleanfalse
sxLhSxPropsLhSxProps—
childrenReactNodeReactNode—

إمكانية الوصول​

  • العنصر الجذري يحمل role="navigation" + aria-label="شريط الفهرس".