From 5e9e0adff1cf2e5c0930be2fc0a2f098785b864c Mon Sep 17 00:00:00 2001 From: PeachScript Date: Tue, 17 Nov 2020 10:50:30 +0800 Subject: [PATCH] refactor(theme): support to pass demo url for default theme --- packages/theme-default/src/builtins/Previewer.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/theme-default/src/builtins/Previewer.tsx b/packages/theme-default/src/builtins/Previewer.tsx index 9dc51e541c..098e701381 100644 --- a/packages/theme-default/src/builtins/Previewer.tsx +++ b/packages/theme-default/src/builtins/Previewer.tsx @@ -43,6 +43,10 @@ export interface IPreviewerProps extends IPreviewerComponentProps { * use iframe mode for this demo */ iframe?: true | number; + /** + * replace builtin demo url + */ + demoUrl?: string; } /** @@ -50,7 +54,7 @@ export interface IPreviewerProps extends IPreviewerComponentProps { * @param file file path * @param source file source object */ -function getSourceType(file: string, source: IPreviewerComponentProps['sources']['']) { +function getSourceType(file: string, source: IPreviewerComponentProps['sources']['_']) { // use file extension as source type first let type = file.match(/\.(\w+)$/)?.[1]; @@ -65,7 +69,8 @@ const Previewer: React.FC = oProps => { const demoRef = useRef(); const { locale } = useContext(context); const props = useLocaleProps(locale, oProps); - const demoUrl = useDemoUrl(props.identifier); + const builtinDemoUrl = useDemoUrl(props.identifier); + const demoUrl = props.demoUrl || builtinDemoUrl; const isActive = history?.location.hash === `#${props.identifier}`; const isSingleFile = Object.keys(props.sources).length === 1; const openCSB = useCodeSandbox(props.hideActions?.includes('CSB') ? null : props);