Skip to content

Commit

Permalink
chore: codesandbox and stackblitz adjust to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Jun 24, 2024
1 parent d74670d commit 30cbde9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
32 changes: 31 additions & 1 deletion site/src/components/codesandbox/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,50 @@ export const styleContent = `
}
`;

export const tsconfigContent = `{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
`;

export const pkgContent = JSON.stringify(
{
name: 'tdesign-react-demo',
version: '1.0.0',
description: 'React example starter project',
keywords: ['react', 'starter'],
main: 'src/main.jsx',
main: 'src/main.tsx',
dependencies: {
dayjs: orgPkg.dependencies.dayjs,
react: orgPkg.devDependencies.react,
'react-dom': orgPkg.devDependencies['react-dom'],
'tdesign-react': orgPkg.version,
'tdesign-icons-react': orgPkg.dependencies['tdesign-icons-react'],
'react-scripts': '^5.0.0',
'@types/react': orgPkg.devDependencies['@types/react'],
'@types/react-dom': orgPkg.devDependencies['@types/react-dom'],
},
devDependencies: {
typescript: '^4.4.4',
Expand Down
5 changes: 4 additions & 1 deletion site/src/components/codesandbox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';
import Tooltip from 'tdesign-react/tooltip';
import Loading from 'tdesign-react/loading';

import { mainJsContent, htmlContent, pkgContent, styleContent } from './content';
import { mainJsContent, htmlContent, pkgContent, styleContent, tsconfigContent } from './content';
import '../../styles/Codesandbox.less';

export default function Codesandbox(props) {
Expand Down Expand Up @@ -35,6 +35,9 @@ export default function Codesandbox(props) {
'src/demo.tsx': {
content: code,
},
'tsconfig.json': {
content: tsconfigContent,
},
},
}),
})
Expand Down
30 changes: 30 additions & 0 deletions site/src/components/stackblitz/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,40 @@ export const styleContent = `
}
`;

export const tsconfigContent = `{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
`;

export const dependenciesContent = JSON.stringify({
'tdesign-react': orgPkg.version,
'tdesign-icons-react': orgPkg.dependencies['tdesign-icons-react'],
dayjs: orgPkg.dependencies.dayjs,
react: orgPkg.devDependencies.react,
'react-dom': orgPkg.devDependencies['react-dom'],
'@types/react': orgPkg.devDependencies['@types/react'],
'@types/react-dom': orgPkg.devDependencies['@types/react-dom'],
});
5 changes: 3 additions & 2 deletions site/src/components/stackblitz/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef } from 'react';
import Tooltip from 'tdesign-react/tooltip';

import { htmlContent, mainJsContent, styleContent, dependenciesContent } from './content';
import { htmlContent, mainJsContent, styleContent, dependenciesContent, tsconfigContent } from './content';

export default function Stackblitz(props) {
const { code } = props;
Expand All @@ -14,9 +14,10 @@ export default function Stackblitz(props) {
return (
<Tooltip content="在 Stackblitz 中打开">
<form ref={formRef} method="post" action="https://stackblitz.com/run" target="_blank" onClick={submit}>
<input type="hidden" name="project[files][src/demo.jsx]" value={code} />
<input type="hidden" name="project[files][src/demo.tsx]" value={code} />
<input type="hidden" name="project[files][src/index.css]" value={styleContent} />
<input type="hidden" name="project[files][src/index.js]" value={mainJsContent} />
<input type="hidden" name="project[tsconfig.json]" value={tsconfigContent} />
<input type="hidden" name="project[files][public/index.html]" value={htmlContent} />
<input type="hidden" name="project[dependencies]" value={dependenciesContent} />
<input type="hidden" name="project[template]" value="create-react-app" />
Expand Down

0 comments on commit 30cbde9

Please sign in to comment.