diff --git a/.dumi/theme/builtins/Previewer/CodePreviewer.tsx b/.dumi/theme/builtins/Previewer/CodePreviewer.tsx index 4fc8ff9964..74749b2a90 100644 --- a/.dumi/theme/builtins/Previewer/CodePreviewer.tsx +++ b/.dumi/theme/builtins/Previewer/CodePreviewer.tsx @@ -108,7 +108,7 @@ const CodePreviewer: React.FC = (props) => { clientOnly, pkgDependencyList, } = props; - const { showDebug } = useContext(DemoContext); + const { showDebug, codeType } = useContext(DemoContext); const { pkg } = useSiteData(); const location = useLocation(); @@ -134,7 +134,6 @@ const CodePreviewer: React.FC = (props) => { const riddleIconRef = useRef(null); const codepenIconRef = useRef(null); const [codeExpand, setCodeExpand] = useState(false); - const [codeType, setCodeType] = useState('tsx'); const { theme } = useContext(SiteContext); const { hash, pathname, search } = location; @@ -541,7 +540,6 @@ createRoot(document.getElementById('container')).render(); styleCode={style} error={liveDemoError} entryName={entryName} - onCodeTypeChange={setCodeType} onSourceChange={setLiveDemoSource} />
{ @@ -67,7 +68,6 @@ interface CodePreviewProps jsxCode?: string; styleCode?: string; entryName: string; - onCodeTypeChange?: (activeKey: string) => void; onSourceChange?: (source: Record) => void; } @@ -92,7 +92,6 @@ const CodePreview: React.FC = ({ jsxCode = '', styleCode = '', entryName, - onCodeTypeChange, onSourceChange, error, }) => { @@ -108,6 +107,7 @@ const CodePreview: React.FC = ({ initialCodes.style = ''; } const [highlightedCodes, setHighlightedCodes] = React.useState(initialCodes); + const { codeType, setCodeType } = useContext(DemoContext); const sourceCodes = { // omit trailing line break tsx: sourceCode?.trim(), @@ -178,7 +178,15 @@ const CodePreview: React.FC = ({ ); } - return ; + return ( + + ); }; export default CodePreview; diff --git a/.dumi/theme/slots/Content/index.tsx b/.dumi/theme/slots/Content/index.tsx index e584d94fa3..c131e848da 100644 --- a/.dumi/theme/slots/Content/index.tsx +++ b/.dumi/theme/slots/Content/index.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useLayoutEffect, useMemo } from 'react'; +import React, { useContext, useLayoutEffect, useMemo, useState } from 'react'; import { Col, Flex, Typography } from 'antd'; import { createStyles } from 'antd-style'; import classNames from 'classnames'; @@ -43,6 +43,7 @@ const Content: React.FC = ({ children }) => { const { styles } = useStyle(); const [showDebug, setShowDebug] = useLayoutState(false); + const [codeType, setCodeType] = useState('tsx'); const debugDemos = useMemo( () => meta.toc?.filter((item) => item._debug_demo).map((item) => item.id) || [], [meta], @@ -55,8 +56,8 @@ const Content: React.FC = ({ children }) => { }, []); const contextValue = useMemo( - () => ({ showDebug, setShowDebug }), - [showDebug, debugDemos], + () => ({ showDebug, setShowDebug, codeType, setCodeType }), + [showDebug, codeType, debugDemos], ); const isRTL = direction === 'rtl'; diff --git a/.dumi/theme/slots/DemoContext.ts b/.dumi/theme/slots/DemoContext.ts index d377a4207b..0396dc385f 100644 --- a/.dumi/theme/slots/DemoContext.ts +++ b/.dumi/theme/slots/DemoContext.ts @@ -2,11 +2,14 @@ import { createContext } from 'react'; export type DemoContextProps = { showDebug?: boolean; + codeType?: string; }; const DemoContext = createContext<{ showDebug?: boolean; setShowDebug?: (showDebug: boolean) => void; + codeType?: string; + setCodeType?: (codeType: string) => void; }>({}); export default DemoContext;