Skip to content

Commit db0e5c8

Browse files
committed
improve tutorial layout
1 parent 2332c65 commit db0e5c8

File tree

9 files changed

+130
-68
lines changed

9 files changed

+130
-68
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"serve": "vitepress serve src"
66
},
77
"dependencies": {
8-
"@vue/repl": "^0.4.8",
8+
"@vue/repl": "^0.4.9",
99
"@vue/theme": "^0.1.35",
1010
"dynamics.js": "^1.1.5",
1111
"gsap": "^3.9.0",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.vitepress/config.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,6 @@ export const sidebar = {
468468
}
469469
]
470470
}
471-
],
472-
'/tutorial/': [
473-
{
474-
text: 'Tutorial',
475-
items: [
476-
{
477-
text: '1. Adding Data',
478-
link: '/tutorial/#step-1'
479-
},
480-
{
481-
text: '2. Two-way Binding',
482-
link: '/tutorial/#step-2'
483-
}
484-
]
485-
}
486471
]
487472
}
488473

src/.vitepress/theme/components/PreferenceSwitch.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ function useToggleFn(
116116
.preference-switch {
117117
font-size: 12px;
118118
border-bottom: 1px solid var(--vt-c-divider-light);
119-
transition: border-color 0.5s;
119+
transition: border-color 0.5s, background-color .5s ease;
120120
margin-bottom: 20px;
121121
position: sticky;
122122
top: -0.5px;
123123
background-color: var(--vt-c-bg);
124124
padding-top: 10px;
125+
z-index: 10;
125126
}
126127
127128
.toggle {
@@ -243,7 +244,7 @@ function useToggleFn(
243244
.tip .options-api,
244245
.tip .composition-api {
245246
color: var(--vt-c-text-code);
246-
transition: color 0.5s;
247+
/* transition: color 0.5s; */
247248
font-weight: 600;
248249
}
249250
</style>

src/tutorial/TutorialRepl.vue

Lines changed: 100 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
onHashChange
99
} from '../examples/utils'
1010
import '@vue/repl/style.css'
11+
import PreferenceSwitch from '../.vitepress/theme/components/PreferenceSwitch.vue'
12+
import { VTFlyout, VTIconChevronLeft, VTIconChevronRight } from '@vue/theme'
1113
1214
const store = new ReplStore({
1315
defaultVueRuntimeURL: `https://unpkg.com/vue@${version}/dist/vue.esm-browser.js`
@@ -17,14 +19,37 @@ const preferComposition = inject('prefer-composition') as Ref<boolean>
1719
const preferSFC = inject('prefer-sfc') as Ref<boolean>
1820
1921
const currentStep = ref('')
22+
const keys = Object.keys(data)
23+
const totalSteps = keys.length
24+
25+
const titleRE = /<h1.*?>([\w\s-_]+?)<a class="header-anchor/
26+
const allSteps = keys.map((key, i) => {
27+
const desc = data[key]['description.md'] as string
28+
return {
29+
text: `${i + 1}. ${desc.match(titleRE)![1]}`,
30+
link: `#${key}`
31+
}
32+
})
2033
2134
const currentDescription = computed(() => {
2235
return data[currentStep.value]?.['description.md']
2336
})
2437
38+
const currentStepIndex = computed(() => {
39+
return keys.indexOf(currentStep.value) + 1
40+
})
41+
42+
const prevStep = computed(() => {
43+
const match = currentStep.value.match(/\d+/)
44+
const prev = match && `step-${+match[0] - 1}`
45+
if (prev && data.hasOwnProperty(prev)) {
46+
return prev
47+
}
48+
})
49+
2550
const nextStep = computed(() => {
26-
const nextMatch = currentStep.value.match(/\d+/)
27-
const next = nextMatch && `step-${+nextMatch[0] + 1}`
51+
const match = currentStep.value.match(/\d+/)
52+
const next = match && `step-${+match[0] + 1}`
2853
if (next && data.hasOwnProperty(next)) {
2954
return next
3055
}
@@ -80,13 +105,26 @@ updateExample()
80105
<template>
81106
<section class="tutorial">
82107
<article class="instruction">
108+
<PreferenceSwitch />
109+
<VTFlyout
110+
:button="`${currentStepIndex} / ${totalSteps}`"
111+
:items="allSteps"
112+
></VTFlyout>
83113
<div class="vt-doc" v-html="currentDescription"></div>
84-
<footer class="footer">
114+
<div class="hint">
85115
<button @click="toggleResult">{{ buttonText }}</button>
86-
<a v-if="nextStep" :href="`#${nextStep}`">Next Step &gt;</a>
116+
</div>
117+
<footer>
118+
<a v-if="prevStep" :href="`#${prevStep}`"
119+
><VTIconChevronLeft class="vt-link-icon" style="margin:0" /> Prev</a
120+
>
121+
<a class="next-step" v-if="nextStep" :href="`#${nextStep}`"
122+
>Next <VTIconChevronRight class="vt-link-icon"
123+
/></a>
87124
</footer>
88125
</article>
89126
<Repl
127+
layout="vertical"
90128
:store="store"
91129
:showCompileOutput="false"
92130
:clearConsole="false"
@@ -97,61 +135,85 @@ updateExample()
97135

98136
<style scoped>
99137
.tutorial {
100-
--ins-height: min(30vh, 250px);
138+
display: flex;
139+
--height: calc(100vh - var(--vt-nav-height) - var(--vt-banner-height, 0px));
101140
}
102141
103-
.vue-repl,
104142
.instruction {
105-
max-width: 1105px;
143+
width: 33%;
144+
height: var(--height);
145+
padding: 0 32px 24px;
106146
border-right: 1px solid var(--vt-c-divider-light);
107-
}
108-
109-
.instruction {
110-
height: var(--ins-height);
111-
padding: 24px 32px;
112-
border-bottom: 1px solid var(--vt-c-divider-light);
113147
font-size: 15px;
114148
overflow-y: auto;
149+
position: relative;
150+
--vt-nav-height: 40px;
151+
}
152+
153+
.vue-repl {
154+
width: 67%;
155+
height: var(--height);
156+
}
157+
158+
.vt-flyout {
159+
z-index: 9;
160+
position: absolute;
161+
right: 20px;
115162
}
116163
117164
footer {
118165
display: flex;
119166
align-items: center;
120167
justify-content: space-between;
121-
border-top: 1px solid #7e7e7e;
122-
margin-top: 2em;
168+
border-top: 1px solid var(--vt-c-divider);
169+
margin-top: 1.5em;
123170
padding-top: 1em;
124171
}
125-
footer button,
126-
a {
127-
color: var(--vt-c-green-light);
172+
173+
footer a {
174+
font-weight: 500;
175+
color: var(--vt-c-brand);
128176
}
129177
130-
.instruction h1 {
131-
font-weight: 600;
132-
font-size: 18px;
133-
margin-bottom: 0.5em;
178+
.next-step {
179+
margin-left: auto;
134180
}
135181
136-
.vue-repl {
137-
height: calc(
138-
100vh - var(--vt-nav-height) - var(--ins-height) -
139-
var(--vt-banner-height, 0px)
140-
);
182+
.vt-doc :deep(h1) {
183+
font-size: 1.4em;
184+
margin: 1em 0;
141185
}
142186
143-
@media (max-width: 960px) {
144-
.vue-repl {
145-
border: none;
146-
height: calc(
147-
100vh - var(--vt-nav-height) - var(--ins-height) -
148-
var(--vt-banner-height, 0px) - 48px
149-
);
150-
}
187+
.vt-doc :deep(.header-anchor) {
188+
display: none;
151189
}
152190
153-
.vt-doc :deep(h1) {
154-
font-size: 1.5em;
155-
margin-bottom: 1em;
191+
.hint {
192+
padding-top: 1em;
193+
}
194+
195+
button {
196+
background-color: var(--vt-c-brand);
197+
color: var(--vt-c-bg);
198+
padding: 4px 12px 3px;
199+
border-radius: 8px;
200+
font-weight: 600;
201+
font-size: 14px;
202+
}
203+
204+
@media (max-width: 720px) {
205+
.tutorial {
206+
display: block;
207+
}
208+
.instruction {
209+
width: 100%;
210+
border-right: none;
211+
border-bottom: 1px solid var(--vt-c-divider-light);
212+
height: 30vh;
213+
}
214+
.vue-repl {
215+
width: 100%;
216+
height: calc(70vh - var(--vt-nav-height) - var(--vt-banner-height, 0px));
217+
}
156218
}
157219
</style>

src/tutorial/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
page: true
3+
sidebar: false
34
aside: false
45
footer: false
56
returnToTop: false
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
:::tip WIP
2-
The tutorial is currently work in progress. Check back later!
3-
:::
4-
51
# Adding Data
62

73
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes.
84

95
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`.
6+
7+
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes.
8+
9+
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`.
10+
11+
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes.
12+
13+
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`.
14+
15+
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes.
16+
17+
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`.
18+
19+
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes.
20+
21+
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`.
22+
23+
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes.
24+
25+
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`.

src/tutorial/test.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/tutorial/tutorial.data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
const stepFiles = files[step]
1818
const desc = stepFiles['description.md'] as string
1919
if (desc) {
20-
stepFiles['description.md'] = md.render(desc).html
20+
stepFiles['description.md'] = md.render(desc)
2121
}
2222
}
2323
return files

0 commit comments

Comments
 (0)