Skip to content

Commit d2cc2d3

Browse files
committed
重构:将TypescriptSupport组件模块化,拆分样式和功能代码
1 parent da7560b commit d2cc2d3

File tree

6 files changed

+280
-228
lines changed

6 files changed

+280
-228
lines changed

office-website/src/components/TypescriptSupport.tsx

Lines changed: 0 additions & 228 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
3+
export const TypeSafetyIcon = () => (
4+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
5+
<path d="M8 12L11 15L16 9" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
6+
<path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
7+
</svg>
8+
);
9+
10+
export const SmartSuggestionIcon = () => (
11+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
12+
<path d="M9 19.15V4.85C9 4.85 15 1.12 15 12C15 22.88 9 19.15 9 19.15Z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
13+
<path d="M5.28 9.32C5.28 9.32 7.89 7.5 7.89 12C7.89 16.5 5.28 14.68 5.28 14.68" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
14+
<path d="M18.42 9.32C18.42 9.32 15.81 7.5 15.81 12C15.81 16.5 18.42 14.68 18.42 14.68" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
15+
</svg>
16+
);
17+
18+
export const RefactoringIcon = () => (
19+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
20+
<path d="M3 7V5C3 4.46957 3.21071 3.96086 3.58579 3.58579C3.96086 3.21071 4.46957 3 5 3H19C19.5304 3 20.0391 3.21071 20.4142 3.58579C20.7893 3.96086 21 4.46957 21 5V19C21 19.5304 20.7893 20.0391 20.4142 20.4142C20.0391 20.7893 19.5304 21 19 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V17" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
21+
<path d="M13 17L17 12L13 7" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
22+
<path d="M7 12L17 12" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
23+
</svg>
24+
);
25+
26+
export const ModernSyntaxIcon = () => (
27+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
28+
<path d="M6 16.8V20.4C6 20.8418 6.12643 21.2627 6.36001 21.6C6.59358 21.9373 6.92161 22.1767 7.29912 22.2836C7.67664 22.3905 8.08474 22.359 8.44016 22.1937C8.79558 22.0284 9.07848 21.7483 9.24 21.4L15.24 10.4" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
29+
<path d="M18 14L21 17L18 20" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
30+
<path d="M12 8L9 5L12 2" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
31+
<path d="M9 5H13.24C13.8214 5.00014 14.394 5.11665 14.9237 5.34223C15.4535 5.56782 15.9279 5.89725 16.32 6.31C16.7121 6.72276 17.0144 7.21343 17.2103 7.74792C17.4062 8.28242 17.492 8.84889 17.462 9.41718C17.4319 9.98546 17.2868 10.5397 17.0359 11.0486C16.785 11.5574 16.4335 12.0093 16 12.38L9.24 21.4" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
32+
</svg>
33+
);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import { CodeContainer } from '../../styles/components/TypescriptSupport.styles';
3+
import CustomCodeBlock from '../CustomCodeBlock';
4+
5+
const tsCode = `// 类型定义
6+
interface UserScriptOptions {
7+
name: string;
8+
version: string;
9+
match: string[];
10+
namespace?: string;
11+
description?: string;
12+
}
13+
14+
// 类型安全的 API 调用
15+
GM_addStyle('.my-style { color: #3B82F6; }');
16+
17+
// 泛型支持
18+
function getData<T>(url: string): Promise<T> {
19+
return new Promise((resolve, reject) => {
20+
GM_xmlhttpRequest({
21+
method: 'GET',
22+
url,
23+
onload: (response) => {
24+
try {
25+
const data = JSON.parse(response.responseText) as T;
26+
resolve(data);
27+
} catch (error) {
28+
reject(error);
29+
}
30+
},
31+
onerror: (error) => reject(error)
32+
});
33+
});
34+
}
35+
36+
// 使用示例
37+
interface User {
38+
id: number;
39+
name: string;
40+
email: string;
41+
}
42+
43+
// 类型安全的异步请求
44+
async function fetchUser(id: number): Promise<User> {
45+
return await getData<User>(\`https://api.example.com/users/\${id}\`);
46+
}`;
47+
48+
const TypescriptCodeExample: React.FC = () => {
49+
return (
50+
<CodeContainer>
51+
<CustomCodeBlock
52+
code={tsCode}
53+
language="typescript"
54+
showLineNumbers={true}
55+
/>
56+
</CodeContainer>
57+
);
58+
};
59+
60+
export default TypescriptCodeExample;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import {
3+
FeatureItem,
4+
FeatureIcon,
5+
FeatureText,
6+
FeatureTitle,
7+
FeatureDescription
8+
} from '../../styles/components/TypescriptSupport.styles';
9+
10+
interface TypescriptFeatureProps {
11+
title: string;
12+
description: string;
13+
icon: React.ReactNode;
14+
}
15+
16+
const TypescriptFeature: React.FC<TypescriptFeatureProps> = ({
17+
title,
18+
description,
19+
icon
20+
}) => {
21+
return (
22+
<FeatureItem>
23+
<FeatureIcon>{icon}</FeatureIcon>
24+
<FeatureText>
25+
<FeatureTitle>{title}</FeatureTitle>
26+
<FeatureDescription>{description}</FeatureDescription>
27+
</FeatureText>
28+
</FeatureItem>
29+
);
30+
};
31+
32+
export default TypescriptFeature;

0 commit comments

Comments
 (0)