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
الخصائص
| الخصائص | الوصف | النوع | الافتراضي |
|---|---|---|---|
| indexList | string[] | string[] | A-Z |
| sticky | boolean | boolean | true |
| stickyOffsetTop | number | number | 0 |
| highlightColor | string | string | — |
| sx | LhSxProps | LhSxProps | — |
| children | ReactNode | ReactNode | — |
| itemSlot | (index) => ReactNode | (index: string) => ReactNode | — |
| onSelect | (index) => void | (index: string) => void | — |
IndexBarGroup
| الخصائص | الوصف | النوع |
|---|---|---|
| index | مفتاح المجموعة (مطابق لـ indexList) | string |
| sx | LhSxProps | LhSxProps |
| children | LhIndexBarItem | ReactNode |
IndexBarItem
| الخصائص | الوصف | النوع | الافتراضي |
|---|---|---|---|
| disabled | معطّل (تباين مخفّض) | boolean | false |
| sx | LhSxProps | LhSxProps | — |
| children | ReactNode | ReactNode | — |
إمكانية الوصول
- العنصر الجذري يحمل role="navigation" + aria-label="شريط الفهرس".