IndexBar インデックスバー
連絡先式のインデックスバー:右側のアルファベットインデックス + グループアンカーの位置決め。scroll-spy のアクティブ換算 (resolveActiveIndex)とタッチ換算(hitIndexBar)はすべて @lh-ui/share/core/index-bar の純粋なロジックを利用し、本コンポーネントは DOM 計測 + scrollTo のグルーコードのみを記述します。
基本的な使い方
インデックスバー(クリック / タッチでグループへ位置決め)
A
阿白
阿黄
B
柏舟
薄荷
C
春日
椿
A
B
C
現在のインデックス:
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhIndexBar, LhIndexBarGroup, LhIndexBarItem } from '@lh-ui/vue3'
const current = ref('')
const groups: Record<string, string[]> = {
A: ['阿白', '阿黄'],
B: ['柏舟', '薄荷'],
C: ['春日', '椿'],
}
function onSelect(index: string) {
current.value = index
}
</script>
<template>
<LhIndexBar :index-list="['A', 'B', 'C']" @select="onSelect">
<LhIndexBarGroup v-for="key in ['A', 'B', 'C']" :key="key" :index="key">
<LhIndexBarItem v-for="name in groups[key]" :key="name">{{ name }}</LhIndexBarItem>
</LhIndexBarGroup>
</LhIndexBar>
</template>吸着とカスタムハイライト
sticky でグループヘッダーの上部吸着を有効化(デフォルトで有効)。sticky-offset-top はナビゲーションバーの確保分のオフセット、 highlight-color はアクティブインデックスのハイライト色をカスタマイズします。
吸着 + カスタムハイライト色
甲
甲一
乙
乙一
丙
丙一
甲
乙
丙
API
IndexBar Props
| プロパティ | 説明 | 型 | デフォルト値 |
|---|---|---|---|
| index-list | インデックス項目の配列(未指定時はデフォルトで A-Z の 26 項目。空配列の場合はサイドバーをレンダリングしない) | string[] | A-Z |
| sticky | アンカーグループヘッダーの上部吸着 | boolean | true |
| sticky-offset-top | 吸着オフセット px(ナビゲーションバーの確保用) | number | 0 |
| highlight-color | アクティブインデックスのハイライト色(未指定時は indexBar.highlightColor トークンを使用) | string | — |
IndexBar Events
| イベント | 説明 | コールバック |
|---|---|---|
| select | サイドバーのインデックス項目をクリック / タッチ | index: string |
IndexBar Slots
| スロット名 | 説明 | ペイロード |
|---|---|---|
| default | グループの内容(LhIndexBarGroup / LhIndexBarItem のペア) | — |
| item | インデックス項目のカスタムレンダリング | { index } |
IndexBarGroup Props
| プロパティ | 説明 | 型 | デフォルト値 |
|---|---|---|---|
| index | グループのインデックスキー(indexList の項目と対応) | string | — |
IndexBarItem Props
| プロパティ | 説明 | 型 | デフォルト値 |
|---|---|---|---|
| disabled | 無効(コントラストを下げる) | boolean | false |
IndexBarItem Slots
| スロット名 | 説明 |
|---|---|
| default | 項目の内容 |

