-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: doc support Sandpack component
- Loading branch information
Showing
8 changed files
with
478 additions
and
144 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,7 @@ | ||
.light { | ||
--sp-layout-height: 500px !important; | ||
} | ||
|
||
.dark { | ||
--sp-layout-height: 500px !important; | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/document/main-doc/src/components/Sandpack/index.tsx
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,28 @@ | ||
import ModernSandpack, { ModernSandpackProps } from '@modern-js/sandpack-react'; | ||
import React, { PropsWithChildren } from 'react'; | ||
import { useDark } from 'rspress/runtime'; | ||
|
||
import './index.css'; | ||
|
||
const Sandpack = (props: PropsWithChildren<ModernSandpackProps>) => { | ||
const dark = useDark(); | ||
const { children, ...otherProps } = props; | ||
const files: Record<string, string> = {}; | ||
React.Children.forEach(children, (child: any) => { | ||
if (child) { | ||
const { meta, children } = child.props.children.props; | ||
const matches = meta.match(/title="(.*)"/); | ||
if (matches.length > 1) { | ||
files[matches[1]] = children; | ||
} | ||
} | ||
}); | ||
return ( | ||
<ModernSandpack | ||
files={files} | ||
theme={dark ? 'dark' : 'light'} | ||
{...otherProps} | ||
/> | ||
); | ||
}; | ||
export default Sandpack; |
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
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.