@coffic/cosy-ui 0.3.15 → 0.3.35

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,186 +1,91 @@
1
1
  ---
2
2
  /**
3
3
  * @component Alert
4
- *
4
+ *
5
5
  * @description
6
6
  * Alert 组件用于向用户显示重要的提示信息,支持多种类型的提示样式和交互效果。
7
- *
8
- * @design
9
- * 设计理念:
10
- * 1. 简洁明了 - 使用清晰的视觉层次和颜色编码传达信息的重要性和类型
11
- * 2. 响应式交互 - 提供丰富的动画和交互反馈,增强用户体验
12
- * 3. 可定制性 - 支持多种配置选项,适应不同场景需求
13
- * 4. 无障碍性 - 遵循 WAI-ARIA 实践,确保所有用户都能获得良好体验
14
- *
15
- * 视觉特点:
16
- * - 入场/退出动画:平滑的滑入/滑出效果
17
- * - 悬停效果:轻微上浮和阴影增强
18
- * - 图标动画:悬停时轻微放大
19
- * - 左侧彩色边框:直观区分不同类型的提示
20
- * - 进度条:自动关闭时的视觉倒计时
21
- *
7
+ *
22
8
  * @usage
23
9
  * 基本用法:
24
10
  * ```astro
25
11
  * <Alert type="info">这是一条信息提示</Alert>
26
12
  * ```
27
- *
13
+ *
28
14
  * 带标题:
29
15
  * ```astro
30
16
  * <Alert type="success" title="操作成功">您的操作已成功完成</Alert>
31
17
  * ```
32
- *
33
- * 可关闭的提示:
34
- * ```astro
35
- * <Alert type="warning" closeable={true}>请注意这个警告信息</Alert>
36
- * ```
37
- *
38
- * 自动关闭:
39
- * ```astro
40
- * <Alert type="success" autoClose={5000}>5秒后自动关闭</Alert>
41
- * ```
42
- *
18
+ *
43
19
  * 组合使用:
44
20
  * ```astro
45
- * <Alert
46
- * type="error"
47
- * title="提交失败"
48
- * closeable={true}
49
- * autoClose={10000}
21
+ * <Alert
22
+ * type="error"
23
+ * title="提交失败"
50
24
  * class="my-custom-class"
51
25
  * >
52
26
  * 请检查表单并重新提交
53
27
  * </Alert>
54
28
  * ```
55
- *
29
+ *
56
30
  * @props
57
31
  * @prop {('info'|'success'|'warning'|'error')} [type='info'] - 提示类型,影响颜色和图标
58
32
  * @prop {string} [title] - 提示标题,可选
59
- * @prop {boolean} [closeable=false] - 是否显示关闭按钮
60
33
  * @prop {string} [class] - 自定义 CSS 类名
61
- * @prop {number} [autoClose] - 自动关闭的时间(毫秒),不设置则不自动关闭
62
- *
34
+ *
63
35
  * @slots
64
36
  * @slot default - 提示内容
65
- *
66
- * @cssVariables
67
- * 组件内部使用的 CSS 变量:
68
- * --auto-close-duration: 进度条动画持续时间,自动设置为 autoClose 属性值
69
- *
70
- * @accessibility
71
- * - 使用适当的 ARIA 角色(role="alert")
72
- * - 关闭按钮带有描述性 aria-label
73
- * - 动画遵循 prefers-reduced-motion 媒体查询(待实现)
74
- *
75
- * @dependencies
76
- * 依赖于以下图标组件:
77
- * - InfoIcon, SuccessIcon, WarningIcon, ErrorIcon, CloseIcon
78
37
  */
79
38
 
80
- // 导入样式
81
- import "../../app.css";
82
-
39
+ // 导入其他资源必须使用相对路径
40
+ import '../../app.css';
83
41
  import { InfoIcon, SuccessIcon, WarningIcon, ErrorIcon, CloseIcon } from '../../index';
84
42
 
85
43
  interface Props {
86
- type?: 'info' | 'success' | 'warning' | 'error';
87
- title?: string;
88
- closeable?: boolean;
89
- class?: string;
90
- autoClose?: number; // 自动关闭的时间(毫秒),如果不设置则不自动关闭
44
+ type?: 'info' | 'success' | 'warning' | 'error';
45
+ title?: string;
46
+ class?: string;
91
47
  }
92
48
 
93
- const {
94
- type = 'info',
95
- title,
96
- closeable = false,
97
- class: className = '',
98
- autoClose,
99
- } = Astro.props;
49
+ const { type = 'info', title, class: className = '' } = Astro.props;
100
50
 
101
51
  // 根据类型设置样式
102
52
  const alertClass = {
103
- info: 'cosy:alert-info',
104
- success: 'cosy:alert-success',
105
- warning: 'cosy:alert-warning',
106
- error: 'cosy:alert-error',
53
+ info: 'cosy:alert-info',
54
+ success: 'cosy:alert-success',
55
+ warning: 'cosy:alert-warning',
56
+ error: 'cosy:alert-error',
107
57
  }[type as 'info' | 'success' | 'warning' | 'error'];
108
58
 
109
59
  // 根据类型设置图标组件
110
60
  const IconComponent = {
111
- info: InfoIcon,
112
- success: SuccessIcon,
113
- warning: WarningIcon,
114
- error: ErrorIcon,
61
+ info: InfoIcon,
62
+ success: SuccessIcon,
63
+ warning: WarningIcon,
64
+ error: ErrorIcon,
115
65
  }[type as 'info' | 'success' | 'warning' | 'error'];
116
66
  ---
117
67
 
118
- <div class={`cosy:alert ${alertClass} ${className}`} role="alert" data-auto-close={autoClose}>
119
- <div class="cosy:alert-content">
120
- <div class="cosy:alert-icon">
121
- <IconComponent />
122
- </div>
123
- <div class="cosy:alert-body">
124
- {title && <h3 class="cosy:alert-title">{title}</h3>}
125
- <div class="cosy:alert-message"><slot /></div>
126
- </div>
127
- {closeable && (
128
- <button class="cosy:alert-close-btn" aria-label="关闭提示">
129
- <CloseIcon />
130
- </button>
131
- )}
132
- </div>
133
- {autoClose && <div class="cosy:alert-progress"></div>}
134
- </div>
135
-
136
- <script define:vars={{ closeable, autoClose }}>
137
- /**
138
- * 初始化所有 Alert 组件
139
- * 设置关闭按钮事件和自动关闭功能
140
- */
141
- function initializeAlerts() {
142
- const alerts = document.querySelectorAll('.cosy\\:alert');
143
-
144
- alerts.forEach(alert => {
145
- // 设置关闭按钮
146
- if (closeable) {
147
- const closeBtn = alert.querySelector('.cosy\\:alert-close-btn');
148
- if (closeBtn) {
149
- closeBtn.addEventListener('click', () => closeAlert(alert));
150
- }
151
- }
152
-
153
- // 设置自动关闭
154
- const autoCloseTime = alert.dataset.autoClose;
155
- if (autoCloseTime) {
156
- // 设置进度条动画时间
157
- alert.style.setProperty('--auto-close-duration', `${autoCloseTime}ms`);
158
-
159
- // 设置定时器自动关闭
160
- setTimeout(() => {
161
- closeAlert(alert);
162
- }, parseInt(autoCloseTime));
163
- }
164
- });
165
- }
166
-
167
- /**
168
- * 关闭 Alert 的动画处理
169
- * @param {HTMLElement} alert - 要关闭的 Alert 元素
170
- */
171
- function closeAlert(alert) {
172
- // 添加关闭动画类
173
- alert.classList.add('cosy:closing');
174
-
175
- // 动画结束后移除元素
176
- setTimeout(() => {
177
- alert.remove();
178
- }, 300); // 与动画时长相匹配
179
- }
68
+ <div class={`cosy:alert ${alertClass} ${className}`} role="alert">
69
+ <div class="cosy:alert-content cosy:flex cosy:flex-row cosy:gap-4 cosy:items-center">
70
+ <IconComponent />
180
71
 
181
- // 初始化
182
- initializeAlerts();
72
+ <div class="cosy:flex cosy:items-center cosy:h-full cosy:flex-col">
73
+ {
74
+ title && (
75
+ <h3 class="cosy:font-bold" style="margin-top: 0 !important">
76
+ {title}
77
+ </h3>
78
+ )
79
+ }
80
+ {
81
+ title && (
82
+ <div class="cosy:text-xs">
83
+ <slot />
84
+ </div>
85
+ )
86
+ }
183
87
 
184
- // Astro 页面切换时重新初始化
185
- document.addEventListener('astro:page-load', initializeAlerts);
186
- </script>
88
+ {!title && <slot />}
89
+ </div>
90
+ </div>
91
+ </div>