Files
heroui-vue/apps/docs/demos/scroll-shadow-visibility-change.vue

99 lines
3.3 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import type { ScrollShadowVisibility } from "@heroui-vue/components";
import { ref } from "vue";
import {
Card,
CardDescription,
CardTitle,
ScrollShadow,
} from "@heroui-vue/components";
const images = [
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/robot1.jpeg",
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/avocado.jpeg",
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/oranges.jpeg",
];
const VISIBILITY_LABELS: Record<ScrollShadowVisibility, string> = {
auto: "自动",
both: "两侧",
bottom: "底部",
left: "左侧",
none: "无",
right: "右侧",
top: "顶部",
};
const verticalState = ref<ScrollShadowVisibility>("none");
function setVerticalState(value: ScrollShadowVisibility) {
verticalState.value = value;
}
const horizontalState = ref<ScrollShadowVisibility>("none");
function setHorizontalState(value: ScrollShadowVisibility) {
horizontalState.value = value;
}
const getRandomImage = (idx: number) => {
return images[idx % images.length];
};
</script>
<template>
<div class="w-full sm:max-w-sm">
<div class="mb-8 flex flex-col gap-2">
<div class="rounded bg-default p-4">
<p class="text-sm font-semibold">
垂直阴影状态:{{ VISIBILITY_LABELS[verticalState] }}
</p>
</div>
<div class="w-full">
<ScrollShadow
class="max-h-[240px] p-4"
orientation="vertical"
@visibility-change="(visibility) => setVerticalState(visibility)"
>
<div class="space-y-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<p>
段落 {{ idx + 1 }}:Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nullam pulvinar risus non risus hendrerit
venenatis. Pellentesque sit amet hendrerit risus, sed porttitor
quam. Morbi accumsan cursus enim, sed ultricies sapien.
</p>
</template>
</div>
</ScrollShadow>
</div>
</div>
<div class="flex flex-col gap-2">
<div class="rounded bg-default p-4">
<p class="text-sm font-semibold">
水平阴影状态:{{ VISIBILITY_LABELS[horizontalState] }}
</p>
</div>
<div class="w-full">
<ScrollShadow
class="p-4"
orientation="horizontal"
@visibility-change="(visibility) => setHorizontalState(visibility)"
>
<div class="flex flex-row gap-4">
<template :key="idx" v-for="(_, idx) in Array.from({ length: 10 })">
<Card
class="flex min-w-[200px] flex-row gap-3 p-1"
variant="transparent"
>
<img
alt="示例卡片"
class="aspect-square h-16 w-16 shrink-0 rounded-xl object-cover select-none sm:h-20 sm:w-20"
loading="lazy"
:src="getRandomImage(idx)"
/>
<div class="flex flex-1 flex-col justify-center gap-1">
<CardTitle class="text-sm">连接未来</CardTitle>
<CardDescription class="text-xs">今天 18:30</CardDescription>
</div>
</Card>
</template>
</div>
</ScrollShadow>
</div>
</div>
</div>
</template>