Add sandpack

This commit is contained in:
Defectink
2022-04-13 11:47:52 +08:00
parent ba761f4bd9
commit c9b0cbb96f
7 changed files with 500 additions and 3 deletions

View File

@ -22,7 +22,7 @@ const PostCard: FC<Props> = ({ post }) => {
'mb-4 dark:text-gray-200'
)}
>
<div>
<div className="flex-1">
<h2 className="mb-4 text-3xl font-semibold font-Barlow">
{post.title}
</h2>

View File

@ -0,0 +1,29 @@
import { FC, useEffect, useState } from 'react';
import { Sandpack, SandpackProps } from '@codesandbox/sandpack-react';
import '@codesandbox/sandpack-react/dist/index.css';
import { useTheme } from 'next-themes';
interface Props extends SandpackProps {}
const RUASandpack: FC<Props> = ({ ...rest }) => {
const [mounted, setMounted] = useState(false);
const { systemTheme, theme } = useTheme();
const currentTheme = theme === 'system' ? systemTheme : theme;
useEffect(() => setMounted(true), []);
if (!mounted) return null;
return (
<>
<div className="my-2">
<Sandpack
{...rest}
theme={currentTheme === 'dark' ? 'dark' : 'light'}
/>
</div>
</>
);
};
export default RUASandpack;