docs/.vitepress/theme/components/Badge.vue
106 lines · 2376 bytes
1<!--
2 Copyright (c) 2024 taskylizard
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15-->
16<script setup lang="ts">
17interface Props {
18 text?: string
19 link?: string
20 type?: 'info' | 'tip' | 'warning' | 'danger' | 'green'
21 icon?: string
22}
23withDefaults(defineProps<Props>(), {
24 type: 'info'
25})
26</script>
27
28<template>
29 <component
30 :target="link ? '_blank' : undefined"
31 :is="link ? 'a' : 'span'"
32 class="VPBadge"
33 :class="link ? 'tip' : type"
34 :href="link"
35 >
36 <div v-if="icon" :class="icon" />
37 <slot>{{ text }}</slot>
38 </component>
39</template>
40
41<style scoped>
42.VPBadge {
43 display: inline-flex;
44 margin-left: 2px;
45 border: 1px solid transparent;
46 border-radius: 12px;
47 padding: 0 10px;
48 line-height: 22px;
49 font-size: 12px;
50 font-weight: 500;
51 transform: translateY(-2px);
52 align-items: center;
53 gap: 0.2rem;
54 padding-right: 10px;
55 vertical-align: middle;
56 /** If the badge is a link, we don't want to apply the link style from global styles. */
57 text-decoration: none !important;
58}
59
60.vp-doc h1 > .VPBadge {
61 margin-top: 4px;
62 vertical-align: top;
63}
64
65.vp-doc h2 > .VPBadge {
66 margin-top: 3px;
67 padding: 0 8px;
68 vertical-align: top;
69}
70
71.vp-doc h3 > .VPBadge {
72 vertical-align: middle;
73}
74
75.vp-doc h4 > .VPBadge,
76.vp-doc h5 > .VPBadge,
77.vp-doc h6 > .VPBadge {
78 vertical-align: middle;
79 line-height: 18px;
80}
81
82.VPBadge.info {
83 color: var(--vp-badge-info-text);
84 background-color: var(--vp-badge-info-bg);
85}
86
87.VPBadge.tip {
88 color: var(--vp-badge-tip-text);
89 background-color: var(--vp-badge-tip-bg);
90}
91
92.VPBadge.warning {
93 color: var(--vp-badge-warning-text);
94 background-color: var(--vp-badge-warning-bg);
95}
96
97.VPBadge.danger {
98 color: var(--vp-badge-danger-text);
99 background-color: var(--vp-badge-danger-bg);
100}
101
102.VPBadge.green {
103 color: var(--vp-custom-block-tip-text);
104 background-color: var(--vp-custom-block-tip-bg);
105}
106</style>