diff --git a/src/index.tsx b/src/index.tsx index 82482d44..2b7fc5c9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -71,6 +71,10 @@ export interface CodePreviewProps extends SplitProps { * @default light */ theme?: ReactCodeMirrorProps['theme']; + /** + * Specifies the initial state of the source panel. + */ + sourceState?: 'hidden' | 'shown'; } export interface CodePreviewState { diff --git a/src/useCodePreview.ts b/src/useCodePreview.ts index 06c900cc..418fde4c 100644 --- a/src/useCodePreview.ts +++ b/src/useCodePreview.ts @@ -16,12 +16,13 @@ export const getReactDOMClient = () => { }; export function useCodePreview(props: CodePreviewProps) { + const isShowEdit = props.sourceState === 'shown'; const [demoDom, setDemoDom] = useState(); const playerId = useRef(`${parseInt(String(Math.random() * 1e9), 10).toString(36)}`); const [fullScreen, setFullScreen] = useState(false); const [errorMessage, setErrorMessage] = useState(''); - const [showEdit, setShowEdit] = useState(false); - const [width, setWidth] = useState(1); + const [showEdit, setShowEdit] = useState(isShowEdit); + const [width, setWidth] = useState(isShowEdit ? '50%' : 1); const [copied, setCopied] = useState(false); const [code, setCode] = useState(props.code || ''); diff --git a/test/index.test.tsx b/test/index.test.tsx index 85af2d33..a9ee6245 100644 --- a/test/index.test.tsx +++ b/test/index.test.tsx @@ -7,6 +7,7 @@ describe('', () => { const component = TestRenderer.create(); let tree = component.toJSON(); if (tree && !Array.isArray(tree)) { + /* eslint-disable jest/no-conditional-expect */ expect(tree.type).toEqual('div'); expect(tree.props.className).toEqual('w-split w-code-preview w-code-preview-bordered w-split-horizontal'); expect(tree.props.style).toEqual({ diff --git a/tsconfig.json b/tsconfig.json index 79da1c40..c1a38a4d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,8 +19,8 @@ "noUnusedLocals": true, "experimentalDecorators": true, "removeComments": false, - "noEmit": true, - "esModuleInterop": true + "esModuleInterop": true, + "emitDeclarationOnly": true }, "include": ["src"] } diff --git a/website/App.tsx b/website/App.tsx index 056da6d0..1495ca13 100644 --- a/website/App.tsx +++ b/website/App.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import GitHubCorners from '@uiw/react-github-corners'; import Markdown from '@uiw/react-markdown-preview'; import '@wcj/dark-mode';