-
Notifications
You must be signed in to change notification settings - Fork 88
docs: add example of tutorialkit:store
and tutorialkit:core
usages
#348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b05fc55
docs: add example of `tutorialkit:store` usage
AriPerkkio ddcdc3a
docs: add example of `tutorialkit:core` usage
AriPerkkio d6a816e
docs: code review, remove "Using low level APIs"
AriPerkkio cfb8209
docs: add initial draft of "TutorialKit API" docs
AriPerkkio 0138820
docs: code review, setup page for 'How to'
AriPerkkio 91197ed
docs: add more tutorialkit store api docs
AriPerkkio 87e69d0
docs: rest of tutorialkit api docs
AriPerkkio b8c6c80
docs: first version on 'how to use tutorial store' docs
AriPerkkio b58c1f5
docs: first version on 'how to write to terminal' docs
AriPerkkio 05a5feb
docs: first version on 'Provide feedback to user when lesson is solve…
AriPerkkio 590ea76
docs: add github discussion link
AriPerkkio 1da8471
Merge branch 'main' into docs/tutorial-store
AriPerkkio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
docs/tutorialkit.dev/src/components/react-examples/HelpButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Dialog } from '@tutorialkit/react'; | ||
import { useState } from 'react'; | ||
|
||
export function HelpButton() { | ||
const [message, setMessage] = useState<string | null>(null); | ||
|
||
async function onClick() { | ||
setMessage('Your index.js should have a default export'); | ||
} | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={onClick} | ||
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" | ||
> | ||
Help | ||
</button> | ||
|
||
{message && ( | ||
<Dialog title="Help" confirmText="OK" onClose={() => setMessage(null)}> | ||
{message} | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
} |
104 changes: 104 additions & 0 deletions
104
docs/tutorialkit.dev/src/content/docs/guides/using-low-level-apis.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
title: Using low level APIs | ||
--- | ||
|
||
import { HelpButton } from "@components/react-examples/HelpButton"; | ||
import '@tutorialkit/astro/default-theme.css'; | ||
|
||
TutorialKit exposes low level APIs that authors can utilize to provide highly custom experience in their tutorials. | ||
|
||
## Tutorial Store | ||
|
||
You can access Tutorial Store by importing the `tutorialkit:store` entrypoint. | ||
|
||
```ts | ||
import tutorialStore from "tutorialkit:store"; | ||
``` | ||
|
||
The Tutorial Store provides access to current state of the Tutorial, for example the files and their contents. | ||
|
||
```ts | ||
import tutorialStore from "tutorialkit:store"; | ||
|
||
console.log(tutorialStore.documents.value); | ||
AriPerkkio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
"/index.js": { | ||
"value": "export default 'hello from index.js';\n", | ||
"type": "file", | ||
}, | ||
"/vite.config.ts": { | ||
"value": "import { defineConfig } from \"vite\";\n\nexport default defineConfig({});\n", | ||
"type": "file", | ||
} | ||
} | ||
``` | ||
|
||
It also exposes methods that can be used to modify lesson files: | ||
|
||
```ts | ||
import tutorialStore from "tutorialkit:store"; | ||
|
||
await tutorialStore.addFolder("/src"); | ||
await tutorialStore.addFile("/src/new-file.js"); | ||
tutorialStore.updateFile("/src/new-file.js", "console.log('Hello world');"); | ||
``` | ||
|
||
### Example usage in React component | ||
|
||
Here is an example of custom React component that reads contents of `index.js` and gives user hints about the expected content. | ||
|
||
<HelpButton client:load /> | ||
|
||
```tsx title="src/components/HelpButton.tsx" | ||
import tutorialStore from "tutorialkit:store"; | ||
import { Dialog } from "@tutorialkit/react"; | ||
import { useState } from "react"; | ||
|
||
export function HelpButton() { | ||
const [message, setMessage] = useState<string | null>(null); | ||
|
||
async function onClick() { | ||
const files = tutorialStore.documents.value; | ||
const index = files["/index.js"].value as string; | ||
|
||
if (index.length === 0) { | ||
setMessage("Your index.js should not be empty"); | ||
} else if (!index.includes("export default")) { | ||
setMessage("Your index.js should have a default export"); | ||
} else { | ||
setMessage("All good"); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={onClick} | ||
className="px-4 py-1 rounded-md bg-tk-elements-primaryButton-backgroundColor text-tk-elements-primaryButton-textColor" | ||
> | ||
Help | ||
</button> | ||
|
||
{message && ( | ||
<Dialog title="Help" confirmText="OK" onClose={() => setMessage(null)}> | ||
{message} | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
} | ||
``` | ||
|
||
```mdx title="content.mdx" | ||
--- | ||
type: lesson | ||
title: Lesson Topic | ||
--- | ||
|
||
import { HelpButton } from "@/components/HelpButton"; | ||
|
||
# Lesson Topic | ||
|
||
In this lesson we'll learn about... | ||
Click this button if you need help: <HelpButton client:load /> | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.