Skip to content

Commit

Permalink
feat(styles): support for always-on preview (#68)
Browse files Browse the repository at this point in the history
* feat: support for always-on preview

* 显示加载数量
  • Loading branch information
northword committed Jun 20, 2024
1 parent 7eb4bb5 commit 4cfe31e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 93 deletions.
1 change: 1 addition & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare module 'vue' {
ElRow: typeof import('element-plus/es')['ElRow']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSpace: typeof import('element-plus/es')['ElSpace']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
ElTag: typeof import('element-plus/es')['ElTag']
ElText: typeof import('element-plus/es')['ElText']
ElTimeline: typeof import('element-plus/es')['ElTimeline']
Expand Down
52 changes: 13 additions & 39 deletions src/styles/components/StyleListItem.vue
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
<script setup lang="ts">
const props = defineProps<{
style: Style;
mode?: "sample" | "full";
}>();
const style = props.style;
const mode = props.mode ?? "sample";
</script>

<template>
<template v-if="mode === 'sample'">
<client-only>
<el-popover trigger="hover" width="90%">
<template #reference>
{{ style.title }}
</template>
<div class="csl-preview">
<h3>引注</h3>
<div v-html="style.citations"></div>
<h3>参考文献表</h3>
<div v-html="style.bibliography"></div>
</div>
</el-popover>
</client-only>
</template>
<template v-else>
<h2>{{ style.title }}</h2>
<div class="csl-preview">
<h3>引注</h3>
<div v-html="style.citations" class="csl-preview-citations"></div>
<h3>参考文献表</h3>
<div v-html="style.bibliography" class="csl-preview-bibliography"></div>
</div>
</template>
<client-only>
<el-popover trigger="hover" width="90%">
<template #reference>
<a :href="style.dir">{{ style.title }}</a>
</template>
<div class="csl-preview">
<h3>引注</h3>
<div v-html="style.citations"></div>
<h3>参考文献表</h3>
<div v-html="style.bibliography"></div>
</div>
</el-popover>
</client-only>
</template>

<style>
.csl-preview {
/* font-family: Georgia, Times, "Times New Roman", serif; */
font-size: 1rem;
}
.csl-preview h3 {
font-weight: bold;
font-size: 1.5rem;
margin: 1rem 0;
}
</style>
18 changes: 18 additions & 0 deletions src/styles/components/StyleListItemPreview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script setup lang="ts">
const props = defineProps<{
style: Style;
}>();
const style = props.style;
</script>

<template>
<a :href="style.dir">
<h2>{{ style.title }}</h2>
</a>
<div class="csl-preview">
<h3>引注</h3>
<div v-html="style.citations" class="csl-preview-citations"></div>
<h3>参考文献表</h3>
<div v-html="style.bibliography" class="csl-preview-bibliography"></div>
</div>
</template>
75 changes: 21 additions & 54 deletions src/styles/components/StylesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { syncRef, useUrlSearchParams } from "@vueuse/core";
import Search from "@theme/components/Search.vue";
import TagsFilter from "@theme/components/TagsFilter.vue";
import StyleListItem from "./StyleListItem.vue";
import StyleListItemPreview from "./StyleListItemPreview.vue";
import { data as styles } from "../data/styles.data";
Expand Down Expand Up @@ -85,24 +86,33 @@ const filtered = computed(() => {
<Search v-model="searchText" placeholder="搜索样式名称..." />

<!-- 显示预览 -->
<!-- <el-switch v-model="showPreview" /> -->
<el-switch
v-model="showPreview"
size="large"
inline-prompt
active-text="始终显示预览"
inactive-text="仅在悬浮时显示预览"
/>
</div>

<!-- 标签筛选 -->
<TagsFilter v-model="selectedTags" :tags="allTags" />

<!-- 插件卡片列表 -->
<div class="styles-list">
<ul>
<div class="styles-list vp-doc">
<p>共加载 {{ filtered.length }} 条样式。</p>
<ul v-if="!showPreview">
<li v-for="style in filtered" :key="style.id">
<a :href="style.dir">
<StyleListItem
:style="style"
:mode="showPreview ? 'full' : 'sample'"
/>
</a>
<StyleListItem :style="style" />
</li>
</ul>
<div v-else>
<StyleListItemPreview
v-for="style in filtered"
:key="style.id"
:style="style"
/>
</div>
</div>

<!-- 空状态 -->
Expand All @@ -118,51 +128,8 @@ const filtered = computed(() => {
.toolbar > * {
margin: 0 8px;
}
.toolbar > :first-child {
margin-left: 0;
}
.toolbar > :last-child {
margin-right: 0;
}
.el-checkbox-group {
display: flex;
justify-content: center;
padding-bottom: 20px;
flex-wrap: wrap;
}
.el-checkbox {
margin: 0px 10px 10px 0px;
}
.el-checkbox > :deep(.el-checkbox__input) {
display: none !important;
}
.el-checkbox-button {
border: var(--el-border);
border-radius: var(--el-border-radius-base);
/* box-shadow: none!important; */
}
.el-checkbox-button__inner {
border: unset !important;
border-left-color: unset !important;
}
.el-col {
border-radius: 4px;
min-height: 36px;
padding-bottom: 20px;
}
.styles-list ul {
display: block;
list-style-type: disc;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
padding-inline-start: 40px;
unicode-bidi: isolate;
.styles-list {
padding: 0 10rem;
}
</style>

0 comments on commit 4cfe31e

Please sign in to comment.