@coffic/cosy-ui 0.9.10 → 0.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,156 +0,0 @@
1
- ---
2
- /**
3
- * @component CardCourse
4
- *
5
- * @description
6
- * 课程卡片组件,用于展示课程信息,具有统一的设计风格。支持动态图标和渐变背景。
7
- *
8
- * @usage
9
- * ```astro
10
- * <CardCourse courseName="React 基础教程" courseSlug="react" lang="zh" href="/courses/react-basics" />
11
- * ```
12
- *
13
- * @props
14
- * - courseName: string - 课程标题
15
- * - courseSlug: string - 课程唯一标识(用于图标和背景)
16
- * - description?: string - 课程描述
17
- * - lang: string - 语言("en" 或 "zh")
18
- * - href: string - 课程链接
19
- */
20
-
21
- import '../../style.ts';
22
- import WebsiteIcon from '../icons/WebsiteIcon.astro';
23
- import AstroIcon from '../icons/AstroIcon.astro';
24
- import GolangIcon from '../icons/CodeIcon.astro';
25
- import JavaIcon from '../icons/CodeIcon.astro';
26
- import PhpIcon from '../icons/CodeIcon.astro';
27
- import VueIcon from '../icons/CodeIcon.astro';
28
- import SwiftIcon from '../icons/CodeIcon.astro';
29
- import BookIcon from '../icons/DocumentIcon.astro';
30
-
31
- interface Props {
32
- courseName: string;
33
- courseSlug: string;
34
- description?: string;
35
- lang: string;
36
- href: string;
37
- }
38
-
39
- const { courseName, courseSlug, description = '', lang, href } = Astro.props;
40
-
41
- // 图标映射(用 SVG 组件)
42
- const courseIconMap: Record<string, any> = {
43
- computer_networks: BookIcon,
44
- computer_organization: BookIcon,
45
- operating_systems: BookIcon,
46
- data_structures: BookIcon,
47
- higher_mathematics: BookIcon,
48
- linear_algebra: BookIcon,
49
- probability_and_statistics: BookIcon,
50
- vue: VueIcon,
51
- php: PhpIcon,
52
- javascript: BookIcon,
53
- java: JavaIcon,
54
- golang: GolangIcon,
55
- swift_ui: SwiftIcon,
56
- flutter: BookIcon,
57
- astro: GolangIcon,
58
- caddy: BookIcon,
59
- kong: BookIcon,
60
- default: BookIcon,
61
- };
62
-
63
- const courseGradientMap: Record<string, string> = {
64
- computer_networks: 'cosy:from-primary/50 cosy:to-secondary/50',
65
- computer_organization: 'cosy:from-primary/50 cosy:to-accent/50',
66
- operating_systems: 'cosy:from-secondary/50 cosy:to-accent/50',
67
- data_structures: 'cosy:from-accent/50 cosy:to-primary/50',
68
- higher_mathematics: 'cosy:from-success/50 cosy:to-info/50',
69
- linear_algebra: 'cosy:from-info/50 cosy:to-success/50',
70
- probability_and_statistics: 'cosy:from-success/50 cosy:to-accent/50',
71
- vue: 'cosy:from-success/50 cosy:to-primary/50',
72
- php: 'cosy:from-secondary/50 cosy:to-accent/50',
73
- javascript: 'cosy:from-warning/50 cosy:to-error/50',
74
- java: 'cosy:from-error/50 cosy:to-warning/50',
75
- golang: 'cosy:from-info/50 cosy:to-primary/50',
76
- swift_ui: 'cosy:from-warning/50 cosy:to-error/50',
77
- flutter: 'cosy:from-primary/50 cosy:to-secondary/50',
78
- astro: 'cosy:from-secondary/50 cosy:to-accent/50',
79
- caddy: 'cosy:from-success/50 cosy:to-primary/50',
80
- kong: 'cosy:from-accent/50 cosy:to-secondary/50',
81
- default: 'cosy:from-neutral cosy:to-base-content',
82
- };
83
-
84
- function normalizeName(name: string) {
85
- return name.toLowerCase().replace(/[^a-z0-9]/g, '_');
86
- }
87
-
88
- const normalizedName = normalizeName(courseSlug);
89
-
90
- // 动态选择图标
91
- let IconComponent = courseIconMap[normalizedName] || null;
92
- if (!IconComponent) {
93
- for (const key in courseIconMap) {
94
- if (key !== 'default' && normalizedName.includes(key)) {
95
- IconComponent = courseIconMap[key];
96
- break;
97
- }
98
- }
99
- }
100
- if (!IconComponent) IconComponent = courseIconMap.default;
101
-
102
- // 动态选择渐变
103
- let courseGradient = courseGradientMap[normalizedName] || '';
104
- if (!courseGradient) {
105
- for (const key in courseGradientMap) {
106
- if (key !== 'default' && normalizedName.includes(key)) {
107
- courseGradient = courseGradientMap[key];
108
- break;
109
- }
110
- }
111
- }
112
- if (!courseGradient) courseGradient = courseGradientMap.default;
113
-
114
- // 标题格式化
115
- const displayName = courseName
116
- .replace(/_/g, ' ')
117
- .replace(/\b\w/g, (l) => l.toUpperCase());
118
- ---
119
-
120
- <div
121
- class={`cosy:card cosy:shadow-lg hover:cosy:shadow-xl cosy:transition-all cosy:duration-300 hover:cosy:-translate-y-1 cosy:border-0 cosy:overflow-hidden cosy:bg-gradient-to-br ${courseGradient} cosy:relative`}>
122
- <!-- 背景图标 -->
123
- <div
124
- class="cosy:absolute cosy:top-2 cosy:right-2 cosy:opacity-30 cosy:w-24 cosy:h-24">
125
- {
126
- IconComponent === AstroIcon ? (
127
- <IconComponent name="astro" class="cosy:w-full cosy:h-full" />
128
- ) : (
129
- <IconComponent class="cosy:w-full cosy:h-full" />
130
- )
131
- }
132
- </div>
133
- <div class="cosy:card-body cosy:p-6 cosy:relative cosy:z-10">
134
- <!-- 标题和描述区域 -->
135
- <div class="cosy:mb-4">
136
- <h3 class="cosy:text-lg cosy:font-semibold cosy:truncate cosy:text-start">
137
- {displayName}
138
- </h3>
139
- {
140
- description && (
141
- <p class="cosy:text-sm cosy:mt-4 cosy:line-clamp-3 cosy:text-start">
142
- {description}
143
- </p>
144
- )
145
- }
146
- </div>
147
- <!-- 操作按钮 -->
148
- <div class="cosy:card-actions cosy:justify-end cosy:mt-4">
149
- <a
150
- href={href}
151
- class="cosy:btn cosy:bg-base-100 cosy:backdrop-blur-sm cosy:border cosy:border-base-100/30 hover:cosy:bg-base-100/30 cosy:transition-all cosy:duration-300">
152
- {lang === 'en' ? 'Start Learning' : '开始学习'}
153
- </a>
154
- </div>
155
- </div>
156
- </div>