|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed } from "vue"; |
| 3 | +import { EXTERNAL_URL_RE, normalizeLink } from "../../helper/vite-util"; |
| 4 | +
|
| 5 | +interface Props { |
| 6 | + tag?: string; |
| 7 | + size?: "medium" | "big"; |
| 8 | + theme?: "brand" | "alt" | "sponsor"; |
| 9 | + text: string; |
| 10 | + href?: string; |
| 11 | + target?: string; |
| 12 | + rel?: string; |
| 13 | +} |
| 14 | +const props = withDefaults(defineProps<Props>(), { |
| 15 | + size: "medium", |
| 16 | + theme: "brand", |
| 17 | +}); |
| 18 | +
|
| 19 | +const isExternal = computed(() => props.href && EXTERNAL_URL_RE.test(props.href)); |
| 20 | +
|
| 21 | +const component = computed(() => { |
| 22 | + return props.tag || (props.href ? "a" : "button"); |
| 23 | +}); |
| 24 | +</script> |
| 25 | + |
| 26 | +<template> |
| 27 | + <component |
| 28 | + :is="component" |
| 29 | + class="VPButton" |
| 30 | + :class="[size, theme]" |
| 31 | + :href="href ? normalizeLink(href) : undefined" |
| 32 | + :target="props.target ?? (isExternal ? '_blank' : undefined)" |
| 33 | + :rel="props.rel ?? (isExternal ? 'noreferrer' : undefined)" |
| 34 | + > |
| 35 | + {{ text }} |
| 36 | + </component> |
| 37 | +</template> |
| 38 | + |
| 39 | +<style scoped> |
| 40 | +.VPButton { |
| 41 | + text-decoration: none; |
| 42 | + display: inline-block; |
| 43 | + border: 1px solid transparent; |
| 44 | + text-align: center; |
| 45 | + font-weight: 600; |
| 46 | + white-space: nowrap; |
| 47 | + transition: color 0.25s, border-color 0.25s, background-color 0.25s; |
| 48 | +} |
| 49 | +
|
| 50 | +.VPButton:active { |
| 51 | + transition: color 0.1s, border-color 0.1s, background-color 0.1s; |
| 52 | +} |
| 53 | +
|
| 54 | +.VPButton.medium { |
| 55 | + border-radius: 20px; |
| 56 | + padding: 0 20px; |
| 57 | + line-height: 38px; |
| 58 | + font-size: 14px; |
| 59 | +} |
| 60 | +
|
| 61 | +.VPButton.big { |
| 62 | + border-radius: 24px; |
| 63 | + padding: 0 24px; |
| 64 | + line-height: 46px; |
| 65 | + font-size: 16px; |
| 66 | +} |
| 67 | +
|
| 68 | +.VPButton.brand { |
| 69 | + border-color: var(--vp-button-brand-border); |
| 70 | + color: var(--vp-button-brand-text); |
| 71 | + background-color: var(--vp-button-brand-bg); |
| 72 | +} |
| 73 | +
|
| 74 | +.VPButton.brand:hover { |
| 75 | + border-color: var(--vp-button-brand-hover-border); |
| 76 | + color: var(--vp-button-brand-hover-text); |
| 77 | + background-color: var(--vp-button-brand-hover-bg); |
| 78 | +} |
| 79 | +
|
| 80 | +.VPButton.brand:active { |
| 81 | + border-color: var(--vp-button-brand-active-border); |
| 82 | + color: var(--vp-button-brand-active-text); |
| 83 | + background-color: var(--vp-button-brand-active-bg); |
| 84 | +} |
| 85 | +
|
| 86 | +.VPButton.alt { |
| 87 | + border-color: var(--vp-button-alt-border); |
| 88 | + color: var(--vp-button-alt-text); |
| 89 | + background-color: var(--vp-button-alt-bg); |
| 90 | +} |
| 91 | +
|
| 92 | +.VPButton.alt:hover { |
| 93 | + border-color: var(--vp-button-alt-hover-border); |
| 94 | + color: var(--vp-button-alt-hover-text); |
| 95 | + background-color: var(--vp-button-alt-hover-bg); |
| 96 | +} |
| 97 | +
|
| 98 | +.VPButton.alt:active { |
| 99 | + border-color: var(--vp-button-alt-active-border); |
| 100 | + color: var(--vp-button-alt-active-text); |
| 101 | + background-color: var(--vp-button-alt-active-bg); |
| 102 | +} |
| 103 | +
|
| 104 | +.VPButton.sponsor { |
| 105 | + border-color: var(--vp-button-sponsor-border); |
| 106 | + color: var(--vp-button-sponsor-text); |
| 107 | + background-color: var(--vp-button-sponsor-bg); |
| 108 | +} |
| 109 | +
|
| 110 | +.VPButton.sponsor:hover { |
| 111 | + border-color: var(--vp-button-sponsor-hover-border); |
| 112 | + color: var(--vp-button-sponsor-hover-text); |
| 113 | + background-color: var(--vp-button-sponsor-hover-bg); |
| 114 | +} |
| 115 | +
|
| 116 | +.VPButton.sponsor:active { |
| 117 | + border-color: var(--vp-button-sponsor-active-border); |
| 118 | + color: var(--vp-button-sponsor-active-text); |
| 119 | + background-color: var(--vp-button-sponsor-active-bg); |
| 120 | +} |
| 121 | +</style> |
0 commit comments