|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref } from 'vue' |
| 3 | +import { VPImage } from 'vitepress/theme' |
| 4 | +
|
| 5 | +interface Tab { |
| 6 | + name: string |
| 7 | + slot: string |
| 8 | + icon?: string |
| 9 | +} |
| 10 | +
|
| 11 | +const props = defineProps<{ |
| 12 | + tabs: Tab[] |
| 13 | +}>() |
| 14 | +
|
| 15 | +const activeIndex = ref(0) |
| 16 | +
|
| 17 | +// Icon alias to light/dark paths mapping |
| 18 | +const iconMap: Record<string, { light: string; dark: string }> = { |
| 19 | + 'testo-class': { |
| 20 | + light: '/icon/light-testo-class.svg', |
| 21 | + dark: '/icon/dark-testo-class.svg', |
| 22 | + }, |
| 23 | + 'testo-function': { |
| 24 | + light: '/icon/light-testo-function.svg', |
| 25 | + dark: '/icon/dark-testo-function.svg', |
| 26 | + }, |
| 27 | + 'testo-php': { |
| 28 | + light: '/icon/light-testo-php.svg', |
| 29 | + dark: '/icon/dark-testo-php.svg', |
| 30 | + }, |
| 31 | + 'testo': { |
| 32 | + light: '/icon/light-khinkali-bordered.svg', |
| 33 | + dark: '/icon/dark-khinkali-bordered.svg', |
| 34 | + }, |
| 35 | +} |
| 36 | +
|
| 37 | +const getIcon = (tab: Tab) => { |
| 38 | + const alias = tab.icon || 'testo' |
| 39 | + return iconMap[alias] |
| 40 | +} |
| 41 | +</script> |
| 42 | + |
| 43 | +<template> |
| 44 | + <div class="code-tabs-ide"> |
| 45 | + <!-- Tabs Bar --> |
| 46 | + <div class="ide-tabs"> |
| 47 | + <button |
| 48 | + v-for="(tab, index) in tabs" |
| 49 | + :key="index" |
| 50 | + class="ide-tab" |
| 51 | + :class="{ active: activeIndex === index }" |
| 52 | + @click="activeIndex = index" |
| 53 | + > |
| 54 | + <span class="tab-icon"> |
| 55 | + <VPImage :image="getIcon(tab)" /> |
| 56 | + </span> |
| 57 | + <span class="tab-name">{{ tab.name }}</span> |
| 58 | + </button> |
| 59 | + </div> |
| 60 | + |
| 61 | + <!-- Code Content via slots --> |
| 62 | + <div class="ide-content"> |
| 63 | + <template v-for="(tab, index) in tabs" :key="tab.slot"> |
| 64 | + <div v-show="activeIndex === index" class="code-slot"> |
| 65 | + <slot :name="tab.slot"></slot> |
| 66 | + </div> |
| 67 | + </template> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | +</template> |
| 71 | + |
| 72 | +<style scoped> |
| 73 | +.code-tabs-ide { |
| 74 | + border-radius: 12px; |
| 75 | + overflow: hidden; |
| 76 | + background: var(--vp-code-block-bg); |
| 77 | + box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15); |
| 78 | + margin: 24px 0; |
| 79 | +} |
| 80 | +
|
| 81 | +/* Tabs */ |
| 82 | +.ide-tabs { |
| 83 | + display: flex; |
| 84 | + background: #252526; |
| 85 | + border-bottom: 1px solid rgba(255,255,255,0.1); |
| 86 | + overflow-x: auto; |
| 87 | + border-radius: 12px 12px 0 0; |
| 88 | + scrollbar-width: none; /* Firefox */ |
| 89 | + -ms-overflow-style: none; /* IE/Edge */ |
| 90 | +} |
| 91 | +
|
| 92 | +.ide-tabs::-webkit-scrollbar { |
| 93 | + display: none; /* Chrome/Safari */ |
| 94 | +} |
| 95 | +
|
| 96 | +.dark .ide-tabs { |
| 97 | + background: #1e1e1e; |
| 98 | +} |
| 99 | +
|
| 100 | +.ide-tab:first-child { |
| 101 | + border-radius: 12px 0 0 0; |
| 102 | +} |
| 103 | +
|
| 104 | +.ide-tab { |
| 105 | + display: flex; |
| 106 | + align-items: center; |
| 107 | + gap: 8px; |
| 108 | + padding: 10px 16px; |
| 109 | + background: transparent; |
| 110 | + border: none; |
| 111 | + border-right: 1px solid rgba(255,255,255,0.05); |
| 112 | + color: #888; |
| 113 | + font-size: 13px; |
| 114 | + font-family: var(--vp-font-family-base); |
| 115 | + cursor: pointer; |
| 116 | + transition: all 0.2s ease; |
| 117 | + white-space: nowrap; |
| 118 | +} |
| 119 | +
|
| 120 | +.ide-tab:hover { |
| 121 | + background: rgba(255,255,255,0.05); |
| 122 | + color: #ccc; |
| 123 | +} |
| 124 | +
|
| 125 | +.ide-tab.active { |
| 126 | + background: var(--vp-code-block-bg); |
| 127 | + color: #fff; |
| 128 | + border-bottom: 2px solid var(--vp-c-brand-1); |
| 129 | + margin-bottom: -1px; |
| 130 | +} |
| 131 | +
|
| 132 | +.tab-icon { |
| 133 | + width: 16px; |
| 134 | + height: 16px; |
| 135 | + flex-shrink: 0; |
| 136 | + display: flex; |
| 137 | + align-items: center; |
| 138 | + justify-content: center; |
| 139 | +} |
| 140 | +
|
| 141 | +.tab-icon :deep(img) { |
| 142 | + width: 16px; |
| 143 | + height: 16px; |
| 144 | + max-width: 16px; |
| 145 | + max-height: 16px; |
| 146 | + object-fit: contain; |
| 147 | +} |
| 148 | +
|
| 149 | +/* Content - reset VitePress code block styles */ |
| 150 | +.ide-content { |
| 151 | + position: relative; |
| 152 | +} |
| 153 | +
|
| 154 | +.code-slot { |
| 155 | + width: 100%; |
| 156 | +} |
| 157 | +
|
| 158 | +/* Override VitePress code block styles inside our component */ |
| 159 | +.code-slot :deep(div[class*="language-"]) { |
| 160 | + margin: 0 !important; |
| 161 | + border-radius: 0 !important; |
| 162 | + box-shadow: none !important; |
| 163 | +} |
| 164 | +
|
| 165 | +.code-slot :deep(.vp-code-group) { |
| 166 | + margin: 0 !important; |
| 167 | + border-radius: 0 !important; |
| 168 | +} |
| 169 | +
|
| 170 | +.code-slot :deep(div[class*="language-"]:hover) { |
| 171 | + transform: none !important; |
| 172 | + box-shadow: none !important; |
| 173 | +} |
| 174 | +
|
| 175 | +/* Hide the language label */ |
| 176 | +.code-slot :deep(span.lang) { |
| 177 | + display: none; |
| 178 | +} |
| 179 | +
|
| 180 | +/* Hide copy button or style it */ |
| 181 | +.code-slot :deep(button.copy) { |
| 182 | + top: 8px; |
| 183 | + right: 8px; |
| 184 | +} |
| 185 | +
|
| 186 | +/* Responsive */ |
| 187 | +@media (max-width: 640px) { |
| 188 | + .ide-tab { |
| 189 | + padding: 8px 12px; |
| 190 | + font-size: 12px; |
| 191 | + } |
| 192 | +} |
| 193 | +</style> |
0 commit comments