Files
DefectingCat.github.io/components/rua/rua-sandpack.tsx
2024-04-16 16:12:18 +08:00

53 lines
1.2 KiB
TypeScript

'use client';
import { Sandpack, SandpackProps } from '@codesandbox/sandpack-react';
import { THEME_CATPUCCIN_MAP } from 'lib/consts';
import useMounted from 'lib/hooks/use-mounted';
import { useTheme } from 'next-themes';
import { memo } from 'react';
interface Props extends SandpackProps {}
const RUASandpack = ({ ...rest }: Props) => {
const { mounted } = useMounted();
const { theme } = useTheme();
if (!mounted) {
return (
<div className="my-2 rounded-[0.5em] overflow-hidden">
<Sandpack
{...rest}
options={{
showConsole: true,
showConsoleButton: true,
editorHeight: '512px',
}}
/>
</div>
);
}
return (
<>
<div className="my-2 rounded-[0.5em] overflow-hidden">
<Sandpack
{...rest}
theme={
THEME_CATPUCCIN_MAP[
(theme ?? 'latte') as keyof typeof THEME_CATPUCCIN_MAP
]
}
options={{
showConsole: true,
showConsoleButton: true,
editorHeight: '512px',
showRefreshButton: true,
}}
/>
</div>
</>
);
};
export default memo(RUASandpack);