|
| 1 | +<script setup> |
| 2 | +import { ShikiMagicMove } from 'shiki-magic-move/vue' |
| 3 | +import 'shiki-magic-move/dist/style.css' |
| 4 | +import { createHighlighter } from 'shiki' |
| 5 | +import { ref, onMounted } from 'vue' |
| 6 | +
|
| 7 | +const props = defineProps({ |
| 8 | + steps: { type: Array, required: true }, |
| 9 | + lang: { type: String, default: 'r' }, |
| 10 | + theme: { type: String, default: 'github-light' } |
| 11 | +}) |
| 12 | +
|
| 13 | +const currentStep = ref(0) |
| 14 | +const highlighter = ref(null) |
| 15 | +const ready = ref(false) |
| 16 | +
|
| 17 | +onMounted(async () => { |
| 18 | + highlighter.value = await createHighlighter({ |
| 19 | + themes: [props.theme], |
| 20 | + langs: [props.lang] |
| 21 | + }) |
| 22 | + ready.value = true |
| 23 | +}) |
| 24 | +
|
| 25 | +function prev() { |
| 26 | + if (currentStep.value > 0) currentStep.value-- |
| 27 | +} |
| 28 | +function next() { |
| 29 | + if (currentStep.value < props.steps.length - 1) currentStep.value++ |
| 30 | +} |
| 31 | +</script> |
| 32 | + |
| 33 | +<template> |
| 34 | + <div class="code-stepper" v-if="ready"> |
| 35 | + <div class="code-stepper-header"> |
| 36 | + <span class="code-stepper-title"> |
| 37 | + <strong>{{ steps[currentStep].label }}</strong> |
| 38 | + </span> |
| 39 | + <div class="code-stepper-controls"> |
| 40 | + <button @click="prev" :disabled="currentStep === 0">← Prev</button> |
| 41 | + <span class="code-stepper-indicator">Step {{ currentStep + 1 }} / {{ steps.length }}</span> |
| 42 | + <button @click="next" :disabled="currentStep === steps.length - 1">Next →</button> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + <div class="code-stepper-body"> |
| 46 | + <ShikiMagicMove |
| 47 | + :highlighter="highlighter" |
| 48 | + :code="steps[currentStep].code" |
| 49 | + :lang="lang" |
| 50 | + :theme="theme" |
| 51 | + :options="{ duration: 500, stagger: 2 }" |
| 52 | + /> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + <div v-else class="code-stepper-loading">Loading code animation...</div> |
| 56 | +</template> |
| 57 | + |
| 58 | +<style scoped> |
| 59 | +.code-stepper { |
| 60 | + border: 1px solid var(--vp-c-divider); |
| 61 | + border-radius: 8px; |
| 62 | + overflow: hidden; |
| 63 | + margin: 16px 0; |
| 64 | +} |
| 65 | +
|
| 66 | +.code-stepper-header { |
| 67 | + display: flex; |
| 68 | + align-items: center; |
| 69 | + justify-content: space-between; |
| 70 | + padding: 8px 16px; |
| 71 | + background: var(--vp-c-bg-soft); |
| 72 | + border-bottom: 1px solid var(--vp-c-divider); |
| 73 | + font-size: 0.85rem; |
| 74 | +} |
| 75 | +
|
| 76 | +.code-stepper-controls { |
| 77 | + display: flex; |
| 78 | + align-items: center; |
| 79 | + gap: 8px; |
| 80 | +} |
| 81 | +
|
| 82 | +.code-stepper-controls button { |
| 83 | + padding: 4px 12px; |
| 84 | + border: 1px solid var(--vp-c-divider); |
| 85 | + border-radius: 4px; |
| 86 | + background: var(--vp-c-bg); |
| 87 | + cursor: pointer; |
| 88 | + font-size: 0.8rem; |
| 89 | + transition: background 0.2s, border-color 0.2s; |
| 90 | +} |
| 91 | +
|
| 92 | +.code-stepper-controls button:hover:not(:disabled) { |
| 93 | + background: var(--vp-c-bg-soft); |
| 94 | + border-color: var(--vp-c-brand); |
| 95 | +} |
| 96 | +
|
| 97 | +.code-stepper-controls button:disabled { |
| 98 | + opacity: 0.4; |
| 99 | + cursor: default; |
| 100 | +} |
| 101 | +
|
| 102 | +.code-stepper-indicator { |
| 103 | + font-weight: 600; |
| 104 | + font-variant-numeric: tabular-nums; |
| 105 | + color: var(--vp-c-text-2); |
| 106 | +} |
| 107 | +
|
| 108 | +.code-stepper-body { |
| 109 | + padding: 16px 20px; |
| 110 | + overflow-x: auto; |
| 111 | + font-size: 0.875rem; |
| 112 | + line-height: 1.6; |
| 113 | +} |
| 114 | +
|
| 115 | +.code-stepper-loading { |
| 116 | + padding: 24px; |
| 117 | + text-align: center; |
| 118 | + color: var(--vp-c-text-3); |
| 119 | + font-size: 0.85rem; |
| 120 | +} |
| 121 | +</style> |
0 commit comments