-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathStackBlitzGithub.tsx
More file actions
46 lines (40 loc) · 1.22 KB
/
StackBlitzGithub.tsx
File metadata and controls
46 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sdk from '@stackblitz/sdk';
import React from 'react';
import GithubCodeBlock from './GithubCodeBlock';
interface StackBlitzGithubProps {
repoPath: string;
openFile?: string | string[];
codeFiles?: string[];
startScript?: string;
}
const StackBlitzGithub: React.FC<StackBlitzGithubProps> = ({
repoPath,
openFile = 'main.ts',
codeFiles: plainCodeFiles = undefined,
startScript,
}) => {
const openFiles = Array.isArray(openFile) ? openFile : openFile ? openFile.split(',') : [];
const options = {
openFile: openFiles ? openFiles.join(',') : undefined,
view: 'editor',
startScript,
} as const;
if (!plainCodeFiles) {
plainCodeFiles = [...openFiles];
}
return (
<>
<div className="mb-1 italic text-sm">
Click{' '}
<a href="#" onClick={() => sdk.openGithubProject(repoPath, options)}>
here
</a>{' '}
to open an interactive playground.
</div>
{plainCodeFiles.map((file) => (
<GithubCodeBlock key={file} repoPath={repoPath} file={file} />
))}
</>
);
};
export default StackBlitzGithub;