mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 01:01:38 +00:00
Add sandpack
This commit is contained in:
@ -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>
|
||||
|
29
components/RUA/RUASandpack.tsx
Normal file
29
components/RUA/RUASandpack.tsx
Normal 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;
|
Reference in New Issue
Block a user