메인 콘텐츠로 건너뛰기

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로 그룹 헤더 고정(기본 ON), stickyOffsetTop은 내비바 예약 오프셋, highlightColor는 활성 색상을 덮어씁니다:

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

item 커스텀 렌더링​

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="인덱스 바".