Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/useCodePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export const getReactDOMClient = () => {
};

export function useCodePreview(props: CodePreviewProps) {
const isShowEdit = props.sourceState === 'shown';
const [demoDom, setDemoDom] = useState<HTMLDivElement>();
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<number | string>(1);
const [showEdit, setShowEdit] = useState(isShowEdit);
const [width, setWidth] = useState<number | string>(isShowEdit ? '50%' : 1);
const [copied, setCopied] = useState(false);
const [code, setCode] = useState(props.code || '');

Expand Down
1 change: 1 addition & 0 deletions test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('<CodePreview />', () => {
const component = TestRenderer.create(<CodePreview />);
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({
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"noUnusedLocals": true,
"experimentalDecorators": true,
"removeComments": false,
"noEmit": true,
"esModuleInterop": true
"esModuleInterop": true,
"emitDeclarationOnly": true
},
"include": ["src"]
}
1 change: 0 additions & 1 deletion website/App.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down