import { useColorMode } from "@docusaurus/theme-common"; import useBaseUrl from "@docusaurus/useBaseUrl"; import { CSSProperties, FC, RefObject, useEffect, useRef, useState, } from "react"; export const Playground: FC<{ innerRef?: RefObject; style?: CSSProperties; headerText?: string; customCode?: string; autosize?: boolean; }> = (props) => { const { colorMode } = useColorMode(); const sinhoPath = useBaseUrl("/dist/bundle.min.js"); const importMap = { imports: { sinho: sinhoPath, "sinho/jsx-runtime": sinhoPath, }, }; useEffect(() => { import("./playgroundComponent"); }, []); const Playground: any = "x-playground"; return ( ); }; export const CodeSnippetPlayground: FC<{ headerText?: string; customCode?: (code: string) => string; }> = (props) => { const [customCode, setCustomCode] = useState(""); const playgroundRef = useRef(null); useEffect(() => { if (playgroundRef.current == null) return; const codeElement = playgroundRef.current .previousElementSibling as HTMLElement | null; const detectedCode = codeElement?.innerText ?? ""; setCustomCode(props.customCode?.(detectedCode) ?? detectedCode); }, [props.customCode]); return ( ); }; export const CodeSnippetComponentPlayground: FC<{ headerText?: string; componentName: string; }> = (props) => { return ( `${code} import { defineComponents } from "sinho"; defineComponents(${props.componentName}); document.body.append(new ${props.componentName}());` } /> ); };