-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add sandbox component and improve tabs component
Implemented a new Sandbox component that allows the embedding of dynamic code editors like CodeSandbox and Stackblitz inside documentation. Moreover, enhanced the existing Tabs component by adding more flexible control of tab states. They were added secondary index settings and implemented an option to preserve the tab state in local storage, both changes to increase usability and user experience. Signed-off-by: prisis <d.bannert@anolilab.de>
- Loading branch information
Showing
11 changed files
with
267 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,3 @@ | ||
import { Sandbox } from "@visulima/nextra-theme-docs"; | ||
|
||
<Sandbox repo="vercel/next.js" branch="canary" dir="examples/active-class-name" /> |
This file contains 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
42 changes: 42 additions & 0 deletions
42
packages/nextra-theme-docs/__docs__/writing-content/components/sandbox.mdx
This file contains 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,42 @@ | ||
import { Sandbox } from "@visulima/nextra-theme-docs"; | ||
|
||
<Sandbox repo="vercel/next.js" branch="canary" dir="examples/active-class-name" /> | ||
|
||
## API | ||
|
||
The `Sandbox` component takes the following props: | ||
|
||
### `repo` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
The GitHub repository to use. This should be in the format `owner/repo`. | ||
|
||
### `branch` | ||
|
||
- Type: `string` | ||
- Default: `main` | ||
|
||
The branch to use. Defaults to `main`. | ||
|
||
### `dir` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
The directory to use. Defaults to the root of the repository. | ||
|
||
### `file` | ||
|
||
- Type: `string` | ||
- Default: `` | ||
|
||
The file to use. | ||
|
||
### `minHeight` | ||
|
||
- Type: `string` | ||
- Default: `700px` | ||
|
||
The minimum height of the iframe. Defaults to `700px`. |
This file contains 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
This file contains 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,66 @@ | ||
import type { FC } from "react"; | ||
import { useTheme } from "next-themes"; | ||
import { useConfig } from "../contexts"; | ||
import { Tab, Tabs } from "./tabs"; | ||
|
||
const defaultProviders: Record<string, string> = { | ||
CodeSandbox: `https://codesandbox.io/embed/github/{repo}/tree/{branch}/{dir}?hidenavigation=1&theme={colorMode}`, | ||
StackBlitz: `https://stackblitz.com/github/{repo}/tree/{branch}/{dir}?embed=1&file={file}&theme={colorMode}`, | ||
}; | ||
const Sandbox: FC<{ | ||
branch?: string; | ||
dir?: string; | ||
file: string; | ||
minHeight?: string; | ||
repo?: string; | ||
src?: string; | ||
// eslint-disable-next-line unicorn/prevent-abbreviations | ||
}> = ({ branch = "main", dir = "", file, minHeight = "700px", repo: repository = "", src: source = undefined }) => { | ||
const { sandbox } = useConfig(); | ||
const { resolvedTheme } = useTheme(); | ||
|
||
const providers: Record<string, string> = { ...defaultProviders, ...sandbox?.providers }; | ||
|
||
Object.keys(providers).forEach((key: string) => { | ||
if (source) { | ||
// eslint-disable-next-line security/detect-object-injection | ||
providers[key] = source; | ||
} | ||
|
||
// eslint-disable-next-line security/detect-object-injection | ||
providers[key] = (providers[key] as string) | ||
.replace("{repo}", repository) | ||
.replace("{branch}", branch) | ||
.replace("{dir}", dir) | ||
.replace("{file}", file) | ||
.replace("{colorMode}", resolvedTheme ?? "light"); | ||
}); | ||
|
||
return ( | ||
<Tabs | ||
/* eslint-disable-next-line @arthurgeron/react-usememo/require-usememo */ | ||
classes={{ | ||
tabs: "relative text-white bg-gray-200 rounded-t-lg dark:bg-gray-700", | ||
}} | ||
disableScrollBar | ||
prefix="sandbox" | ||
storageKey="sandbox" | ||
> | ||
{Object.keys(providers).map((key: string) => ( | ||
<Tab className="not-prose relative" key={key} style={{ minHeight }} title={key}> | ||
<span className="absolute inset-x-0 top-20 m-auto block w-40 text-center">Loading Sandbox...</span> | ||
<iframe | ||
className="not-prose absolute left-0 top-0 z-10 h-full w-full overflow-hidden" | ||
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" | ||
/* eslint-disable-next-line security/detect-object-injection */ | ||
src={providers[key]} | ||
style={{ minHeight, width: "100%" }} | ||
title="Sandbox editor" | ||
/> | ||
</Tab> | ||
))} | ||
</Tabs> | ||
); | ||
}; | ||
|
||
export default Sandbox; |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
aeb6378
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
visulima-docs – ./
visulima-docs-visulima.vercel.app
visulima-docs.vercel.app
www.visulima.com
visulima.com
visulima-docs-git-main-visulima.vercel.app