Skip to content

Commit

Permalink
refactor(theme): support to pass demo url for default theme
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Nov 17, 2020
1 parent 4fcdd4e commit 5e9e0ad
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/theme-default/src/builtins/Previewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ export interface IPreviewerProps extends IPreviewerComponentProps {
* use iframe mode for this demo
*/
iframe?: true | number;
/**
* replace builtin demo url
*/
demoUrl?: string;
}

/**
* get source code type for file
* @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];

Expand All @@ -65,7 +69,8 @@ const Previewer: React.FC<IPreviewerProps> = oProps => {
const demoRef = useRef();
const { locale } = useContext(context);
const props = useLocaleProps<IPreviewerProps>(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);
Expand Down

0 comments on commit 5e9e0ad

Please sign in to comment.