Skip to content

Commit b58c1f5

Browse files
committed
docs: first version on 'how to write to terminal' docs
1 parent b8c6c80 commit b58c1f5

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

docs/tutorialkit.dev/src/content/docs/guides/how-to-use-tutorialkit-api.mdx

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: How to use TutorialKit API
33
description: "Examples showing how to utilize TutorialKit APIs"
44
---
55

6+
import { Tabs, TabItem } from '@astrojs/starlight/components';
7+
68
## Access tutorial state
79

810
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
1315
<img alt="Open in StackBlitz" src="https://developer.stackblitz.com/img/open_in_stackblitz.svg" />
1416
</a>
1517

16-
```tsx
18+
<Tabs>
19+
<TabItem label="HelpButton.tsx">
20+
21+
```tsx title="src/components/HelpButton.tsx"
1722
import tutorialStore from "tutorialkit:store";
1823
import { Dialog } from "@tutorialkit/react";
1924
import { useState } from "react";
@@ -66,9 +71,87 @@ function verifyIndexJs(code: string) {
6671
}
6772
```
6873

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+
6997

7098
## Write to terminal
7199

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+
72155
## Provide feedback to user when lesson is solved
73156

74157
## How to watch a file for changes

0 commit comments

Comments
 (0)