docs/.vitepress/theme/components/Badge.vue

8074d87a6cd8b91868151bd1fdc05f98cd54eb32
wotaku/docs/.vitepress/theme/components/Badge.vue

93 lines · 2045 bytes

 1<!--
 2  All Rights Reserved
 3
 4  Copyright (c) 2025 taskylizard
 5
 6  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
 7-->
 8<script setup lang="ts">
 9interface Props {
10  text?: string
11  link?: string
12  type?: 'info' | 'tip' | 'warning' | 'danger' | 'green'
13  icon?: string
14}
15withDefaults(defineProps<Props>(), {
16  type: 'info'
17})
18</script>
19
20<template>
21  <component :target="link ? '_blank' : undefined" :is="link ? 'a' : 'span'" class="VPBadge"
22    :class="link ? 'tip' : type" :href="link">
23    <div v-if="icon" :class="icon" />
24    <slot>{{ text }}</slot>
25  </component>
26</template>
27
28<style scoped>
29.VPBadge {
30  display: inline-flex;
31  margin-left: 2px;
32  border: 1px solid transparent;
33  border-radius: 12px;
34  padding: 0 10px;
35  line-height: 22px;
36  font-size: 12px;
37  font-weight: 500;
38  transform: translateY(-2px);
39  align-items: center;
40  gap: 0.2rem;
41  padding-right: 10px;
42  vertical-align: middle;
43  /** If the badge is a link, we don't want to apply the link style from global styles. */
44  text-decoration: none !important;
45}
46
47.vp-doc h1>.VPBadge {
48  margin-top: 4px;
49  vertical-align: top;
50}
51
52.vp-doc h2>.VPBadge {
53  margin-top: 3px;
54  padding: 0 8px;
55  vertical-align: top;
56}
57
58.vp-doc h3>.VPBadge {
59  vertical-align: middle;
60}
61
62.vp-doc h4>.VPBadge,
63.vp-doc h5>.VPBadge,
64.vp-doc h6>.VPBadge {
65  vertical-align: middle;
66  line-height: 18px;
67}
68
69.VPBadge.info {
70  color: var(--vp-badge-info-text);
71  background-color: var(--vp-badge-info-bg);
72}
73
74.VPBadge.tip {
75  color: var(--vp-badge-tip-text);
76  background-color: var(--vp-badge-tip-bg);
77}
78
79.VPBadge.warning {
80  color: var(--vp-badge-warning-text);
81  background-color: var(--vp-badge-warning-bg);
82}
83
84.VPBadge.danger {
85  color: var(--vp-badge-danger-text);
86  background-color: var(--vp-badge-danger-bg);
87}
88
89.VPBadge.green {
90  color: var(--vp-custom-block-tip-text);
91  background-color: var(--vp-custom-block-tip-bg);
92}
93</style>