Scroll Area
内容超出时换成自定义滚动条。底下是 Reka UI ScrollArea,原生滚动还在。
Installation
pnpm dlx @weme-ui/weme-ui add scroll-areaUsage
Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import ScrollArea from '../scroll-area.vue'
const items = [
'Apple',
'Banana',
'Blueberry',
'Cherry',
'Grape',
'Lemon',
'Mango',
'Orange',
'Peach',
'Pear',
'Pineapple',
'Strawberry',
'Watermelon',
]
</script>
<template>
<div class="flex items-center">
<ScrollArea class="h-48 w-48">
<div class="p-3 flex flex-col gap-2">
<p v-for="item in items" :key="item" class="text-sm">
{{ item }}
</p>
</div>
</ScrollArea>
</div>
</template>Examples
Orientation
Vueexamples/orientation.vueExpand codeHide code
<script lang="ts" setup>
import ScrollArea from '../scroll-area.vue'
const items = [
'Apple',
'Banana',
'Blueberry',
'Cherry',
'Grape',
'Lemon',
'Mango',
'Orange',
'Peach',
'Pear',
'Pineapple',
'Strawberry',
'Watermelon',
]
</script>
<template>
<div class="flex flex-wrap gap-3 items-center">
<ScrollArea orientation="vertical" class="h-48 w-40">
<div class="p-3 flex flex-col gap-2">
<p v-for="item in items" :key="item" class="text-sm">
{{ item }}
</p>
</div>
</ScrollArea>
<ScrollArea orientation="horizontal" class="w-64">
<div class="p-3 flex gap-3 w-max">
<p v-for="item in items" :key="item" class="text-sm whitespace-nowrap">
{{ item }}
</p>
</div>
</ScrollArea>
</div>
</template>Type
Vueexamples/type.vueExpand codeHide code
<script lang="ts" setup>
import ScrollArea from '../scroll-area.vue'
const types = ['hover', 'always', 'scroll', 'auto', 'glimpse'] as const
const items = [
'Apple',
'Banana',
'Blueberry',
'Cherry',
'Grape',
'Lemon',
'Mango',
'Orange',
'Peach',
'Pear',
'Pineapple',
'Strawberry',
'Watermelon',
]
</script>
<template>
<div class="flex flex-wrap gap-3 items-center">
<ScrollArea v-for="type in types" :key="type" :type="type" class="h-48 w-40">
<div class="p-3 flex flex-col gap-2">
<p v-for="item in items" :key="item" class="text-sm">
{{ item }}
</p>
</div>
</ScrollArea>
</div>
</template>Props
PropTypeDefault
asAsTag | Component'div'
渲染为的元素或组件(Reka UI
Primitive)AsTag | Component'div'
orientation'horizontal' | 'vertical'-
滚动条方向;未传时横向和纵向都渲染
'horizontal' | 'vertical'-
type'auto' | 'always' | 'scroll' | 'hover' | 'glimpse''hover'
滚动条何时可见:
auto 溢出时、always 始终、scroll 滚动时、hover 悬停或滚动、glimpse 进入时短暂显示'auto' | 'always' | 'scroll' | 'hover' | 'glimpse''hover'
scrollHideDelaynumber0
停止交互后隐藏滚动条的毫秒数。
type 不是 'scroll' 时未传按 0;'scroll' 且未传时走 Reka 的 600number0dir'ltr' | 'rtl'-
阅读方向;未传时继承
ConfigProvider,否则按 LTR'ltr' | 'rtl'-
classany-
根节点额外 class
any-uiPartial<ScrollAreaStyleSlots>-
覆盖 slots 样式(
root / viewport / scrollbar / thumb)Partial<ScrollAreaStyleSlots>-
Slots
SlotDescription
default滚动内容
滚动内容
CSS Variables
可在 *.style.ts 或 class 中使用,例如 bg-scrollbar-color。
CSS VariableValue
--scrollbar-colorneutral.3
neutral.3
--scrollbar-thumb-colorneutral.8
neutral.8
--scrollbar-thumb-hover-colorneutral.9
neutral.9
error.9 / success.7 等为语义色别名(色板阶),详见 Tokens。
Accessibility
基于 Reka UI ScrollArea(ScrollAreaRoot / ScrollAreaViewport)。保留浏览器原生滚动,键盘滚动也走原生,平台之间不完全一样。
Files
src/components/scroll-area/scroll-area.vuesrc/components/scroll-area/scroll-area.props.tssrc/components/scroll-area/scroll-area.style.ts