メインコンテンツへスキップ

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="インデックスバー"。