|
| 1 | +<script lang="ts" setup> |
| 2 | +import { onMounted, ref } from 'vue' |
| 3 | +import StarIcon from './StarIcon.vue' |
| 4 | +
|
| 5 | +const props = defineProps<{ |
| 6 | + owner: string |
| 7 | + repo: string |
| 8 | +}>() |
| 9 | +
|
| 10 | +const count = ref(0) |
| 11 | +
|
| 12 | +async function fetchCount() { |
| 13 | + const res = await fetch(`https://api.github.com/repos/${props.owner}/${props.repo}`) |
| 14 | + const resJson = await res.json() |
| 15 | + count.value = resJson.stargazers_count ?? 0 |
| 16 | +} |
| 17 | +onMounted(fetchCount) |
| 18 | +</script> |
| 19 | + |
| 20 | +<template> |
| 21 | + <div class="Wrapper"> |
| 22 | + <a |
| 23 | + title="Github" |
| 24 | + class="Button" |
| 25 | + :href="`https://github.com/${owner}/${repo}`" |
| 26 | + target="_blank" |
| 27 | + rel="noreferrer noopener" |
| 28 | + > |
| 29 | + <StarIcon /> |
| 30 | + Star |
| 31 | + </a> |
| 32 | + <a |
| 33 | + class="Count" |
| 34 | + :href="`https://github.com/${owner}/${repo}/stargazers`" |
| 35 | + aria-label="{label}" |
| 36 | + target="_blank" |
| 37 | + rel="noreferrer noopener" |
| 38 | + > |
| 39 | + {{ new Intl.NumberFormat().format(count) }} |
| 40 | + </a> |
| 41 | + </div> |
| 42 | +</template> |
| 43 | + |
| 44 | +<style scoped> |
| 45 | +.Wrapper { |
| 46 | + margin-left: 14px; |
| 47 | + display: block; |
| 48 | +} |
| 49 | +
|
| 50 | +@media only screen and (max-width: 800px) { |
| 51 | + .Wrapper { |
| 52 | + display: none; |
| 53 | + } |
| 54 | +} |
| 55 | +
|
| 56 | +.Button { |
| 57 | + display: flex; |
| 58 | + align-items: center; |
| 59 | + gap: 5px; |
| 60 | +
|
| 61 | + padding: 3px 10px; |
| 62 | + border-radius: 8px; |
| 63 | + border-bottom-right-radius: 0; |
| 64 | + border-top-right-radius: 0; |
| 65 | + float: left; |
| 66 | + cursor: pointer; |
| 67 | + position: relative; |
| 68 | + user-select: none; |
| 69 | + vertical-align: middle; |
| 70 | + white-space: nowrap; |
| 71 | + text-decoration: none; |
| 72 | +
|
| 73 | + font-size: 13px; |
| 74 | + font-weight: 600; |
| 75 | + line-height: 20px; |
| 76 | +
|
| 77 | + background-color: #FAFBFC; |
| 78 | + border: 1px solid rgba(27, 31, 35, 0.2); |
| 79 | + border-right: 0px; |
| 80 | + color: inherit; |
| 81 | +} |
| 82 | +
|
| 83 | +.Count { |
| 84 | + border-bottom-right-radius: 8px; |
| 85 | + border-left: 0; |
| 86 | + border-top-right-radius: 8px; |
| 87 | + float: left; |
| 88 | + padding: 3px 10px; |
| 89 | + vertical-align: middle; |
| 90 | +
|
| 91 | + font-size: 13px; |
| 92 | + font-weight: 600; |
| 93 | + line-height: 20px; |
| 94 | + text-decoration: none; |
| 95 | +
|
| 96 | + background-color: #fff; |
| 97 | + border: 1px solid rgba(27, 31, 35, 0.2); |
| 98 | +} |
| 99 | +
|
| 100 | +.dark .Button { |
| 101 | + border: 1px solid #4d4d4f; |
| 102 | + background-color: #4d4d4f; |
| 103 | +} |
| 104 | +
|
| 105 | +.dark .Count { |
| 106 | + background-color: #65666A; |
| 107 | +} |
| 108 | +</style> |
0 commit comments