@coffic/cosy-ui 0.9.26 → 0.9.28
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.
- package/dist/app.css +1 -1
- package/dist/src/assets/iconData.ts +10 -0
- package/dist/src-astro/alert/Alert.astro +10 -8
- package/dist/src-astro/alert-dialog/AlertDialog.astro +7 -4
- package/dist/src-astro/badge/Badge.astro +26 -6
- package/dist/src-astro/button/Button.astro +20 -0
- package/dist/src-astro/card/Card.astro +20 -20
- package/dist/src-astro/card-course/CardCourse.astro +11 -12
- package/dist/src-astro/card-course/types.ts +6 -6
- package/dist/src-astro/container/Container.astro +45 -40
- package/dist/src-astro/icons/ChevronLeftIcon.astro +31 -0
- package/dist/src-astro/icons/ChevronRightIcon.astro +31 -0
- package/dist/src-astro/icons/index.ts +2 -0
- package/dist/src-astro/layout-app/AppHeader.astro +1 -1
- package/dist/src-astro/layout-app/AppLayout.astro +24 -24
- package/dist/src-astro/layout-app/SkeletonLoader.astro +1 -1
- package/dist/src-astro/link/Link.astro +63 -53
- package/dist/src-astro/link/index.ts +2 -17
- package/dist/src-astro/link/types.ts +102 -0
- package/dist/src-astro/placeholder/PlaceHolder.astro +15 -15
- package/dist/src-astro/placeholder/types.ts +6 -6
- package/dist/src-astro/toc/TableOfContents.astro +53 -76
- package/dist/src-astro/toc/index.ts +1 -9
- package/package.json +1 -1
- package/dist/src-astro/link/LinkAnimations.astro +0 -29
- package/dist/src-astro/link/LinkBasic.astro +0 -17
- package/dist/src-astro/link/LinkVariants.astro +0 -20
- package/dist/src-astro/toc/TableOfContentsBasic.astro +0 -25
|
@@ -13,6 +13,29 @@
|
|
|
13
13
|
* 3. 一致性 - 保持与整体设计系统的一致性
|
|
14
14
|
* 4. 可访问性 - 确保链接可被键盘导航和屏幕阅读器识别
|
|
15
15
|
*
|
|
16
|
+
* @props
|
|
17
|
+
* @prop {string} [active=false] - 是否为激活状态
|
|
18
|
+
* @prop {string} [align] - 对齐方式:left、center、right
|
|
19
|
+
* @prop {string} [animation='none'] - 动画效果:none、hover-lift、hover-glow、hover-scale
|
|
20
|
+
* @prop {boolean} [block=false] - 是否为块级显示
|
|
21
|
+
* @prop {boolean} [btn=false] - 是否启用按钮风格
|
|
22
|
+
* @prop {boolean} [circle=false] - 是否为圆形按钮(需配合 btn 使用)
|
|
23
|
+
* @prop {string} [class] - 自定义 CSS 类名
|
|
24
|
+
* @prop {any} [class:list] - 类名列表
|
|
25
|
+
* @prop {string} [color] - 按钮颜色(需配合 btn 使用):primary、secondary、accent、info、success、warning、error
|
|
26
|
+
* @prop {boolean} [debug=false] - 是否显示调试边框
|
|
27
|
+
* @prop {boolean} [external=false] - 是否为外部链接,自动新窗口打开
|
|
28
|
+
* @prop {boolean} [fullWidth=false] - 是否占满宽度
|
|
29
|
+
* @prop {boolean} [ghost=false] - 是否为幽灵按钮(需配合 btn 使用)
|
|
30
|
+
* @prop {string} href - 链接地址(必需)
|
|
31
|
+
* @prop {string} [icon] - 图标名称,支持所有可用的图标组件
|
|
32
|
+
* @prop {string} [navigationType] - 导航类型(需配合 navigation 变体使用):previous、next
|
|
33
|
+
* @prop {boolean} [noUnderline=true] - 是否移除下划线
|
|
34
|
+
* @prop {boolean} [rounded=false] - 是否添加圆角
|
|
35
|
+
* @prop {string} [size='md'] - 尺寸大小:sm、md、lg
|
|
36
|
+
* @prop {string} [variant='default'] - 样式变体:default、primary、secondary、text、cta、ghost、light、navigation、github
|
|
37
|
+
* @prop {...HTMLAttributes<'a'>} [rest] - 其他 HTML <a> 标签属性
|
|
38
|
+
*
|
|
16
39
|
* @usage
|
|
17
40
|
* 基本用法:
|
|
18
41
|
* ```astro
|
|
@@ -31,6 +54,19 @@
|
|
|
31
54
|
* <Link href="/docs" variant="text">查看文档</Link>
|
|
32
55
|
* <Link href="/get-started" variant="cta">立即开始</Link>
|
|
33
56
|
* <Link href="/preview" variant="ghost">预览</Link>
|
|
57
|
+
* <Link href="/previous" variant="navigation" navigationType="previous">上一页</Link>
|
|
58
|
+
* <Link href="/next" variant="navigation" navigationType="next">下一页</Link>
|
|
59
|
+
* <Link href="https://github.com/user/repo" variant="github">GitHub 仓库</Link>
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* 图标支持:
|
|
63
|
+
* ```astro
|
|
64
|
+
* <Link href="/home" icon="HomeIcon">首页</Link>
|
|
65
|
+
* <Link href="/settings" icon="SettingsIcon">设置</Link>
|
|
66
|
+
* <Link href="/search" icon="SearchIcon">搜索</Link>
|
|
67
|
+
* <Link href="/user" icon="UserIcon">用户</Link>
|
|
68
|
+
* <Link href="/mail" icon="MailIcon">邮件</Link>
|
|
69
|
+
* <Link href="/download" icon="DownloadIcon">下载</Link>
|
|
34
70
|
* ```
|
|
35
71
|
*
|
|
36
72
|
* 块级显示:
|
|
@@ -52,56 +88,20 @@
|
|
|
52
88
|
* <Link href="/medium" size="md">中型链接</Link>
|
|
53
89
|
* <Link href="/large" size="lg">大型链接</Link>
|
|
54
90
|
* ```
|
|
91
|
+
*
|
|
92
|
+
* 按钮风格:
|
|
93
|
+
* ```astro
|
|
94
|
+
* <Link href="/signup" btn>按钮链接</Link>
|
|
95
|
+
* <Link href="/ghost" btn ghost>幽灵按钮</Link>
|
|
96
|
+
* <Link href="/circle" btn circle>圆形按钮</Link>
|
|
97
|
+
* <Link href="/full" btn fullWidth>全宽按钮</Link>
|
|
98
|
+
* ```
|
|
55
99
|
*/
|
|
56
100
|
|
|
57
101
|
import '../../style.ts';
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// 定义链接尺寸类型
|
|
62
|
-
type LinkSize = 'sm' | 'md' | 'lg';
|
|
63
|
-
|
|
64
|
-
// 定义链接变体类型
|
|
65
|
-
type LinkVariant =
|
|
66
|
-
| 'default'
|
|
67
|
-
| 'primary'
|
|
68
|
-
| 'secondary'
|
|
69
|
-
| 'text'
|
|
70
|
-
| 'cta'
|
|
71
|
-
| 'ghost'
|
|
72
|
-
| 'light';
|
|
73
|
-
|
|
74
|
-
// 定义链接动画类型
|
|
75
|
-
type LinkAnimation = 'none' | 'hover-lift' | 'hover-glow' | 'hover-scale';
|
|
76
|
-
|
|
77
|
-
interface Props extends HTMLAttributes<'a'> {
|
|
78
|
-
href: string;
|
|
79
|
-
external?: boolean;
|
|
80
|
-
block?: boolean;
|
|
81
|
-
class?: string;
|
|
82
|
-
'class:list'?: any;
|
|
83
|
-
variant?: LinkVariant;
|
|
84
|
-
animation?: LinkAnimation;
|
|
85
|
-
size?: LinkSize;
|
|
86
|
-
debug?: boolean;
|
|
87
|
-
centerText?: boolean;
|
|
88
|
-
btn?: boolean;
|
|
89
|
-
circle?: boolean;
|
|
90
|
-
ghost?: boolean;
|
|
91
|
-
noUnderline?: boolean;
|
|
92
|
-
rounded?: boolean;
|
|
93
|
-
fullWidth?: boolean;
|
|
94
|
-
color?:
|
|
95
|
-
| 'primary'
|
|
96
|
-
| 'secondary'
|
|
97
|
-
| 'accent'
|
|
98
|
-
| 'info'
|
|
99
|
-
| 'success'
|
|
100
|
-
| 'warning'
|
|
101
|
-
| 'error';
|
|
102
|
-
align?: 'left' | 'center' | 'right';
|
|
103
|
-
active?: boolean;
|
|
104
|
-
}
|
|
102
|
+
import { ChevronLeftIcon, ChevronRightIcon, GithubIcon } from '../icons';
|
|
103
|
+
// 导入所有图标组件
|
|
104
|
+
import * as Icons from '../icons';
|
|
105
105
|
|
|
106
106
|
const {
|
|
107
107
|
href,
|
|
@@ -113,7 +113,6 @@ const {
|
|
|
113
113
|
class: className = '',
|
|
114
114
|
'class:list': classList,
|
|
115
115
|
debug = false,
|
|
116
|
-
centerText = false,
|
|
117
116
|
btn = false,
|
|
118
117
|
circle = false,
|
|
119
118
|
ghost = false,
|
|
@@ -123,9 +122,14 @@ const {
|
|
|
123
122
|
color,
|
|
124
123
|
align,
|
|
125
124
|
active = false,
|
|
125
|
+
navigationType,
|
|
126
|
+
icon,
|
|
126
127
|
...rest
|
|
127
128
|
} = Astro.props;
|
|
128
129
|
|
|
130
|
+
// 获取图标组件
|
|
131
|
+
const IconComponent = icon ? (Icons as any)[icon] : null;
|
|
132
|
+
|
|
129
133
|
// 构建类名
|
|
130
134
|
const classes = [
|
|
131
135
|
// 基础链接样式
|
|
@@ -134,6 +138,9 @@ const classes = [
|
|
|
134
138
|
// 显示方式
|
|
135
139
|
block ? 'cosy:flex cosy:w-full' : 'cosy:inline-flex',
|
|
136
140
|
|
|
141
|
+
// 图标和文字间距(当有图标时添加间距)
|
|
142
|
+
icon && 'cosy:gap-2',
|
|
143
|
+
|
|
137
144
|
// 变体样式
|
|
138
145
|
variant === 'primary' && 'cosy:text-primary cosy:hover:text-primary-focus',
|
|
139
146
|
variant === 'secondary' &&
|
|
@@ -147,6 +154,10 @@ const classes = [
|
|
|
147
154
|
'cosy:text-base-content cosy:hover:text-base-content/90',
|
|
148
155
|
variant === 'light' &&
|
|
149
156
|
'cosy:text-white cosy:hover:text-white/90 cosy:font-medium',
|
|
157
|
+
variant === 'navigation' &&
|
|
158
|
+
'cosy:flex cosy:items-center cosy:gap-3 cosy:p-4 cosy:bg-base-100 cosy:border cosy:border-base-300 cosy:rounded-lg cosy:shadow-sm cosy:hover:shadow-md cosy:hover:border-base-400 cosy:transition-all cosy:duration-300 cosy:ease-in-out cosy:no-underline cosy:hover:no-underline cosy:font-medium cosy:text-base-content cosy:hover:text-base-content cosy:hover:-translate-y-1 cosy:hover:scale-[1.01] cosy:backdrop-blur-sm cosy:hover:backdrop-blur-md',
|
|
159
|
+
variant === 'github' &&
|
|
160
|
+
'cosy:flex cosy:items-center cosy:gap-2 cosy:text-base-content cosy:hover:text-base-content/80 cosy:transition-colors cosy:duration-200 cosy:no-underline cosy:hover:no-underline cosy:font-medium',
|
|
150
161
|
|
|
151
162
|
// 尺寸样式
|
|
152
163
|
size === 'sm' && 'cosy:text-sm',
|
|
@@ -192,11 +203,6 @@ const classes = [
|
|
|
192
203
|
className,
|
|
193
204
|
];
|
|
194
205
|
|
|
195
|
-
// 文本居中样式(兼容旧用法)
|
|
196
|
-
if (centerText) {
|
|
197
|
-
classes.push('cosy:justify-center cosy:text-center');
|
|
198
|
-
}
|
|
199
|
-
|
|
200
206
|
// 调试样式
|
|
201
207
|
if (debug) {
|
|
202
208
|
classes.push('cosy:border cosy:border-dashed cosy:border-red-500');
|
|
@@ -208,5 +214,9 @@ if (debug) {
|
|
|
208
214
|
class:list={[classes, classList]}
|
|
209
215
|
{...external ? { target: '_blank', rel: 'noopener noreferrer' } : {}}
|
|
210
216
|
{...rest}>
|
|
217
|
+
{navigationType === 'previous' && <ChevronLeftIcon />}
|
|
218
|
+
{variant === 'github' && <GithubIcon />}
|
|
219
|
+
{IconComponent && <IconComponent />}
|
|
211
220
|
<slot />
|
|
221
|
+
{navigationType === 'next' && <ChevronRightIcon />}
|
|
212
222
|
</a>
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import LinkVariants from './LinkVariants.astro';
|
|
4
|
-
import LinkAnimations from './LinkAnimations.astro';
|
|
5
|
-
import BasicSourceCode from './LinkBasic.astro?raw';
|
|
6
|
-
import VariantsSourceCode from './LinkVariants.astro?raw';
|
|
7
|
-
import AnimationsSourceCode from './LinkAnimations.astro?raw';
|
|
8
|
-
import { extractSimpleExample } from '../../src/utils/component';
|
|
9
|
-
|
|
10
|
-
export { Link, LinkBasic, LinkVariants, LinkAnimations };
|
|
11
|
-
|
|
12
|
-
// 导出示例源代码
|
|
13
|
-
export const LinkExampleCodes = {
|
|
14
|
-
Basic: extractSimpleExample(BasicSourceCode, 'Link'),
|
|
15
|
-
Variants: extractSimpleExample(VariantsSourceCode, 'Link'),
|
|
16
|
-
Animations: extractSimpleExample(AnimationsSourceCode, 'Link'),
|
|
17
|
-
};
|
|
1
|
+
export { default as Link } from './Link.astro';
|
|
2
|
+
export type { LinkProps } from './types';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
2
|
+
|
|
3
|
+
// 定义链接尺寸类型
|
|
4
|
+
export type LinkSize = 'sm' | 'md' | 'lg';
|
|
5
|
+
|
|
6
|
+
// 定义链接变体类型
|
|
7
|
+
export type LinkVariant =
|
|
8
|
+
| 'default'
|
|
9
|
+
| 'primary'
|
|
10
|
+
| 'secondary'
|
|
11
|
+
| 'text'
|
|
12
|
+
| 'cta'
|
|
13
|
+
| 'ghost'
|
|
14
|
+
| 'light'
|
|
15
|
+
| 'navigation'
|
|
16
|
+
| 'github';
|
|
17
|
+
|
|
18
|
+
// 定义链接动画类型
|
|
19
|
+
export type LinkAnimation = 'none' | 'hover-lift' | 'hover-glow' | 'hover-scale';
|
|
20
|
+
|
|
21
|
+
// 定义图标类型(排除需要特殊属性的组件)
|
|
22
|
+
export type LinkIconName =
|
|
23
|
+
| 'AlertTriangle'
|
|
24
|
+
| 'AppStoreIcon'
|
|
25
|
+
| 'CalendarIcon'
|
|
26
|
+
| 'ChartIcon'
|
|
27
|
+
| 'CheckCircle'
|
|
28
|
+
| 'CheckIcon'
|
|
29
|
+
| 'ChevronDownIcon'
|
|
30
|
+
| 'ChevronLeftIcon'
|
|
31
|
+
| 'ChevronRightIcon'
|
|
32
|
+
| 'ClipboardIcon'
|
|
33
|
+
| 'CloseIcon'
|
|
34
|
+
| 'CodeIcon'
|
|
35
|
+
| 'DashboardIcon'
|
|
36
|
+
| 'DeleteIcon'
|
|
37
|
+
| 'DocumentIcon'
|
|
38
|
+
| 'DownloadIcon'
|
|
39
|
+
| 'EditIcon'
|
|
40
|
+
| 'ErrorIcon'
|
|
41
|
+
| 'FolderIcon'
|
|
42
|
+
| 'GithubIcon'
|
|
43
|
+
| 'GlobeIcon'
|
|
44
|
+
| 'HeartIcon'
|
|
45
|
+
| 'HomeIcon'
|
|
46
|
+
| 'InfoCircle'
|
|
47
|
+
| 'InfoIcon'
|
|
48
|
+
| 'InboxArchive'
|
|
49
|
+
| 'LinkIcon'
|
|
50
|
+
| 'LinkedinIcon'
|
|
51
|
+
| 'LogOut'
|
|
52
|
+
| 'MailIcon'
|
|
53
|
+
| 'MenuIcon'
|
|
54
|
+
| 'MessageIcon'
|
|
55
|
+
| 'NotificationIcon'
|
|
56
|
+
| 'RefreshIcon'
|
|
57
|
+
| 'ReportIcon'
|
|
58
|
+
| 'SaveIcon'
|
|
59
|
+
| 'SearchIcon'
|
|
60
|
+
| 'SecurityIcon'
|
|
61
|
+
| 'SettingsIcon'
|
|
62
|
+
| 'StarIcon'
|
|
63
|
+
| 'SunCloudyIcon'
|
|
64
|
+
| 'ToolsIcon'
|
|
65
|
+
| 'TwitterIcon'
|
|
66
|
+
| 'UploadIcon'
|
|
67
|
+
| 'UserIcon'
|
|
68
|
+
| 'UsersIcon'
|
|
69
|
+
| 'WalletIcon'
|
|
70
|
+
| 'WarningIcon'
|
|
71
|
+
| 'WebsiteIcon'
|
|
72
|
+
| 'XCircle';
|
|
73
|
+
|
|
74
|
+
export interface LinkProps extends HTMLAttributes<'a'> {
|
|
75
|
+
href: string;
|
|
76
|
+
external?: boolean;
|
|
77
|
+
block?: boolean;
|
|
78
|
+
class?: string;
|
|
79
|
+
'class:list'?: any;
|
|
80
|
+
variant?: LinkVariant;
|
|
81
|
+
animation?: LinkAnimation;
|
|
82
|
+
size?: LinkSize;
|
|
83
|
+
debug?: boolean;
|
|
84
|
+
btn?: boolean;
|
|
85
|
+
circle?: boolean;
|
|
86
|
+
ghost?: boolean;
|
|
87
|
+
noUnderline?: boolean;
|
|
88
|
+
rounded?: boolean;
|
|
89
|
+
fullWidth?: boolean;
|
|
90
|
+
color?:
|
|
91
|
+
| 'primary'
|
|
92
|
+
| 'secondary'
|
|
93
|
+
| 'accent'
|
|
94
|
+
| 'info'
|
|
95
|
+
| 'success'
|
|
96
|
+
| 'warning'
|
|
97
|
+
| 'error';
|
|
98
|
+
align?: 'left' | 'center' | 'right';
|
|
99
|
+
active?: boolean;
|
|
100
|
+
navigationType?: 'previous' | 'next';
|
|
101
|
+
icon?: LinkIconName;
|
|
102
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
/**
|
|
3
3
|
* @component PlaceHolder
|
|
4
|
-
* @description
|
|
4
|
+
* @description 占位符组件,用于在布局中占用指定的空间,支持自定义宽度、高度、内边距和背景色
|
|
5
5
|
* @usage
|
|
6
6
|
* ```astro
|
|
7
7
|
* <PlaceHolder width="md" height="lg" padding="md" background="base-200">
|
|
@@ -9,19 +9,21 @@
|
|
|
9
9
|
* </PlaceHolder>
|
|
10
10
|
* ```
|
|
11
11
|
* @props
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* @prop {string} [background] - 背景色类名,可选值:base-100、base-200、base-300、primary、secondary、accent、info、success、warning、error
|
|
13
|
+
* @prop {string} [class] - 自定义 CSS 类名,用于添加额外的样式
|
|
14
|
+
* @prop {string} [height='md'] - 高度尺寸,可选值:none、xs、sm、md、lg、xl、2xl、3xl、4xl、5xl、6xl、full
|
|
15
|
+
* @prop {string} [padding='none'] - 内边距大小,可选值:none、xs、sm、md、lg、xl
|
|
16
|
+
* @prop {string} [width='md'] - 宽度尺寸,可选值:none、xs、sm、md、lg、xl、2xl、3xl、4xl、5xl、6xl、full
|
|
17
17
|
* @slots
|
|
18
|
-
*
|
|
18
|
+
* @slot default - 占位符内容
|
|
19
19
|
*/
|
|
20
20
|
import '../../style.ts';
|
|
21
21
|
import type { PlaceHolderProps } from './types';
|
|
22
22
|
|
|
23
23
|
interface Props extends PlaceHolderProps {
|
|
24
|
-
|
|
24
|
+
background?: string;
|
|
25
|
+
class?: string;
|
|
26
|
+
height?:
|
|
25
27
|
| 'none'
|
|
26
28
|
| 'xs'
|
|
27
29
|
| 'sm'
|
|
@@ -34,7 +36,8 @@ interface Props extends PlaceHolderProps {
|
|
|
34
36
|
| '5xl'
|
|
35
37
|
| '6xl'
|
|
36
38
|
| 'full';
|
|
37
|
-
|
|
39
|
+
padding?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
40
|
+
width?:
|
|
38
41
|
| 'none'
|
|
39
42
|
| 'xs'
|
|
40
43
|
| 'sm'
|
|
@@ -47,17 +50,14 @@ interface Props extends PlaceHolderProps {
|
|
|
47
50
|
| '5xl'
|
|
48
51
|
| '6xl'
|
|
49
52
|
| 'full';
|
|
50
|
-
padding?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
51
|
-
background?: string;
|
|
52
|
-
class?: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
const {
|
|
56
|
-
width = 'md',
|
|
57
|
-
height = 'md',
|
|
58
|
-
padding = 'none',
|
|
59
56
|
background,
|
|
60
57
|
class: className = '',
|
|
58
|
+
height = 'md',
|
|
59
|
+
padding = 'none',
|
|
60
|
+
width = 'md',
|
|
61
61
|
} = Astro.props;
|
|
62
62
|
|
|
63
63
|
// 宽度样式映射
|
|
@@ -3,14 +3,14 @@ export type PlaceHolderHeight = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl
|
|
|
3
3
|
export type PlaceHolderPadding = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
4
4
|
|
|
5
5
|
export interface PlaceHolderProps {
|
|
6
|
-
/** 占位符宽度 */
|
|
7
|
-
width?: PlaceHolderWidth;
|
|
8
|
-
/** 占位符高度 */
|
|
9
|
-
height?: PlaceHolderHeight;
|
|
10
|
-
/** 内边距大小 */
|
|
11
|
-
padding?: PlaceHolderPadding;
|
|
12
6
|
/** 背景色类名,如 'base-200', 'primary', 'secondary' */
|
|
13
7
|
background?: string;
|
|
14
8
|
/** 自定义 CSS 类名 */
|
|
15
9
|
class?: string;
|
|
10
|
+
/** 占位符高度 */
|
|
11
|
+
height?: PlaceHolderHeight;
|
|
12
|
+
/** 内边距大小 */
|
|
13
|
+
padding?: PlaceHolderPadding;
|
|
14
|
+
/** 占位符宽度 */
|
|
15
|
+
width?: PlaceHolderWidth;
|
|
16
16
|
}
|
|
@@ -1,111 +1,85 @@
|
|
|
1
1
|
---
|
|
2
2
|
/**
|
|
3
3
|
* @component TableOfContents
|
|
4
|
+
* @description 目录导航组件,用于显示页面内容的标题结构,自动检测页面中的标题元素,生成目录列表,并在用户滚动页面时高亮当前可见的标题
|
|
5
|
+
* @usage 用于创建页面内容的目录导航,帮助用户快速了解页面结构和导航到特定内容
|
|
6
|
+
* @props
|
|
7
|
+
* @prop {string} [class] - 自定义 CSS 类名,用于覆盖默认样式
|
|
8
|
+
* @prop {string} [containerSelector='main'] - 内容容器选择器,用于限制标题搜索范围
|
|
9
|
+
* @prop {boolean} [fixed=true] - 是否固定在右侧,设置为 false 时目录会跟随内容流
|
|
10
|
+
* @prop {string} [lang] - 语言设置,默认自动检测当前语言环境
|
|
11
|
+
* @prop {number} [maxDepth=3] - 最大深度,控制目录显示的标题级别
|
|
12
|
+
* @prop {number} [minHeadings=2] - 显示目录所需的最少标题数量,少于此时目录会自动隐藏
|
|
13
|
+
* @prop {string} [selector='h2, h3'] - 标题选择器,用于指定要包含在目录中的标题元素
|
|
14
|
+
* @prop {string} [title] - 目录标题文本,默认根据语言自动选择
|
|
15
|
+
* @slots
|
|
16
|
+
* @slot default - 目录内容(通常为空,内容由 JavaScript 动态生成)
|
|
4
17
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* 4. 响应式设计 - 在小屏幕设备上自动隐藏,优化空间利用
|
|
16
|
-
* 5. 智能显示 - 当页面结构不需要目录时自动隐藏
|
|
17
|
-
* 6. 多语言支持 - 支持多种语言显示,自动检测当前语言环境
|
|
18
|
-
*
|
|
19
|
-
* @usage
|
|
20
|
-
* 基本用法:
|
|
21
|
-
* ```astro
|
|
22
|
-
* <TableOfContents />
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* 自定义标题和选择器:
|
|
26
|
-
* ```astro
|
|
27
|
-
* <TableOfContents
|
|
28
|
-
* title="章节导航"
|
|
29
|
-
* selector="h2, h3, h4"
|
|
30
|
-
* maxDepth={4}
|
|
31
|
-
* />
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* 非固定位置:
|
|
35
|
-
* ```astro
|
|
36
|
-
* <TableOfContents fixed={false} />
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* 指定内容容器:
|
|
40
|
-
* ```astro
|
|
41
|
-
* <TableOfContents containerSelector=".article-content" />
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* 指定语言:
|
|
45
|
-
* ```astro
|
|
46
|
-
* <TableOfContents lang="zh-cn" />
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* 启用日志:
|
|
50
|
-
* ```astro
|
|
51
|
-
* <TableOfContents enableLogging={true} />
|
|
52
|
-
* ```
|
|
18
|
+
* 功能特性:
|
|
19
|
+
* - 自动检测页面标题结构
|
|
20
|
+
* - 智能显示/隐藏(根据标题数量)
|
|
21
|
+
* - 滚动时高亮当前标题
|
|
22
|
+
* - 平滑滚动到目标位置
|
|
23
|
+
* - 响应式设计(小屏幕自动隐藏)
|
|
24
|
+
* - 多语言支持
|
|
25
|
+
* - 支持自定义容器和选择器
|
|
26
|
+
* - 自动生成标题 ID
|
|
27
|
+
* - 排除特定标题(通过 ignore-heading 属性)
|
|
53
28
|
*/
|
|
54
|
-
|
|
55
|
-
// 导入样式
|
|
56
29
|
import '../../style.ts';
|
|
57
30
|
import { createTextGetter } from '../../src/utils/i18n.ts';
|
|
58
31
|
import { LanguageUtil } from '../../src/utils/language.ts';
|
|
59
32
|
|
|
60
33
|
interface Props {
|
|
34
|
+
/**
|
|
35
|
+
* 自定义 CSS 类名
|
|
36
|
+
*/
|
|
37
|
+
class?: string;
|
|
38
|
+
/**
|
|
39
|
+
* 内容容器选择器,用于限制标题搜索范围
|
|
40
|
+
* @default "main"
|
|
41
|
+
*/
|
|
42
|
+
containerSelector?: string;
|
|
61
43
|
/**
|
|
62
44
|
* 是否固定在右侧
|
|
63
45
|
* @default true
|
|
64
46
|
*/
|
|
65
47
|
fixed?: boolean;
|
|
66
48
|
/**
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
class?: string;
|
|
70
|
-
/**
|
|
71
|
-
* 标题选择器
|
|
72
|
-
* @default "h2, h3"
|
|
49
|
+
* 语言设置
|
|
50
|
+
* @default 自动检测
|
|
73
51
|
*/
|
|
74
|
-
|
|
52
|
+
lang?: string;
|
|
75
53
|
/**
|
|
76
54
|
* 最大深度
|
|
77
55
|
* @default 3
|
|
78
56
|
*/
|
|
79
57
|
maxDepth?: number;
|
|
80
|
-
/**
|
|
81
|
-
* 标题文本
|
|
82
|
-
* @default 根据语言自动选择
|
|
83
|
-
*/
|
|
84
|
-
title?: string;
|
|
85
|
-
/**
|
|
86
|
-
* 内容容器选择器,用于限制标题搜索范围
|
|
87
|
-
* @default "main"
|
|
88
|
-
*/
|
|
89
|
-
containerSelector?: string;
|
|
90
58
|
/**
|
|
91
59
|
* 显示目录所需的最少标题数量
|
|
92
60
|
* @default 2
|
|
93
61
|
*/
|
|
94
62
|
minHeadings?: number;
|
|
95
63
|
/**
|
|
96
|
-
*
|
|
97
|
-
* @default
|
|
64
|
+
* 标题选择器
|
|
65
|
+
* @default "h2, h3"
|
|
98
66
|
*/
|
|
99
|
-
|
|
67
|
+
selector?: string;
|
|
68
|
+
/**
|
|
69
|
+
* 目录标题文本
|
|
70
|
+
* @default 根据语言自动选择
|
|
71
|
+
*/
|
|
72
|
+
title?: string;
|
|
100
73
|
}
|
|
101
74
|
|
|
102
75
|
const {
|
|
103
|
-
fixed = true,
|
|
104
76
|
class: className = '',
|
|
105
|
-
selector = 'h2, h3',
|
|
106
|
-
maxDepth = 3,
|
|
107
77
|
containerSelector = 'main',
|
|
78
|
+
fixed = true,
|
|
79
|
+
lang,
|
|
80
|
+
maxDepth = 3,
|
|
108
81
|
minHeadings = 2,
|
|
82
|
+
selector = 'h2, h3',
|
|
109
83
|
title,
|
|
110
84
|
} = Astro.props;
|
|
111
85
|
|
|
@@ -121,13 +95,16 @@ const tocId = `toc-${Math.random().toString(36).substring(2, 9)}`;
|
|
|
121
95
|
---
|
|
122
96
|
|
|
123
97
|
<aside
|
|
124
|
-
class:list={[
|
|
98
|
+
class:list={[
|
|
99
|
+
'cosy:hidden cosy:xl:block cosy:w-64 cosy:pr-3 cosy:shrink-0',
|
|
100
|
+
className,
|
|
101
|
+
]}>
|
|
125
102
|
<div class="cosy:top-18 cosy:sticky">
|
|
126
103
|
<div
|
|
127
|
-
class={`toc-container toc-scroll-container ${fixed ? 'cosy:w-
|
|
104
|
+
class={`toc-container toc-scroll-container ${fixed ? 'cosy:w-60' : 'cosy:w-full cosy:max-w-xs'}`}
|
|
128
105
|
id={`${tocId}-container`}
|
|
129
106
|
style="display: none;">
|
|
130
|
-
<div class="cosy:bg-base-
|
|
107
|
+
<div class="cosy:bg-base-200 cosy:shadow-inner cosy:card">
|
|
131
108
|
<div class="cosy:p-4 cosy:card-body">
|
|
132
109
|
<div class="cosy:mb-2 cosy:font-bold cosy:text-lg cosy:card-title">
|
|
133
110
|
{titleText}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import TableOfContents from './TableOfContents.astro';
|
|
2
|
-
import TableOfContentsBasic from './TableOfContentsBasic.astro';
|
|
3
|
-
import BasicSourceCode from './TableOfContentsBasic.astro?raw';
|
|
4
|
-
import { extractSimpleExample } from '../../src/utils/component';
|
|
5
2
|
|
|
6
|
-
export { TableOfContents
|
|
7
|
-
|
|
8
|
-
// 导出示例源代码
|
|
9
|
-
export const TableOfContentsExampleCodes = {
|
|
10
|
-
Basic: extractSimpleExample(BasicSourceCode, 'TableOfContents'),
|
|
11
|
-
};
|
|
3
|
+
export { TableOfContents };
|
package/package.json
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import Link from './Link.astro';
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
<div class="cosy:space-y-4">
|
|
6
|
-
<div class="cosy:flex cosy:gap-4">
|
|
7
|
-
<Link href="/hover-lift" animation="hover-lift" variant="primary">
|
|
8
|
-
上浮效果
|
|
9
|
-
</Link>
|
|
10
|
-
|
|
11
|
-
<Link href="/hover-glow" animation="hover-glow" variant="secondary">
|
|
12
|
-
发光效果
|
|
13
|
-
</Link>
|
|
14
|
-
|
|
15
|
-
<Link href="/hover-scale" animation="hover-scale" variant="cta">
|
|
16
|
-
缩放效果
|
|
17
|
-
</Link>
|
|
18
|
-
</div>
|
|
19
|
-
|
|
20
|
-
<div class="cosy:flex cosy:gap-4">
|
|
21
|
-
<Link href="/block-link" block centerText variant="primary">
|
|
22
|
-
块级居中链接
|
|
23
|
-
</Link>
|
|
24
|
-
</div>
|
|
25
|
-
|
|
26
|
-
<div class="cosy:bg-base-200 cosy:p-4">
|
|
27
|
-
<Link href="/light-variant" variant="light"> 浅色背景中的链接 </Link>
|
|
28
|
-
</div>
|
|
29
|
-
</div>
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import Link from './Link.astro';
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
<div class="cosy:space-y-4">
|
|
6
|
-
<div>
|
|
7
|
-
<Link href="/about">默认链接</Link>
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
<div>
|
|
11
|
-
<Link href="https://example.com" external>外部链接</Link>
|
|
12
|
-
</div>
|
|
13
|
-
|
|
14
|
-
<div>
|
|
15
|
-
<p>这是一段文字,其中包含一个<Link href="/inline">内联链接</Link>。</p>
|
|
16
|
-
</div>
|
|
17
|
-
</div>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import Link from './Link.astro';
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
<div class="cosy:space-y-4">
|
|
6
|
-
<div class="cosy:flex cosy:gap-4">
|
|
7
|
-
<Link href="/signup" variant="primary">主要链接</Link>
|
|
8
|
-
<Link href="/learn-more" variant="secondary">次要链接</Link>
|
|
9
|
-
<Link href="/docs" variant="text">文本链接</Link>
|
|
10
|
-
<Link href="/get-started" variant="cta">行动号召</Link>
|
|
11
|
-
<Link href="/preview" variant="ghost">幽灵链接</Link>
|
|
12
|
-
<Link href="/help" variant="light">浅色链接</Link>
|
|
13
|
-
</div>
|
|
14
|
-
|
|
15
|
-
<div class="cosy:flex cosy:gap-4">
|
|
16
|
-
<Link href="/small" size="sm">小型链接</Link>
|
|
17
|
-
<Link href="/medium" size="md">中型链接</Link>
|
|
18
|
-
<Link href="/large" size="lg">大型链接</Link>
|
|
19
|
-
</div>
|
|
20
|
-
</div>
|