@coffic/cosy-ui 0.3.69 → 0.4.5

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.
Files changed (34) hide show
  1. package/dist/app.css +1 -1
  2. package/dist/components/base/Alert.astro +3 -3
  3. package/dist/components/containers/Container.astro +80 -4
  4. package/dist/components/containers/Main.astro +41 -54
  5. package/dist/components/data-display/Blog.astro +1 -0
  6. package/dist/components/data-display/ProductCard.astro +0 -2
  7. package/dist/components/data-display/Products.astro +0 -2
  8. package/dist/components/data-display/TeamMember.astro +0 -2
  9. package/dist/components/data-display/TeamMembers.astro +0 -2
  10. package/dist/components/display/Banner.astro +0 -1
  11. package/dist/components/display/Card.astro +0 -1
  12. package/dist/components/display/CodeBlock.astro +0 -1
  13. package/dist/components/display/CodeExample.astro +0 -1
  14. package/dist/components/display/Modal.astro +65 -67
  15. package/dist/components/layouts/AppLayout.astro +258 -0
  16. package/dist/components/layouts/BaseLayout.astro +46 -92
  17. package/dist/components/layouts/DashboardLayout.astro +615 -604
  18. package/dist/components/layouts/Footer.astro +141 -113
  19. package/dist/components/layouts/Header.astro +11 -292
  20. package/dist/components/layouts/Sidebar.astro +54 -31
  21. package/dist/components/layouts/SidebarNav.astro +1 -11
  22. package/dist/components/typography/Article.astro +8 -30
  23. package/dist/index.ts +7 -4
  24. package/dist/types/article.ts +22 -0
  25. package/dist/types/footer.ts +119 -22
  26. package/dist/types/header.ts +70 -0
  27. package/dist/types/layout.ts +71 -10
  28. package/dist/types/main.ts +69 -0
  29. package/dist/types/meta.ts +50 -0
  30. package/dist/types/sidebar.ts +38 -0
  31. package/package.json +2 -2
  32. package/dist/components/layouts/DefaultLayout.astro +0 -170
  33. package/dist/components/layouts/DocumentationLayout.astro +0 -624
  34. package/dist/components/layouts/LandingLayout.astro +0 -388
@@ -1,624 +0,0 @@
1
- ---
2
- /**
3
- * DocumentationLayout组件
4
- *
5
- * 适用于文档页面的布局,包含侧边栏导航和目录
6
- *
7
- * 布局效果:
8
- *
9
- * 移动端:
10
- * ```
11
- * +------------------+
12
- * | Header |
13
- * +------------------+
14
- * | Sidebar (1 line) |
15
- * +------------------+
16
- * | |
17
- * | Main Content |
18
- * | |
19
- * | |
20
- * +------------------+
21
- * | Footer |
22
- * +------------------+
23
- * ```
24
- *
25
- * 桌面端:
26
- * ```
27
- * +------------------+
28
- * | Header |
29
- * +--------+---------+
30
- * | | |
31
- * |Sidebar | Content |
32
- * | | |
33
- * | | |
34
- * +--------+---------+
35
- * | Footer |
36
- * +------------------+
37
- * ```
38
- *
39
- * @example
40
- * ```astro
41
- * ---
42
- * import DocumentationLayout from '../layouts/DocumentationLayout.astro';
43
- *
44
- * const sidebarItems = [
45
- * { title: "入门", items: [
46
- * { href: "/docs/getting-started", text: "快速开始" },
47
- * { href: "/docs/installation", text: "安装" }
48
- * ]},
49
- * { title: "组件", items: [
50
- * { href: "/docs/components/button", text: "Button 按钮" },
51
- * { href: "/docs/components/card", text: "Card 卡片" }
52
- * ]}
53
- * ];
54
- * ---
55
- *
56
- * <DocumentationLayout
57
- * title="文档标题"
58
- * description="文档描述"
59
- * sidebarItems={sidebarItems}
60
- * >
61
- * <h1>文档内容</h1>
62
- * <p>这是文档的主要内容</p>
63
- * </DocumentationLayout>
64
- * ```
65
- *
66
- * 自定义页脚示例:
67
- * ```astro
68
- * <DocumentationLayout
69
- * title="文档标题"
70
- * description="文档描述"
71
- * sidebarItems={sidebarItems}
72
- * footerSlogan="简单而强大的组件库"
73
- * footerInspirationalSlogan="让开发更加愉悦"
74
- * footerSocialLinks={[
75
- * "https://github.com/myorg/myrepo",
76
- * "https://twitter.com/myorg"
77
- * ]}
78
- * footerProducts={[
79
- * { name: "组件库", href: "/components" },
80
- * { name: "模板", href: "/templates" }
81
- * ]}
82
- * >
83
- * <h1>文档内容</h1>
84
- * <p>这是文档的主要内容</p>
85
- * </DocumentationLayout>
86
- * ```
87
- *
88
- * 组件支持多种页脚相关的配置参数,可以通过以 `footer` 为前缀的属性来自定义页脚的内容和链接。
89
- * 所有这些参数都是可选的,组件会为常用参数提供默认值。
90
- *
91
- * 全宽内容区域示例:
92
- * ```astro
93
- * <DocumentationLayout
94
- * title="文档标题"
95
- * description="文档描述"
96
- * sidebarItems={sidebarItems}
97
- * contentFullWidth={true}
98
- * >
99
- * <!-- 全宽Hero部分,无需容器限制 -->
100
- * <div class="cosy:bg-primary cosy:p-10 cosy:text-white cosy:text-center">
101
- * <h1 class="cosy:text-3xl">全宽Hero部分</h1>
102
- * <p class="cosy:mt-4">没有容器限制,宽度可以100%占满</p>
103
- * </div>
104
- *
105
- * <!-- 自定义容器部分 -->
106
- * <div class="cosy:mx-auto cosy:p-6 cosy:container">
107
- * <p>在全宽模式下,您可以自行控制内容的容器和间距</p>
108
- * <p>这使得创建全宽背景的同时,保持内容在合适的宽度内</p>
109
- * </div>
110
- *
111
- * <!-- 另一个全宽部分 -->
112
- * <div class="cosy:bg-accent cosy:mt-8 cosy:p-10">
113
- * <div class="cosy:mx-auto cosy:container">
114
- * <h2 class="cosy:text-2xl">灵活的布局</h2>
115
- * <p>您可以自由组合全宽区域和容器限制区域</p>
116
- * </div>
117
- * </div>
118
- * </DocumentationLayout>
119
- * ```
120
- *
121
- * 调试模式示例:
122
- * ```astro
123
- * <DocumentationLayout
124
- * title="文档标题"
125
- * description="文档描述"
126
- * sidebarItems={sidebarItems}
127
- * debug={true}
128
- * >
129
- * <h1>文档内容</h1>
130
- * <p>这是文档的主要内容</p>
131
- * </DocumentationLayout>
132
- * ```
133
- */
134
-
135
- // 导入样式
136
- import '../../app.css';
137
-
138
- import BaseLayout from './BaseLayout.astro';
139
- import TableOfContents from '../navigation/TableOfContents.astro';
140
- import Article from '../typography/Article.astro';
141
- import Footer from './Footer.astro';
142
- import Main from '../containers/Main.astro';
143
- import Header from './Header.astro';
144
- import Sidebar from './Sidebar.astro';
145
- import DefaultLogo from '../../assets/logo.png';
146
- import { getText } from '../../utils/i18n';
147
- import { getValidLanguage } from '../../utils/language';
148
-
149
- export interface SidebarItem {
150
- href: string;
151
- text: string;
152
- items?: SidebarItem[];
153
- }
154
-
155
- export interface SidebarSection {
156
- title: string;
157
- items: SidebarItem[];
158
- }
159
-
160
- export interface Props {
161
- /**
162
- * 页面标题
163
- */
164
- title: string;
165
-
166
- /**
167
- * 页面描述
168
- */
169
- description?: string;
170
-
171
- /**
172
- * 页面关键词
173
- */
174
- keywords?: string;
175
-
176
- /**
177
- * 网站名称
178
- * @default "文档中心"
179
- */
180
- siteName?: string;
181
-
182
- /**
183
- * Logo图片
184
- * @default "/logo.svg"
185
- */
186
- logo?: ImageMetadata;
187
-
188
- /**
189
- * Logo链接地址
190
- * @default "/"
191
- */
192
- logoHref?: string;
193
-
194
- /**
195
- * 侧边栏项目
196
- */
197
- sidebarItems: SidebarSection[];
198
-
199
- /**
200
- * 是否显示侧边栏
201
- * @default true
202
- */
203
- showSidebar?: boolean;
204
-
205
- /**
206
- * 是否显示目录
207
- * @default true
208
- */
209
- showTableOfContents?: boolean;
210
-
211
- /**
212
- * 是否显示页眉
213
- * @default true
214
- */
215
- showHeader?: boolean;
216
-
217
- /**
218
- * 是否显示页脚
219
- * @default true
220
- */
221
- showFooter?: boolean;
222
-
223
- /**
224
- * 自定义头部内容
225
- */
226
- head?: astroHTML.JSX.Element;
227
-
228
- /**
229
- * 页面类名
230
- */
231
- class?: string;
232
-
233
- /**
234
- * 类名列表
235
- */
236
- 'class:list'?: any;
237
-
238
- /**
239
- * 调试模式,显示各个部分的边框
240
- * @default false
241
- */
242
- debug?: boolean;
243
-
244
- /**
245
- * 导航项目
246
- */
247
- navItems?: Array<{
248
- href: string;
249
- label: string;
250
- match: (path: string) => boolean;
251
- }>;
252
-
253
- /**
254
- * 语言列表
255
- */
256
- languages?: Array<{ code: string; name: string }>;
257
-
258
- /**
259
- * 当前语言
260
- */
261
- currentLocale?: string;
262
-
263
- /**
264
- * 基础路径,用于处理网站部署在二级目录的情况
265
- * @default ""
266
- */
267
- basePath?: string;
268
-
269
- /**
270
- * Header 组件的高度
271
- * @default "md"
272
- */
273
- headerHeight?: '3xs' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
274
-
275
- /**
276
- * 内容区域是否全宽
277
- *
278
- * 当设置为 true 时:
279
- * - 内容区域将占满整个可用宽度
280
- * - 不会应用默认的容器和内边距
281
- * - 用户需要自行控制内容的布局、容器和边距
282
- * - 适合创建全宽背景的hero区域、分栏布局等
283
- * - 目录导航会固定在页面右侧
284
- *
285
- * 当设置为 false 时(默认):
286
- * - 内容区域会有固定的最大宽度和内边距
287
- * - 使用标准的文档布局
288
- *
289
- * @default false
290
- *
291
- * @example
292
- * ```astro
293
- * <DocumentationLayout contentFullWidth={true}>
294
- * <!-- 内容将占满整个宽度 -->
295
- * </DocumentationLayout>
296
- * ```
297
- */
298
- contentFullWidth?: boolean;
299
-
300
- /**
301
- * 页脚相关配置
302
- */
303
- // Footer 相关参数
304
- /**
305
- * 页脚标语
306
- * @default "优雅、高效的组件库"
307
- */
308
- footerSlogan?: string;
309
-
310
- /**
311
- * 公司名称
312
- * @default 与siteName相同
313
- */
314
- footerCompany?: string;
315
-
316
- /**
317
- * 版权信息
318
- * @default "保留所有权利"
319
- */
320
- footerCopyright?: string;
321
-
322
- /**
323
- * 页脚横幅标语
324
- * @default "构建美好的数字体验"
325
- */
326
- footerInspirationalSlogan?: string;
327
-
328
- /**
329
- * ICP备案号
330
- */
331
- footerIcp?: string;
332
-
333
- /**
334
- * 网站Logo
335
- */
336
- footerLogo?: { src: string; alt: string };
337
-
338
- /**
339
- * 产品链接列表
340
- */
341
- footerProducts?: Array<{ name: string; href: string; external?: boolean }>;
342
-
343
- /**
344
- * 关于我们链接
345
- * @default "/about"
346
- */
347
- footerAboutLink?: string;
348
-
349
- /**
350
- * 联系我们链接
351
- * @default "/contact"
352
- */
353
- footerContactLink?: string;
354
-
355
- /**
356
- * 服务条款链接
357
- */
358
- footerTermsLink?: string;
359
-
360
- /**
361
- * 隐私政策链接
362
- */
363
- footerPrivacyLink?: string;
364
-
365
- /**
366
- * 社交媒体链接列表
367
- */
368
- footerSocialLinks?: string[];
369
-
370
- /**
371
- * 团队介绍链接
372
- */
373
- footerTeamLink?: string;
374
-
375
- /**
376
- * 加入我们链接
377
- */
378
- footerCareersLink?: string;
379
-
380
- /**
381
- * 新闻动态链接
382
- */
383
- footerNewsLink?: string;
384
-
385
- /**
386
- * 发展历程链接
387
- */
388
- footerHistoryLink?: string;
389
-
390
- /**
391
- * 合作伙伴链接
392
- */
393
- footerPartnersLink?: string;
394
-
395
- /**
396
- * 技术博客链接
397
- */
398
- footerBlogLink?: string;
399
-
400
- /**
401
- * 常见问题链接
402
- */
403
- footerFaqLink?: string;
404
-
405
- /**
406
- * 媒体报道链接
407
- */
408
- footerMediaLink?: string;
409
-
410
- /**
411
- * 技术栈链接
412
- */
413
- footerTechStackLink?: string;
414
-
415
- /**
416
- * 首页链接
417
- */
418
- footerHomeLink?: string;
419
-
420
- /**
421
- * 是否默认展开侧边栏(移动端)
422
- * @default false
423
- */
424
- defaultSidebarOpen?: boolean;
425
- }
426
-
427
- const {
428
- title,
429
- description,
430
- keywords,
431
- siteName = '文档中心',
432
- logo = DefaultLogo,
433
- logoHref = '/',
434
- sidebarItems,
435
- showSidebar = true,
436
- showTableOfContents = true,
437
- showHeader = true,
438
- showFooter = true,
439
- head,
440
- class: className,
441
- 'class:list': classList,
442
- debug = true,
443
- navItems,
444
- languages,
445
- currentLocale,
446
- basePath = '',
447
- headerHeight = 'md',
448
- contentFullWidth = false,
449
- footerHomeLink,
450
- footerSlogan,
451
- footerCompany,
452
- footerCopyright,
453
- footerInspirationalSlogan,
454
- footerIcp,
455
- footerLogo,
456
- footerProducts,
457
- footerAboutLink,
458
- footerContactLink,
459
- footerTermsLink,
460
- footerPrivacyLink,
461
- footerSocialLinks,
462
- footerTeamLink,
463
- footerCareersLink,
464
- footerNewsLink,
465
- footerHistoryLink,
466
- footerPartnersLink,
467
- footerBlogLink,
468
- footerFaqLink,
469
- footerMediaLink,
470
- footerTechStackLink,
471
- defaultSidebarOpen = false,
472
- ...rest
473
- } = Astro.props;
474
-
475
- // 获取当前路径,并处理基础路径
476
- const currentPath = Astro.url.pathname;
477
-
478
- // 获取有效的语言代码
479
- const validLang = getValidLanguage(currentLocale);
480
-
481
- // 根据header高度设置侧边栏top值
482
- const sidebarTopClasses = {
483
- '3xs': 'cosy:top-4',
484
- '2xs': 'cosy:top-6',
485
- xs: 'cosy:top-8',
486
- sm: 'cosy:top-10',
487
- md: 'cosy:top-12',
488
- lg: 'cosy:top-16',
489
- xl: 'cosy:top-20',
490
- };
491
- const sidebarTopClass = sidebarTopClasses[headerHeight];
492
- ---
493
-
494
- <BaseLayout
495
- title={title}
496
- description={description}
497
- keywords={keywords}
498
- head={head}
499
- class:list={[
500
- 'cosy:min-h-screen cosy:flex cosy:flex-col',
501
- { 'cosy:border cosy:border-base-300': debug },
502
- ]}
503
- {...rest}>
504
- {
505
- showHeader && (
506
- <Header
507
- logo={logo}
508
- logoHref={logoHref}
509
- navItems={navItems}
510
- languages={languages}
511
- currentLocale={currentLocale}
512
- sticky={true}
513
- basePath={basePath}
514
- showSidebarToggle={showSidebar && true}
515
- defaultSidebarOpen={defaultSidebarOpen}
516
- height={headerHeight}
517
- transition:persist
518
- />
519
- )
520
- }
521
-
522
- <div class="cosy:flex cosy:lg:flex-row cosy:flex-col cosy:flex-1">
523
- <div class="cosy:flex cosy:flex-row cosy:flex-1 cosy:pb-0 cosy:min-h-screen">
524
- <!-- 侧边栏容器 -->
525
- {
526
- showSidebar && (
527
- <div class={`${sidebarTopClass} cosy:z-10 cosy:sticky cosy:bg-base-100 cosy:h-screen`}>
528
- <Sidebar
529
- sidebarItems={sidebarItems}
530
- currentPath={currentPath}
531
- debug={debug}
532
- class="cosy:lg:border-r cosy:border-b cosy:border-base-300 cosy:lg:border-b-0 cosy:lg:w-64 cosy:lg:shrink-0"
533
- />
534
- </div>
535
- )
536
- }
537
-
538
- <!-- 主内容区域 -->
539
- <Main size="full" padding="none">
540
- {
541
- !contentFullWidth ? (
542
- <div class="cosy:mx-auto cosy:px-4 lg:cosy:px-8 cosy:container">
543
- <div class="cosy:flex cosy:lg:flex-row cosy:flex-col cosy:justify-center cosy:gap-8 cosy:pb-96">
544
- <Article class="cosy:flex-1 xl:cosy:w-[calc(100%-16rem)]">
545
- <slot />
546
- </Article>
547
-
548
- {showTableOfContents && <TableOfContents lang={currentLocale} />}
549
- </div>
550
- </div>
551
- ) : (
552
- <div class="cosy:flex cosy:flex-row cosy:w-full">
553
- <div class="cosy:flex-1">
554
- <Article class="cosy:flex-1" width="full">
555
- <slot />
556
- </Article>
557
- </div>
558
- {showTableOfContents && (
559
- <div class="cosy:hidden cosy:md:block cosy:p-4 cosy:w-64 cosy:shrink-0">
560
- <div class="cosy:top-24 cosy:sticky">
561
- <TableOfContents lang={currentLocale} />
562
- </div>
563
- </div>
564
- )}
565
- </div>
566
- )
567
- }
568
- </Main>
569
- </div>
570
- </div>
571
-
572
- {
573
- showFooter && (
574
- <Footer
575
- siteName={siteName}
576
- lang={currentLocale}
577
- homeLink={footerHomeLink || '/'}
578
- slogan={
579
- footerSlogan ||
580
- getText(validLang, 'footer', 'slogan') ||
581
- getText(validLang, 'footer', 'defaultSlogan')
582
- }
583
- company={footerCompany || siteName}
584
- copyright={footerCopyright || getText(validLang, 'footer', 'copyright')}
585
- inspirationalSlogan={
586
- footerInspirationalSlogan || getText(validLang, 'footer', 'inspirationalSlogan')
587
- }
588
- aboutLink={footerAboutLink || '/about'}
589
- contactLink={footerContactLink || '/contact'}
590
- icp={footerIcp}
591
- logo={footerLogo}
592
- products={footerProducts}
593
- termsLink={footerTermsLink}
594
- privacyLink={footerPrivacyLink}
595
- socialLinks={footerSocialLinks}
596
- teamLink={footerTeamLink}
597
- careersLink={footerCareersLink}
598
- newsLink={footerNewsLink}
599
- historyLink={footerHistoryLink}
600
- partnersLink={footerPartnersLink}
601
- blogLink={footerBlogLink}
602
- faqLink={footerFaqLink}
603
- mediaLink={footerMediaLink}
604
- techStackLink={footerTechStackLink}
605
- />
606
- )
607
- }
608
-
609
- <script>
610
- // Handle sidebar toggle
611
- const sidebarToggle = document.getElementById('sidebar-toggle');
612
- const sidebar = document.getElementById('sidebar-mobile');
613
- const sidebarOverlay = document.getElementById('sidebar-overlay');
614
-
615
- function toggleSidebar() {
616
- sidebar?.classList.toggle('cosy:hidden');
617
- sidebarOverlay?.classList.toggle('cosy:hidden');
618
- document.body.classList.toggle('cosy:overflow-hidden');
619
- }
620
-
621
- sidebarToggle?.addEventListener('click', toggleSidebar);
622
- sidebarOverlay?.addEventListener('click', toggleSidebar);
623
- </script>
624
- </BaseLayout>