docs/.vitepress/theme/components/link-card/Card.vue

ba4f23d3bab9e2bb3b8efdb22317c8cc8f353ec5
wotaku/docs/.vitepress/theme/components/link-card/Card.vue history · blame · raw

167 lines · 3279 bytes

  1<script setup lang="ts">
  2import { computed, inject, ref } from 'vue'
  3import { DECK_MINI_KEY } from './deck'
  4import { renderCardIcon } from './iconMarkup'
  5
  6const props = withDefaults(
  7  defineProps<{
  8    href: string
  9    title: string
 10    icon?: string
 11    download?: boolean
 12    mini?: boolean
 13  }>(),
 14  {
 15    mini: undefined
 16  }
 17)
 18
 19const deckMini = inject(DECK_MINI_KEY, ref(false))
 20const isMini = computed(() => props.mini ?? deckMini.value)
 21
 22const isImageIcon = computed(() => {
 23  const icon = props.icon
 24  if (!icon) return false
 25  return icon.startsWith('/') || icon.startsWith('http') ||
 26    icon.startsWith('data:')
 27})
 28</script>
 29
 30<template>
 31  <a
 32    role="article"
 33    :href="props.href"
 34    :download="props.download ? '' : undefined"
 35    class="vp-card"
 36    :class="{ 'vp-card--mini': isMini }"
 37  >
 38    <article
 39      class="vp-card-container"
 40      :class="{
 41        'vp-card-container--no-details': !$slots.default,
 42        'vp-card-container--mini': isMini
 43      }"
 44    >
 45      <div
 46        v-if="props.icon"
 47        class="vp-card-icon"
 48      >
 49        <img
 50          v-if="isImageIcon"
 51          class="vp-card-icon-img no-zoom"
 52          :src="props.icon"
 53          alt=""
 54          loading="lazy"
 55          decoding="async"
 56        />
 57        <span v-else v-html="renderCardIcon(props.icon)" />
 58      </div>
 59      <h3 class="vp-card-title">{{ props.title }}</h3>
 60      <p v-if="$slots.default" class="vp-card-details"><slot /></p>
 61    </article>
 62  </a>
 63</template>
 64
 65<style scoped>
 66.vp-card,
 67.vp-card:hover,
 68.vp-card:focus,
 69.vp-card:visited {
 70  display: block;
 71  border: 2px solid #3d3d3d;
 72  border-radius: var(--radius-xl);
 73  height: 100%;
 74  background-color: var(--vp-c-bg-soft);
 75  transition: border-color 0.25s, background-color 0.25s;
 76  text-decoration: none !important;
 77  color: inherit !important;
 78}
 79
 80.vp-card:hover {
 81  border-color: var(--vp-c-brand-1, #1473e6);
 82}
 83
 84.vp-card-container {
 85  display: flex;
 86  flex-direction: column;
 87  padding: 24px;
 88  height: 100%;
 89}
 90
 91.vp-card-container--no-details {
 92  justify-content: center;
 93}
 94
 95.vp-card-container--no-details .vp-card-title {
 96  margin-bottom: 0;
 97}
 98
 99.vp-card-icon {
100  display: flex;
101  justify-content: center;
102  align-items: center;
103  margin-bottom: 12px;
104  border-radius: 6px;
105  overflow: hidden;
106  background-color: var(--vp-c-default-soft);
107  width: 40px;
108  height: 40px;
109  font-size: 22px;
110  transition: background-color 0.25s;
111}
112
113.vp-card-icon-img {
114  display: block;
115  width: 100%;
116  height: 100%;
117  object-fit: contain;
118}
119
120.vp-card-title {
121  margin: 0 0 8px;
122  padding: 0;
123  line-height: 24px;
124  font-size: 16px;
125  font-weight: 600;
126  color: var(--vp-c-text-1);
127  border: none;
128  letter-spacing: 0;
129}
130
131.vp-card-details {
132  margin: 0;
133  line-height: 24px;
134  font-size: 14px;
135  font-weight: 500;
136  color: var(--vp-c-text-2);
137}
138
139.vp-card-container--mini {
140  flex-direction: row;
141  align-items: center;
142  gap: 12px;
143  padding: 12px 16px;
144}
145
146.vp-card-container--mini.vp-card-container--no-details {
147  justify-content: flex-start;
148}
149
150.vp-card--mini .vp-card-icon {
151  width: 32px;
152  height: 32px;
153  margin-bottom: 0;
154  font-size: 18px;
155  flex-shrink: 0;
156}
157
158.vp-card--mini .vp-card-title {
159  margin: 0;
160  font-size: 14px;
161  line-height: 1.3;
162}
163
164.vp-card--mini .vp-card-details {
165  display: none;
166}
167</style>