Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix box demo start up #3297

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 56 additions & 13 deletions site/src/components/stackblitz/content.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import orgPkg from '../../../../package.json';

export const htmlContent = `
<div id="app" style="padding: 24px;"></div>
<div id="app"></div>
<script type="module" src="/src/index.jsx"></script>
`;

export const mainJsContent = `
import React from 'react';
import ReactDOM from 'react-dom';
import React, { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import Demo from './demo';
import './index.css';
import 'tdesign-react/dist/tdesign.css';

const rootElement = document.getElementById('app');
ReactDOM.render(<Demo />, rootElement);
const root = createRoot(rootElement);

root.render(
<React.StrictMode>
<Demo />
</React.StrictMode>,
);
`;

export const styleContent = `
Expand Down Expand Up @@ -66,12 +74,47 @@ export const tsconfigContent = `{
}
`;

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'],
});
export const stackblitzRc = `
{
"installDependencies": true,
"startCommand": "npm run dev"
}
`;

export const viteConfigContent = `
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [react()],
});
`;

export const packageJSONContent = JSON.stringify(
{
name: 'tdesign-react-demo',
version: '0.0.0',
private: true,
scripts: {
dev: 'vite',
build: 'vite build',
serve: 'vite preview',
},
dependencies: {
react: orgPkg.devDependencies.react,
dayjs: orgPkg.dependencies.dayjs,
'react-dom': orgPkg.devDependencies['react-dom'],
'tdesign-react': orgPkg.version,
'tdesign-icons-react': orgPkg.dependencies['tdesign-icons-react'],
'@types/react': orgPkg.devDependencies['@types/react'],
'@types/react-dom': orgPkg.devDependencies['@types/react-dom'],
},
devDependencies: {
vite: orgPkg.devDependencies.vite,
'@vitejs/plugin-react': orgPkg.devDependencies['@vitejs/plugin-react'],
typescript: orgPkg.devDependencies.typescript,
},
},
null,
2,
);
30 changes: 23 additions & 7 deletions site/src/components/stackblitz/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React, { useRef, useState } from 'react';
import Tooltip from 'tdesign-react/tooltip';

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

const TypeScriptType = 0;

Expand All @@ -23,20 +31,28 @@ export default function Stackblitz(props) {

return (
<Tooltip content="在 Stackblitz 中打开">
<form ref={formRef} method="post" action="https://stackblitz.com/run" target="_blank" onClick={submit}>
<form
ref={formRef}
method="post"
action={`https://stackblitz.com/run?file=src%2F${isTypeScriptDemo ? 'demo.tsx' : 'demo.jsx'}`}
target="_blank"
onClick={submit}
>
{isTypeScriptDemo ? (
<>
<input type="hidden" name="project[files][src/demo.tsx]" value={code} />
<input type="hidden" name="project[tsconfig.json]" value={tsconfigContent} />
<input type="hidden" name="project[files][tsconfig.json]" value={tsconfigContent} />
</>
) : (
<input type="hidden" name="project[files][src/demo.jsx]" 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[files][public/index.html]" value={htmlContent} />
<input type="hidden" name="project[dependencies]" value={dependenciesContent} />
<input type="hidden" name="project[template]" value="create-react-app" />
<input type="hidden" name="project[files][src/index.jsx]" value={mainJsContent} />
<input type="hidden" name="project[files][index.html]" value={htmlContent} />
<input type="hidden" name="project[files][vite.config.js]" value={viteConfigContent} />
<input type="hidden" name="project[files][.stackblitzrc]" value={stackblitzRc} />
<input type="hidden" name="project[files][package.json]" value={packageJSONContent} />
<input type="hidden" name="project[template]" value="node" />

<div className="action-online">
<svg viewBox="0 0 28 28" height="20">
Expand Down
4 changes: 1 addition & 3 deletions src/form/_example/form-field-linkage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import Form from '../Form';
import Radio from '../../radio';
import Button from '../../button';
import { Form, Radio, Button } from 'tdesign-react';

const { FormItem } = Form;

Expand Down
Loading