scrollspy
Basic scrollspy
Basic scrollspy
Загрузка превью…
src/scrollspy/c-scrollspy-1.vue
<!-- ПОРТ (registry-reui/bases/radix/components/scrollspy/c-scrollspy-1.tsx). -->
<script setup lang="ts">
import { ref } from "vue"
import { Scrollspy } from "@/components/reui/scrollspy"
import { Button } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
const parentRef = ref<HTMLDivElement | null>(null)
const nav = [
{
id: "section-1",
label: "Section 1",
},
{
id: "section-2",
label: "Section 2",
},
{
id: "section-3",
label: "Section 3",
},
{
id: "section-4",
label: "Section 4",
},
{
id: "section-5",
label: "Section 5",
},
]
</script>
<template>
<div class="flex w-full grow gap-5">
<div class="flex w-[150px] flex-col gap-2">
<Scrollspy :offset="50" :target="parentRef" class="flex flex-col gap-2.5">
<Button
v-for="item in nav"
:key="item.id"
variant="outline"
:data-scrollspy-anchor="item.id"
class="data-[active=true]:bg-primary data-[active=true]:text-primary-foreground"
>
{{ item.label }}
</Button>
</Scrollspy>
</div>
<div class="grow" ref="parentRef">
<ScrollArea class="-me-5 h-[500px] grow pe-5">
<div class="space-y-8">
<div
v-for="item in nav"
:key="item.id"
:id="item.id"
class="space-y-2.5"
>
<h3 class="text-foreground text-base">{{ item.label }}</h3>
<div class="bg-muted rounded-2xl h-[350px]"></div>
</div>
</div>
</ScrollArea>
</div>
</div>
</template>
Установка
npx shadcn-vue@latest add https://revueui.rootapi.dev/r/c-scrollspy-1.jsonЗависимости реестра
Источник: порт из ReUI (Keenthemes, MIT)