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

ba6dbe9cc5270e79b489d8570ac06e70bc10df21
wotaku/docs/.vitepress/theme/components/Badge.vue history · blame · raw

98 lines · 2076 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
22    :target="link ? '_blank' : undefined"
23    :is="link ? 'a' : 'span'"
24    class="VPBadge"
25    :class="link ? 'tip' : type"
26    :href="link"
27  >
28    <div v-if="icon" :class="icon" />
29    <slot>{{ text }}</slot>
30  </component>
31</template>
32
33<style scoped>
34.VPBadge {
35  display: inline-flex;
36  margin-left: 2px;
37  border: 1px solid transparent;
38  border-radius: 12px;
39  padding: 0 10px;
40  line-height: 22px;
41  font-size: 12px;
42  font-weight: 500;
43  transform: translateY(-2px);
44  align-items: center;
45  gap: 0.2rem;
46  padding-right: 10px;
47  vertical-align: middle;
48  /** If the badge is a link, we don't want to apply the link style from global styles. */
49  text-decoration: none !important;
50}
51
52.vp-doc h1 > .VPBadge {
53  margin-top: 4px;
54  vertical-align: top;
55}
56
57.vp-doc h2 > .VPBadge {
58  margin-top: 3px;
59  padding: 0 8px;
60  vertical-align: top;
61}
62
63.vp-doc h3 > .VPBadge {
64  vertical-align: middle;
65}
66
67.vp-doc h4 > .VPBadge,
68.vp-doc h5 > .VPBadge,
69.vp-doc h6 > .VPBadge {
70  vertical-align: middle;
71  line-height: 18px;
72}
73
74.VPBadge.info {
75  color: var(--vp-badge-info-text);
76  background-color: var(--vp-badge-info-bg);
77}
78
79.VPBadge.tip {
80  color: var(--vp-badge-tip-text);
81  background-color: var(--vp-badge-tip-bg);
82}
83
84.VPBadge.warning {
85  color: var(--vp-badge-warning-text);
86  background-color: var(--vp-badge-warning-bg);
87}
88
89.VPBadge.danger {
90  color: var(--vp-badge-danger-text);
91  background-color: var(--vp-badge-danger-bg);
92}
93
94.VPBadge.green {
95  color: var(--vp-custom-block-tip-text);
96  background-color: var(--vp-custom-block-tip-bg);
97}
98</style>