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
プロパティ
| プロパティ | 説明 | 型 | デフォルト |
|---|---|---|---|
| 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="インデックスバー"。