63 lines
2.0 KiB
Vue
63 lines
2.0 KiB
Vue
<script setup lang="ts">
|
|
import { computed, ref } from "vue";
|
|
import { Card, Link } from "@heroui-vue/components";
|
|
import { withBase } from "vitepress";
|
|
import { searchIndex } from "virtual:docs-data";
|
|
import { componentItems } from "./navigation";
|
|
const props = defineProps<{ category: string }>();
|
|
const items = computed(() =>
|
|
componentItems.filter((item) => item.category === props.category),
|
|
);
|
|
const failed = ref(new Set<string>());
|
|
function imageName(title: string) {
|
|
return title.split(" ")[0].toLowerCase();
|
|
}
|
|
function thumbnail(title: string, theme: "light" | "dark") {
|
|
return `https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/related-components/${theme}-${imageName(title)}.png`;
|
|
}
|
|
function description(url: string) {
|
|
return (
|
|
searchIndex.find((entry) => entry.url === url && entry.section === "概览")
|
|
?.text ?? "查看组件用法与 API"
|
|
);
|
|
}
|
|
</script>
|
|
<template>
|
|
<div class="components-grid not-prose">
|
|
<Card
|
|
v-for="item in items"
|
|
:key="item.url"
|
|
class="component-index-card"
|
|
variant="transparent"
|
|
>
|
|
<div class="component-index-preview" aria-hidden="true">
|
|
<template v-for="theme in ['light', 'dark'] as const" :key="theme">
|
|
<img
|
|
v-if="!failed.has(theme + item.url)"
|
|
:class="'component-thumbnail-' + theme"
|
|
:src="thumbnail(item.title, theme)"
|
|
alt=""
|
|
loading="lazy"
|
|
decoding="async"
|
|
width="874"
|
|
height="594"
|
|
@error="failed.add(theme + item.url)"
|
|
/>
|
|
<div
|
|
v-else
|
|
:class="
|
|
'component-thumbnail-' + theme + ' component-thumbnail-fallback'
|
|
"
|
|
>
|
|
<strong>{{ item.title.split(" ")[0] }}</strong>
|
|
<span>{{ description(item.url) }}</span>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
<Link :href="withBase(item.url)" class="component-index-title">
|
|
{{ item.title }}
|
|
</Link>
|
|
</Card>
|
|
</div>
|
|
</template>
|