@@ -3,6 +3,8 @@ title: How to use TutorialKit API
3
3
description : " Examples showing how to utilize TutorialKit APIs"
4
4
---
5
5
6
+ import { Tabs , TabItem } from ' @astrojs/starlight/components' ;
7
+
6
8
## Access tutorial state
7
9
8
10
In this example we'll read contents of ` index.js ` using Tutorial Store APIs.
@@ -13,7 +15,10 @@ When user clicks `Help` button, we check the contents of `index.js` and provide
13
15
<img alt = " Open in StackBlitz" src = " https://developer.stackblitz.com/img/open_in_stackblitz.svg" />
14
16
</a >
15
17
16
- ``` tsx
18
+ <Tabs >
19
+ <TabItem label = " HelpButton.tsx" >
20
+
21
+ ``` tsx title="src/components/HelpButton.tsx"
17
22
import tutorialStore from " tutorialkit:store" ;
18
23
import { Dialog } from " @tutorialkit/react" ;
19
24
import { useState } from " react" ;
@@ -66,9 +71,87 @@ function verifyIndexJs(code: string) {
66
71
}
67
72
```
68
73
74
+ </TabItem >
75
+ <TabItem label = " content.mdx" >
76
+
77
+ ``` mdx title=" title="src/content/tutorial/chapter/part/lesson/content.mdx"
78
+ ---
79
+ type: lesson
80
+ title: TutorialKit API usage example
81
+ focus: /index.js
82
+ ---
83
+
84
+ import HelpButton from ' @components/HelpButton' ;
85
+
86
+ # TutorialKit API usage example
87
+
88
+ Click this button if you get stuck:
89
+
90
+ <HelpButton client :load />
91
+
92
+ ```
93
+
94
+ </TabItem >
95
+ </Tabs >
96
+
69
97
70
98
## Write to terminal
71
99
100
+ In this example we'll write commands to the terminal using Tutorial Store APIs.
101
+
102
+ When user clicks ` Run tests ` button, we run ` npm run test ` command into the terminal.
103
+ This command starts our ` test ` command defined in template's ` package.json ` .
104
+
105
+ <a class = " my-4 inline-block" href = " https://stackblitz.com/edit/stackblitz-starters-1qz1r8?file=src/components/TerminalWriter.tsx&file=src/content/tutorial/1-basics/1-introduction/1-welcome/content.mdx" >
106
+ <img alt = " Open in StackBlitz" src = " https://developer.stackblitz.com/img/open_in_stackblitz.svg" />
107
+ </a >
108
+
109
+ <Tabs >
110
+ <TabItem label = " TerminalWriter.tsx" >
111
+
112
+ ``` tsx title="src/components/TerminalWriter.tsx"
113
+ import tutorialStore from ' tutorialkit:store' ;
114
+
115
+ export default function TerminalWriter() {
116
+ async function onClick() {
117
+ const terminal = tutorialStore .terminalConfig .value ! .panels [0 ];
118
+ terminal .input (' npm run test\n ' );
119
+ }
120
+
121
+ return (
122
+ <button
123
+ onClick = { onClick }
124
+ className = " px-4 py-1 my-3 cursor-pointer border-1 border-tk-border-primary rounded-md bg-tk-elements-primaryButton-backgroundColor text-tk-elements-primaryButton-textColor"
125
+ >
126
+ Run tests
127
+ </button >
128
+ );
129
+ }
130
+ ```
131
+
132
+ </TabItem >
133
+
134
+ <TabItem label = " content.mdx" >
135
+
136
+ ``` mdx title="src/content/tutorial/chapter/part/lesson/content.mdx"
137
+ ---
138
+ type: lesson
139
+ title: Write to Terminal example
140
+ ---
141
+
142
+ import TerminalWriter from " @components/TerminalWriter" ;
143
+
144
+ # Write to Terminal example
145
+
146
+ Fix <code >counter.js</code > and run the tests!
147
+
148
+ <TerminalWriter client :load />
149
+ ```
150
+
151
+ </TabItem >
152
+
153
+ </Tabs >
154
+
72
155
## Provide feedback to user when lesson is solved
73
156
74
157
## How to watch a file for changes
0 commit comments