@coffic/cosy-ui 0.8.7 → 0.8.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.
- package/dist/app.css +1 -1
- package/dist/src-astro/alert/index.ts +7 -15
- package/dist/src-astro/assets/iconData.ts +211 -106
- package/dist/src-astro/button/index_astro.ts +2 -56
- package/dist/src-astro/card/CardCourse.astro +31 -11
- package/dist/src-astro/card/index.ts +15 -25
- package/dist/src-astro/code-container/CodeContainer.astro +205 -5
- package/dist/src-astro/code-container/index.ts +9 -13
- package/dist/src-astro/contact/index.ts +16 -20
- package/dist/src-astro/errors/index.ts +0 -62
- package/dist/src-astro/footer/index.ts +1 -30
- package/dist/src-astro/header/Header.astro +1 -2
- package/dist/src-astro/header/index.ts +1 -40
- package/dist/src-astro/hero/Hero.astro +1 -1
- package/dist/src-astro/hero/index.ts +1 -39
- package/dist/src-astro/icons/ChartIcon.astro +28 -0
- package/dist/src-astro/icons/DashboardIcon.astro +28 -0
- package/dist/src-astro/icons/DeleteIcon.astro +28 -0
- package/dist/src-astro/icons/DocumentIcon.astro +28 -0
- package/dist/src-astro/icons/DownloadIcon.astro +28 -0
- package/dist/src-astro/icons/EditIcon.astro +28 -0
- package/dist/src-astro/icons/FolderIcon.astro +28 -0
- package/dist/src-astro/icons/HeartIcon.astro +28 -0
- package/dist/src-astro/icons/HomeIcon.astro +28 -0
- package/dist/src-astro/icons/MailIcon.astro +28 -0
- package/dist/src-astro/icons/MessageIcon.astro +28 -0
- package/dist/src-astro/icons/NotificationIcon.astro +28 -0
- package/dist/src-astro/icons/RefreshIcon.astro +28 -0
- package/dist/src-astro/icons/ReportIcon.astro +28 -0
- package/dist/src-astro/icons/SaveIcon.astro +28 -0
- package/dist/src-astro/icons/SecurityIcon.astro +28 -0
- package/dist/src-astro/icons/StarIcon.astro +28 -0
- package/dist/src-astro/icons/ToolsIcon.astro +28 -0
- package/dist/src-astro/icons/UploadIcon.astro +28 -0
- package/dist/src-astro/icons/UsersIcon.astro +28 -0
- package/dist/src-astro/icons/WalletIcon.astro +28 -0
- package/dist/src-astro/icons/index.ts +21 -0
- package/dist/src-astro/layout-app/index.ts +5 -9
- package/dist/src-astro/layout-dashboard/DashboardLayout.astro +101 -555
- package/dist/src-astro/layout-dashboard/DashboardSidebar.astro +206 -0
- package/dist/src-astro/layout-dashboard/DashboardTopNavbar.astro +132 -0
- package/dist/src-astro/layout-dashboard/index.ts +14 -8
- package/dist/src-astro/layout-dashboard/tools.ts +0 -0
- package/dist/src-astro/layout-dashboard/types.ts +313 -0
- package/package.json +4 -4
- package/dist/src-astro/alert/EAlertBasic.astro +0 -11
- package/dist/src-astro/alert/EAlertBasicContainer.astro +0 -11
- package/dist/src-astro/alert/EAlertCustomStyle.astro +0 -16
- package/dist/src-astro/alert/EAlertCustomStyleContainer.astro +0 -11
- package/dist/src-astro/alert/EAlertError.astro +0 -6
- package/dist/src-astro/alert/EAlertInfo.astro +0 -6
- package/dist/src-astro/alert/EAlertSuccess.astro +0 -6
- package/dist/src-astro/alert/EAlertTypesContainer.astro +0 -43
- package/dist/src-astro/alert/EAlertWarning.astro +0 -6
- package/dist/src-astro/alert/EAlertWithTitle.astro +0 -12
- package/dist/src-astro/alert/EAlertWithTitleContainer.astro +0 -11
- package/dist/src-astro/button/ButtonBasic.astro +0 -18
- package/dist/src-astro/button/ButtonBasicContainer.astro +0 -11
- package/dist/src-astro/button/ButtonBlock.astro +0 -5
- package/dist/src-astro/button/ButtonError.astro +0 -5
- package/dist/src-astro/button/ButtonGhost.astro +0 -5
- package/dist/src-astro/button/ButtonIconBoth.astro +0 -9
- package/dist/src-astro/button/ButtonIconLeft.astro +0 -8
- package/dist/src-astro/button/ButtonIconRight.astro +0 -8
- package/dist/src-astro/button/ButtonInfo.astro +0 -5
- package/dist/src-astro/button/ButtonLinkContainer.astro +0 -19
- package/dist/src-astro/button/ButtonNeutral.astro +0 -5
- package/dist/src-astro/button/ButtonOutline.astro +0 -5
- package/dist/src-astro/button/ButtonShapeCircle.astro +0 -5
- package/dist/src-astro/button/ButtonShapeDefault.astro +0 -5
- package/dist/src-astro/button/ButtonShapeSquare.astro +0 -5
- package/dist/src-astro/button/ButtonShapes.astro +0 -23
- package/dist/src-astro/button/ButtonShapesContainer.astro +0 -29
- package/dist/src-astro/button/ButtonSizes.astro +0 -15
- package/dist/src-astro/button/ButtonSizesContainer.astro +0 -11
- package/dist/src-astro/button/ButtonStates.astro +0 -12
- package/dist/src-astro/button/ButtonStatesContainer.astro +0 -11
- package/dist/src-astro/button/ButtonSuccess.astro +0 -5
- package/dist/src-astro/button/ButtonVariantsContainer.astro +0 -73
- package/dist/src-astro/button/ButtonWarning.astro +0 -5
- package/dist/src-astro/button/ButtonWide.astro +0 -5
- package/dist/src-astro/button/ButtonWidth.astro +0 -8
- package/dist/src-astro/button/ButtonWidthContainer.astro +0 -19
- package/dist/src-astro/button/ButtonWithIcons.astro +0 -25
- package/dist/src-astro/button/ButtonWithIconsContainer.astro +0 -29
- package/dist/src-astro/card/CardBasic.astro +0 -5
- package/dist/src-astro/card/ECardBasic.astro +0 -13
- package/dist/src-astro/card/ECardBasicContainer.astro +0 -11
- package/dist/src-astro/card/ECardClickable.astro +0 -16
- package/dist/src-astro/card/ECardClickableContainer.astro +0 -11
- package/dist/src-astro/card/ECardCompact.astro +0 -13
- package/dist/src-astro/card/ECardCompactContainer.astro +0 -11
- package/dist/src-astro/card/ECardCustomStyle.astro +0 -17
- package/dist/src-astro/card/ECardCustomStyleContainer.astro +0 -11
- package/dist/src-astro/card/ECardWithImage.astro +0 -16
- package/dist/src-astro/card/ECardWithImageContainer.astro +0 -11
- package/dist/src-astro/card/ECardWithSubtitle.astro +0 -13
- package/dist/src-astro/card/ECardWithSubtitleContainer.astro +0 -11
- package/dist/src-astro/code-container/ECodeContainerBasic.astro +0 -19
- package/dist/src-astro/code-container/ECodeContainerMultiple.astro +0 -49
- package/dist/src-astro/contact/EContactBasic.astro +0 -15
- package/dist/src-astro/contact/EContactBasicContainer.astro +0 -11
- package/dist/src-astro/contact/EContactCompact.astro +0 -11
- package/dist/src-astro/contact/EContactCompactContainer.astro +0 -11
- package/dist/src-astro/contact/EContactCustomStyle.astro +0 -21
- package/dist/src-astro/contact/EContactCustomStyleContainer.astro +0 -11
- package/dist/src-astro/contact/EContactSocial.astro +0 -20
- package/dist/src-astro/contact/EContactSocialContainer.astro +0 -11
- package/dist/src-astro/contact/EContactWithTitle.astro +0 -17
- package/dist/src-astro/contact/EContactWithTitleContainer.astro +0 -11
- package/dist/src-astro/errors/E403Basic.astro +0 -11
- package/dist/src-astro/errors/E403BasicContainer.astro +0 -20
- package/dist/src-astro/errors/E404Basic.astro +0 -11
- package/dist/src-astro/errors/E404BasicContainer.astro +0 -20
- package/dist/src-astro/errors/E404WithDebug.astro +0 -18
- package/dist/src-astro/errors/E500Basic.astro +0 -11
- package/dist/src-astro/errors/E500BasicContainer.astro +0 -20
- package/dist/src-astro/errors/E503Maintenance.astro +0 -20
- package/dist/src-astro/errors/E503MaintenanceContainer.astro +0 -21
- package/dist/src-astro/errors/EErrorPageCustomStyle.astro +0 -21
- package/dist/src-astro/errors/EErrorPageCustomStyleContainer.astro +0 -21
- package/dist/src-astro/errors/EErrorPageShowcase.astro +0 -68
- package/dist/src-astro/errors/EErrorPageShowcaseContainer.astro +0 -21
- package/dist/src-astro/footer/EFooterBasic.astro +0 -18
- package/dist/src-astro/footer/EFooterBasicContainer.astro +0 -11
- package/dist/src-astro/footer/EFooterComplete.astro +0 -50
- package/dist/src-astro/footer/EFooterCompleteContainer.astro +0 -11
- package/dist/src-astro/footer/EFooterFeaturesContainer.astro +0 -40
- package/dist/src-astro/footer/EFooterWithLogo.astro +0 -28
- package/dist/src-astro/footer/EFooterWithLogoContainer.astro +0 -11
- package/dist/src-astro/footer/EFooterWithNavigation.astro +0 -24
- package/dist/src-astro/footer/EFooterWithNavigationContainer.astro +0 -11
- package/dist/src-astro/footer/EFooterWithProducts.astro +0 -24
- package/dist/src-astro/footer/EFooterWithProductsContainer.astro +0 -11
- package/dist/src-astro/footer/EFooterWithSocial.astro +0 -24
- package/dist/src-astro/footer/EFooterWithSocialContainer.astro +0 -11
- package/dist/src-astro/header/HeaderBasic.astro +0 -19
- package/dist/src-astro/header/HeaderCustomNavbarCenter.astro +0 -28
- package/dist/src-astro/header/HeaderCustomNavbarEnd.astro +0 -25
- package/dist/src-astro/header/HeaderCustomNavbarStart.astro +0 -27
- package/dist/src-astro/header/HeaderCustomPosition.astro +0 -34
- package/dist/src-astro/header/HeaderWithNavigation.astro +0 -27
- package/dist/src-astro/hero/HeroAlignCenter.astro +0 -13
- package/dist/src-astro/hero/HeroAlignContainer.astro +0 -27
- package/dist/src-astro/hero/HeroAlignLeft.astro +0 -13
- package/dist/src-astro/hero/HeroAlignRight.astro +0 -13
- package/dist/src-astro/hero/HeroBackgroundContainer.astro +0 -18
- package/dist/src-astro/hero/HeroBackgroundImage.astro +0 -16
- package/dist/src-astro/hero/HeroBackgroundImageContainer.astro +0 -11
- package/dist/src-astro/hero/HeroBasic.astro +0 -12
- package/dist/src-astro/hero/HeroBasicContainer.astro +0 -11
- package/dist/src-astro/hero/HeroGradientBackground.astro +0 -10
- package/dist/src-astro/hero/HeroPlainBackground.astro +0 -10
- package/dist/src-astro/hero/HeroWithButton.astro +0 -15
- package/dist/src-astro/hero/HeroWithButtonContainer.astro +0 -11
- package/dist/src-astro/hero/HeroWithImage.astro +0 -16
- package/dist/src-astro/hero/HeroWithImageContainer.astro +0 -11
- package/dist/src-astro/layout-app/AppLayoutBasic.astro +0 -54
- package/dist/src-astro/layout-dashboard/DashboardLayoutBasic.astro +0 -51
@@ -0,0 +1,206 @@
|
|
1
|
+
---
|
2
|
+
/**
|
3
|
+
* @component DashboardSidebar
|
4
|
+
*
|
5
|
+
* @description
|
6
|
+
* DashboardSidebar 组件提供仪表盘布局的侧边栏导航功能。
|
7
|
+
* 包含系统名称显示、导航菜单和折叠/展开功能。
|
8
|
+
*
|
9
|
+
* @usage
|
10
|
+
* ```astro
|
11
|
+
* ---
|
12
|
+
* import { DashboardSidebar } from '@coffic/cosy-ui';
|
13
|
+
*
|
14
|
+
* const navItems = [
|
15
|
+
* { href: "/dashboard", icon: "home", text: "仪表盘" },
|
16
|
+
* { href: "/dashboard/users", icon: "user", text: "用户管理" }
|
17
|
+
* ];
|
18
|
+
* ---
|
19
|
+
*
|
20
|
+
* <DashboardSidebar
|
21
|
+
* systemName="管理系统"
|
22
|
+
* navItems={navItems}
|
23
|
+
* />
|
24
|
+
* ```
|
25
|
+
*
|
26
|
+
* @props
|
27
|
+
* - systemName?: string - 系统名称,默认为"管理系统"
|
28
|
+
* - navItems: NavItem[] - 导航项目
|
29
|
+
* - currentPath?: string - 当前路径,用于高亮当前页面
|
30
|
+
* - size?: 'sm' | 'md' | 'lg' | 'xl' - 侧边栏尺寸,默认为"md"
|
31
|
+
* - theme?: SidebarTheme - 侧边栏主题,默认为"default"
|
32
|
+
*/
|
33
|
+
|
34
|
+
import '../../style.ts';
|
35
|
+
import {
|
36
|
+
getNavItemIcon,
|
37
|
+
getSidebarWidth,
|
38
|
+
getSidebarTheme,
|
39
|
+
type NavItem,
|
40
|
+
type SidebarSize,
|
41
|
+
type SidebarTheme,
|
42
|
+
} from './types';
|
43
|
+
import AstroIcon from '../icons/AstroIcon.astro';
|
44
|
+
|
45
|
+
export interface Props {
|
46
|
+
/**
|
47
|
+
* 系统名称
|
48
|
+
* @default "管理系统"
|
49
|
+
*/
|
50
|
+
systemName?: string;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* 导航项目
|
54
|
+
*/
|
55
|
+
navItems: NavItem[];
|
56
|
+
|
57
|
+
/**
|
58
|
+
* 当前路径,用于高亮当前页面
|
59
|
+
*/
|
60
|
+
currentPath?: string;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* 侧边栏尺寸
|
64
|
+
* @default "md"
|
65
|
+
*/
|
66
|
+
size?: SidebarSize;
|
67
|
+
|
68
|
+
/**
|
69
|
+
* 侧边栏主题
|
70
|
+
* @default "default"
|
71
|
+
*/
|
72
|
+
theme?: SidebarTheme;
|
73
|
+
}
|
74
|
+
|
75
|
+
const {
|
76
|
+
systemName = '管理系统',
|
77
|
+
navItems,
|
78
|
+
currentPath = '',
|
79
|
+
size = 'md',
|
80
|
+
theme = 'default',
|
81
|
+
} = Astro.props;
|
82
|
+
|
83
|
+
const themeStyles = getSidebarTheme(theme);
|
84
|
+
---
|
85
|
+
|
86
|
+
<aside
|
87
|
+
class:list={[
|
88
|
+
getSidebarWidth(size),
|
89
|
+
'cosy:min-h-full',
|
90
|
+
themeStyles.bg,
|
91
|
+
themeStyles.textColor,
|
92
|
+
]}>
|
93
|
+
<!-- 侧边栏头部 -->
|
94
|
+
<div
|
95
|
+
class:list={[
|
96
|
+
'cosy:navbar cosy:border-b',
|
97
|
+
themeStyles.headerBg,
|
98
|
+
themeStyles.borderColor,
|
99
|
+
]}>
|
100
|
+
<div class="cosy:navbar-start">
|
101
|
+
<a
|
102
|
+
href="/dashboard"
|
103
|
+
class="cosy:btn cosy:btn-ghost cosy:text-lg cosy:font-semibold cosy:no-underline">
|
104
|
+
<span class="cosy:text-xl">⚡</span>
|
105
|
+
<span class="cosy:hidden cosy:lg:block">{systemName}</span>
|
106
|
+
</a>
|
107
|
+
</div>
|
108
|
+
<div class="cosy:navbar-end">
|
109
|
+
<button class="cosy:btn cosy:btn-ghost cosy:btn-sm" id="collapse-sidebar">
|
110
|
+
<AstroIcon name="menu" size="16px" stroke="currentColor" />
|
111
|
+
</button>
|
112
|
+
</div>
|
113
|
+
</div>
|
114
|
+
|
115
|
+
<!-- 导航菜单 -->
|
116
|
+
<ul
|
117
|
+
class="cosy:menu cosy:p-4 cosy:space-y-1 cosy:list-none cosy:no-underline">
|
118
|
+
{
|
119
|
+
navItems.map((item: NavItem) => {
|
120
|
+
const isActive =
|
121
|
+
currentPath === item.href ||
|
122
|
+
(item.items &&
|
123
|
+
item.items.some(
|
124
|
+
(subitem: NavItem) => currentPath === subitem.href
|
125
|
+
));
|
126
|
+
|
127
|
+
return (
|
128
|
+
<li>
|
129
|
+
<a
|
130
|
+
href={item.href}
|
131
|
+
class:list={['cosy:no-underline', { active: isActive }]}>
|
132
|
+
<AstroIcon
|
133
|
+
name={getNavItemIcon(item)}
|
134
|
+
size="16px"
|
135
|
+
stroke="currentColor"
|
136
|
+
/>
|
137
|
+
<span>{item.text}</span>
|
138
|
+
{item.badge && (
|
139
|
+
<span class="cosy:badge cosy:badge-primary cosy:badge-sm">
|
140
|
+
{item.badge}
|
141
|
+
</span>
|
142
|
+
)}
|
143
|
+
</a>
|
144
|
+
|
145
|
+
{item.items && (
|
146
|
+
<ul class="cosy:ml-4 cosy:list-none cosy:no-underline">
|
147
|
+
{item.items.map((subitem: NavItem) => {
|
148
|
+
const isSubActive = currentPath === subitem.href;
|
149
|
+
return (
|
150
|
+
<li>
|
151
|
+
<a
|
152
|
+
href={subitem.href}
|
153
|
+
class:list={[
|
154
|
+
'cosy:text-sm cosy:no-underline',
|
155
|
+
{ active: isSubActive },
|
156
|
+
]}>
|
157
|
+
<AstroIcon
|
158
|
+
name={getNavItemIcon(subitem)}
|
159
|
+
size="14px"
|
160
|
+
stroke="currentColor"
|
161
|
+
/>
|
162
|
+
<span>{subitem.text}</span>
|
163
|
+
{subitem.badge && (
|
164
|
+
<span class="cosy:badge cosy:badge-primary cosy:badge-xs">
|
165
|
+
{subitem.badge}
|
166
|
+
</span>
|
167
|
+
)}
|
168
|
+
</a>
|
169
|
+
</li>
|
170
|
+
);
|
171
|
+
})}
|
172
|
+
</ul>
|
173
|
+
)}
|
174
|
+
</li>
|
175
|
+
);
|
176
|
+
})
|
177
|
+
}
|
178
|
+
</ul>
|
179
|
+
</aside>
|
180
|
+
|
181
|
+
<script>
|
182
|
+
// 侧边栏折叠/展开功能
|
183
|
+
document.addEventListener('DOMContentLoaded', () => {
|
184
|
+
const collapseSidebarBtn = document.getElementById('collapse-sidebar');
|
185
|
+
const drawerToggle = document.getElementById(
|
186
|
+
'dashboard-drawer'
|
187
|
+
) as HTMLInputElement;
|
188
|
+
|
189
|
+
if (collapseSidebarBtn && drawerToggle) {
|
190
|
+
collapseSidebarBtn.addEventListener('click', () => {
|
191
|
+
drawerToggle.checked = !drawerToggle.checked;
|
192
|
+
// 保存状态到本地存储
|
193
|
+
localStorage.setItem(
|
194
|
+
'sidebarCollapsed',
|
195
|
+
drawerToggle.checked.toString()
|
196
|
+
);
|
197
|
+
});
|
198
|
+
}
|
199
|
+
|
200
|
+
// 从本地存储恢复状态
|
201
|
+
const savedState = localStorage.getItem('sidebarCollapsed');
|
202
|
+
if (savedState && drawerToggle) {
|
203
|
+
drawerToggle.checked = savedState === 'true';
|
204
|
+
}
|
205
|
+
});
|
206
|
+
</script>
|
@@ -0,0 +1,132 @@
|
|
1
|
+
---
|
2
|
+
/**
|
3
|
+
* @component DashboardTopNavbar
|
4
|
+
*
|
5
|
+
* @description
|
6
|
+
* DashboardTopNavbar 组件提供仪表盘布局的顶部导航栏功能。
|
7
|
+
* 包含菜单切换按钮、面包屑导航、搜索框、通知和用户信息。
|
8
|
+
*
|
9
|
+
* @usage
|
10
|
+
* ```astro
|
11
|
+
* ---
|
12
|
+
* import { DashboardTopNavbar } from '@coffic/cosy-ui';
|
13
|
+
* ---
|
14
|
+
*
|
15
|
+
* <DashboardTopNavbar
|
16
|
+
* title="仪表盘"
|
17
|
+
* userName="管理员"
|
18
|
+
* userAvatar="/avatar.jpg"
|
19
|
+
* />
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* @props
|
23
|
+
* - title: string - 页面标题,用于面包屑导航
|
24
|
+
* - userName?: string - 用户名
|
25
|
+
* - userAvatar?: string - 用户头像
|
26
|
+
*/
|
27
|
+
|
28
|
+
import '../../style.ts';
|
29
|
+
import AstroIcon from '../icons/AstroIcon.astro';
|
30
|
+
|
31
|
+
export interface Props {
|
32
|
+
/**
|
33
|
+
* 页面标题,用于面包屑导航
|
34
|
+
*/
|
35
|
+
title: string;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* 用户名
|
39
|
+
*/
|
40
|
+
userName?: string;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* 用户头像
|
44
|
+
*/
|
45
|
+
userAvatar?: string;
|
46
|
+
}
|
47
|
+
|
48
|
+
const { title, userName, userAvatar } = Astro.props;
|
49
|
+
---
|
50
|
+
|
51
|
+
<div class="cosy:navbar cosy:bg-base-100 cosy:shadow-sm">
|
52
|
+
<div class="cosy:navbar-start">
|
53
|
+
<label
|
54
|
+
for="dashboard-drawer"
|
55
|
+
class="cosy:btn cosy:btn-square cosy:btn-ghost cosy:lg:hidden">
|
56
|
+
<AstroIcon name="menu" size="18px" stroke="currentColor" />
|
57
|
+
</label>
|
58
|
+
|
59
|
+
<div class="cosy:breadcrumbs cosy:text-sm cosy:ml-4">
|
60
|
+
<ul>
|
61
|
+
<li><span class="cosy:text-base-content/70">{title}</span></li>
|
62
|
+
</ul>
|
63
|
+
</div>
|
64
|
+
</div>
|
65
|
+
|
66
|
+
<div class="cosy:navbar-end cosy:gap-2">
|
67
|
+
<!-- 搜索框 -->
|
68
|
+
<div class="cosy:form-control cosy:hidden cosy:lg:flex">
|
69
|
+
<div class="cosy:input-group">
|
70
|
+
<input
|
71
|
+
type="text"
|
72
|
+
placeholder="搜索..."
|
73
|
+
class="cosy:input cosy:input-bordered cosy:input-sm cosy:w-48"
|
74
|
+
/>
|
75
|
+
<button class="cosy:btn cosy:btn-square cosy:btn-sm">
|
76
|
+
<AstroIcon name="search" size="16px" stroke="currentColor" />
|
77
|
+
</button>
|
78
|
+
</div>
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<!-- 通知 -->
|
82
|
+
<div class="cosy:indicator">
|
83
|
+
<button class="cosy:btn cosy:btn-ghost cosy:btn-circle">
|
84
|
+
<AstroIcon name="notification" size="18px" stroke="currentColor" />
|
85
|
+
</button>
|
86
|
+
<span
|
87
|
+
class="cosy:badge cosy:badge-xs cosy:badge-primary cosy:indicator-item"
|
88
|
+
>3</span
|
89
|
+
>
|
90
|
+
</div>
|
91
|
+
|
92
|
+
<!-- 用户信息 -->
|
93
|
+
{
|
94
|
+
userName && (
|
95
|
+
<div class="cosy:dropdown cosy:dropdown-end">
|
96
|
+
<div
|
97
|
+
tabindex="0"
|
98
|
+
role="button"
|
99
|
+
class="cosy:btn cosy:btn-ghost cosy:gap-2">
|
100
|
+
{userAvatar ? (
|
101
|
+
<div class="cosy:avatar">
|
102
|
+
<div class="cosy:w-8 cosy:rounded-full">
|
103
|
+
<img src={userAvatar} alt={userName} />
|
104
|
+
</div>
|
105
|
+
</div>
|
106
|
+
) : (
|
107
|
+
<div class="cosy:avatar cosy:placeholder">
|
108
|
+
<div class="cosy:bg-primary cosy:text-primary-content cosy:rounded-full cosy:w-8">
|
109
|
+
<span class="cosy:text-sm">{userName.charAt(0)}</span>
|
110
|
+
</div>
|
111
|
+
</div>
|
112
|
+
)}
|
113
|
+
<span class="cosy:hidden cosy:lg:block">{userName}</span>
|
114
|
+
</div>
|
115
|
+
<ul
|
116
|
+
tabindex="0"
|
117
|
+
class="cosy:dropdown-content cosy:menu cosy:p-2 cosy:shadow cosy:bg-base-100 cosy:rounded-box cosy:w-52">
|
118
|
+
<li>
|
119
|
+
<a class="cosy:no-underline">个人资料</a>
|
120
|
+
</li>
|
121
|
+
<li>
|
122
|
+
<a class="cosy:no-underline">设置</a>
|
123
|
+
</li>
|
124
|
+
<li>
|
125
|
+
<a class="cosy:no-underline">退出登录</a>
|
126
|
+
</li>
|
127
|
+
</ul>
|
128
|
+
</div>
|
129
|
+
)
|
130
|
+
}
|
131
|
+
</div>
|
132
|
+
</div>
|
@@ -1,11 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import { extractSimpleExample } from '../utils/component';
|
1
|
+
/**
|
2
|
+
* 仪表盘布局组件
|
3
|
+
*/
|
5
4
|
|
6
|
-
|
5
|
+
import DashboardLayout from './DashboardLayout.astro';
|
6
|
+
import DashboardSidebar from './DashboardSidebar.astro';
|
7
|
+
import DashboardTopNavbar from './DashboardTopNavbar.astro';
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
export {
|
10
|
+
DashboardLayout,
|
11
|
+
DashboardSidebar,
|
12
|
+
DashboardTopNavbar
|
11
13
|
};
|
14
|
+
|
15
|
+
// 导出类型和函数
|
16
|
+
export type { NavItem, SidebarSize, SidebarTheme, ContentTheme } from './types';
|
17
|
+
export { getIconFromHref, getNavItemIcon, getSidebarWidth, getSidebarTheme, getContentTheme } from './types';
|
File without changes
|
@@ -0,0 +1,313 @@
|
|
1
|
+
/**
|
2
|
+
* 仪表盘组件的共享类型定义
|
3
|
+
*/
|
4
|
+
|
5
|
+
export interface NavItem {
|
6
|
+
href: string;
|
7
|
+
icon?: string; // 现在是可选的,会根据 href 自动推断
|
8
|
+
text: string;
|
9
|
+
badge?: string | number;
|
10
|
+
items?: NavItem[];
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 侧边栏尺寸类型
|
15
|
+
*/
|
16
|
+
export type SidebarSize = 'sm' | 'md' | 'lg' | 'xl';
|
17
|
+
|
18
|
+
/**
|
19
|
+
* 侧边栏尺寸配置映射
|
20
|
+
*/
|
21
|
+
export const sidebarSizeMap: Record<SidebarSize, string> = {
|
22
|
+
'sm': 'cosy:w-48', // 12rem (192px)
|
23
|
+
'md': 'cosy:w-64', // 16rem (256px) - 默认
|
24
|
+
'lg': 'cosy:w-72', // 18rem (288px)
|
25
|
+
'xl': 'cosy:w-80', // 20rem (320px)
|
26
|
+
};
|
27
|
+
|
28
|
+
/**
|
29
|
+
* 获取侧边栏宽度样式类
|
30
|
+
* @param size 侧边栏尺寸
|
31
|
+
* @returns 对应的 CSS 类名
|
32
|
+
*/
|
33
|
+
export function getSidebarWidth(size: SidebarSize = 'md'): string {
|
34
|
+
return sidebarSizeMap[size];
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* 侧边栏背景色主题类型
|
39
|
+
*/
|
40
|
+
export type SidebarTheme = 'default' | 'dark' | 'neutral' | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error';
|
41
|
+
|
42
|
+
/**
|
43
|
+
* 侧边栏背景色主题配置映射
|
44
|
+
*/
|
45
|
+
export const sidebarThemeMap: Record<SidebarTheme, { bg: string; headerBg: string; textColor: string; borderColor: string }> = {
|
46
|
+
'default': {
|
47
|
+
bg: 'cosy:bg-base-300',
|
48
|
+
headerBg: 'cosy:bg-base-300',
|
49
|
+
textColor: 'cosy:text-base-content',
|
50
|
+
borderColor: 'cosy:border-base-200'
|
51
|
+
},
|
52
|
+
'dark': {
|
53
|
+
bg: 'cosy:bg-base-100',
|
54
|
+
headerBg: 'cosy:bg-base-100',
|
55
|
+
textColor: 'cosy:text-base-content',
|
56
|
+
borderColor: 'cosy:border-base-200'
|
57
|
+
},
|
58
|
+
'neutral': {
|
59
|
+
bg: 'cosy:bg-neutral',
|
60
|
+
headerBg: 'cosy:bg-neutral',
|
61
|
+
textColor: 'cosy:text-neutral-content',
|
62
|
+
borderColor: 'cosy:border-neutral-focus'
|
63
|
+
},
|
64
|
+
'primary': {
|
65
|
+
bg: 'cosy:bg-primary',
|
66
|
+
headerBg: 'cosy:bg-primary',
|
67
|
+
textColor: 'cosy:text-primary-content',
|
68
|
+
borderColor: 'cosy:border-primary-focus'
|
69
|
+
},
|
70
|
+
'secondary': {
|
71
|
+
bg: 'cosy:bg-secondary',
|
72
|
+
headerBg: 'cosy:bg-secondary',
|
73
|
+
textColor: 'cosy:text-secondary-content',
|
74
|
+
borderColor: 'cosy:border-secondary-focus'
|
75
|
+
},
|
76
|
+
'accent': {
|
77
|
+
bg: 'cosy:bg-accent',
|
78
|
+
headerBg: 'cosy:bg-accent',
|
79
|
+
textColor: 'cosy:text-accent-content',
|
80
|
+
borderColor: 'cosy:border-accent-focus'
|
81
|
+
},
|
82
|
+
'info': {
|
83
|
+
bg: 'cosy:bg-info',
|
84
|
+
headerBg: 'cosy:bg-info',
|
85
|
+
textColor: 'cosy:text-info-content',
|
86
|
+
borderColor: 'cosy:border-info-focus'
|
87
|
+
},
|
88
|
+
'success': {
|
89
|
+
bg: 'cosy:bg-success',
|
90
|
+
headerBg: 'cosy:bg-success',
|
91
|
+
textColor: 'cosy:text-success-content',
|
92
|
+
borderColor: 'cosy:border-success-focus'
|
93
|
+
},
|
94
|
+
'warning': {
|
95
|
+
bg: 'cosy:bg-warning',
|
96
|
+
headerBg: 'cosy:bg-warning',
|
97
|
+
textColor: 'cosy:text-warning-content',
|
98
|
+
borderColor: 'cosy:border-warning-focus'
|
99
|
+
},
|
100
|
+
'error': {
|
101
|
+
bg: 'cosy:bg-error',
|
102
|
+
headerBg: 'cosy:bg-error',
|
103
|
+
textColor: 'cosy:text-error-content',
|
104
|
+
borderColor: 'cosy:border-error-focus'
|
105
|
+
}
|
106
|
+
};
|
107
|
+
|
108
|
+
/**
|
109
|
+
* 获取侧边栏主题样式类
|
110
|
+
* @param theme 侧边栏主题
|
111
|
+
* @returns 对应的样式配置
|
112
|
+
*/
|
113
|
+
export function getSidebarTheme(theme: SidebarTheme = 'default') {
|
114
|
+
return sidebarThemeMap[theme];
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* 内容区域背景色主题类型
|
119
|
+
*/
|
120
|
+
export type ContentTheme = 'card' | 'transparent' | 'base' | 'neutral' | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error';
|
121
|
+
|
122
|
+
/**
|
123
|
+
* 内容区域背景色主题配置映射
|
124
|
+
*/
|
125
|
+
export const contentThemeMap: Record<ContentTheme, { container: string; shadow: string }> = {
|
126
|
+
'card': {
|
127
|
+
container: 'cosy:card cosy:bg-base-100',
|
128
|
+
shadow: 'cosy:shadow-sm'
|
129
|
+
},
|
130
|
+
'transparent': {
|
131
|
+
container: '',
|
132
|
+
shadow: ''
|
133
|
+
},
|
134
|
+
'base': {
|
135
|
+
container: 'cosy:card cosy:bg-base-200',
|
136
|
+
shadow: 'cosy:shadow-sm'
|
137
|
+
},
|
138
|
+
'neutral': {
|
139
|
+
container: 'cosy:card cosy:bg-neutral',
|
140
|
+
shadow: 'cosy:shadow-sm'
|
141
|
+
},
|
142
|
+
'primary': {
|
143
|
+
container: 'cosy:card cosy:bg-primary cosy:text-primary-content',
|
144
|
+
shadow: 'cosy:shadow-sm'
|
145
|
+
},
|
146
|
+
'secondary': {
|
147
|
+
container: 'cosy:card cosy:bg-secondary cosy:text-secondary-content',
|
148
|
+
shadow: 'cosy:shadow-sm'
|
149
|
+
},
|
150
|
+
'accent': {
|
151
|
+
container: 'cosy:card cosy:bg-accent cosy:text-accent-content',
|
152
|
+
shadow: 'cosy:shadow-sm'
|
153
|
+
},
|
154
|
+
'info': {
|
155
|
+
container: 'cosy:card cosy:bg-info cosy:text-info-content',
|
156
|
+
shadow: 'cosy:shadow-sm'
|
157
|
+
},
|
158
|
+
'success': {
|
159
|
+
container: 'cosy:card cosy:bg-success cosy:text-success-content',
|
160
|
+
shadow: 'cosy:shadow-sm'
|
161
|
+
},
|
162
|
+
'warning': {
|
163
|
+
container: 'cosy:card cosy:bg-warning cosy:text-warning-content',
|
164
|
+
shadow: 'cosy:shadow-sm'
|
165
|
+
},
|
166
|
+
'error': {
|
167
|
+
container: 'cosy:card cosy:bg-error cosy:text-error-content',
|
168
|
+
shadow: 'cosy:shadow-sm'
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
/**
|
173
|
+
* 获取内容区域主题样式类
|
174
|
+
* @param theme 内容主题
|
175
|
+
* @returns 对应的样式配置
|
176
|
+
*/
|
177
|
+
export function getContentTheme(theme: ContentTheme = 'card') {
|
178
|
+
return contentThemeMap[theme];
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* 基于 href 关键词匹配图标名称的映射表
|
183
|
+
*/
|
184
|
+
const hrefToIconMap: Record<string, string> = {
|
185
|
+
// 主页相关
|
186
|
+
'dashboard': 'dashboard',
|
187
|
+
'home': 'home',
|
188
|
+
'index': 'home',
|
189
|
+
|
190
|
+
// 用户相关
|
191
|
+
'user': 'user',
|
192
|
+
'users': 'users',
|
193
|
+
'profile': 'user',
|
194
|
+
'account': 'user',
|
195
|
+
'member': 'users',
|
196
|
+
'team': 'users',
|
197
|
+
|
198
|
+
// 设置相关
|
199
|
+
'setting': 'settings',
|
200
|
+
'config': 'settings',
|
201
|
+
'preference': 'settings',
|
202
|
+
'admin': 'settings',
|
203
|
+
'manage': 'settings',
|
204
|
+
'tool': 'tools',
|
205
|
+
|
206
|
+
// 数据相关
|
207
|
+
'chart': 'chart',
|
208
|
+
'analytics': 'chart',
|
209
|
+
'report': 'report',
|
210
|
+
'statistic': 'chart',
|
211
|
+
'data': 'chart',
|
212
|
+
|
213
|
+
// 文档相关
|
214
|
+
'doc': 'document',
|
215
|
+
'document': 'document',
|
216
|
+
'file': 'document',
|
217
|
+
'page': 'document',
|
218
|
+
'article': 'document',
|
219
|
+
'content': 'document',
|
220
|
+
|
221
|
+
// 日历和时间
|
222
|
+
'calendar': 'calendar',
|
223
|
+
'schedule': 'calendar',
|
224
|
+
'event': 'calendar',
|
225
|
+
'date': 'calendar',
|
226
|
+
|
227
|
+
// 通知和消息
|
228
|
+
'notification': 'notification',
|
229
|
+
'message': 'message',
|
230
|
+
'chat': 'message',
|
231
|
+
'mail': 'mail',
|
232
|
+
'email': 'mail',
|
233
|
+
'inbox': 'inboxArchive',
|
234
|
+
|
235
|
+
// 搜索
|
236
|
+
'search': 'search',
|
237
|
+
'find': 'search',
|
238
|
+
|
239
|
+
// 收藏和标记
|
240
|
+
'favorite': 'star',
|
241
|
+
'bookmark': 'star',
|
242
|
+
'star': 'star',
|
243
|
+
'like': 'heart',
|
244
|
+
|
245
|
+
// 文件夹和目录
|
246
|
+
'folder': 'folder',
|
247
|
+
'directory': 'folder',
|
248
|
+
'category': 'folder',
|
249
|
+
|
250
|
+
// 安全和权限
|
251
|
+
'security': 'security',
|
252
|
+
'permission': 'security',
|
253
|
+
'auth': 'security',
|
254
|
+
'login': 'security',
|
255
|
+
|
256
|
+
// 财务相关
|
257
|
+
'payment': 'wallet',
|
258
|
+
'billing': 'wallet',
|
259
|
+
'finance': 'wallet',
|
260
|
+
'money': 'wallet',
|
261
|
+
'wallet': 'wallet',
|
262
|
+
|
263
|
+
// 操作相关
|
264
|
+
'edit': 'edit',
|
265
|
+
'delete': 'delete',
|
266
|
+
'remove': 'delete',
|
267
|
+
'save': 'save',
|
268
|
+
'download': 'download',
|
269
|
+
'upload': 'upload',
|
270
|
+
'refresh': 'refresh',
|
271
|
+
|
272
|
+
// 工具和实用程序
|
273
|
+
'clipboard': 'clipboard',
|
274
|
+
'link': 'link',
|
275
|
+
'menu': 'menu',
|
276
|
+
'close': 'close',
|
277
|
+
'check': 'check',
|
278
|
+
};
|
279
|
+
|
280
|
+
/**
|
281
|
+
* 根据 href 自动推断图标名称
|
282
|
+
* @param href 链接地址
|
283
|
+
* @param fallbackIcon 如果匹配失败时使用的默认图标
|
284
|
+
* @returns 图标名称
|
285
|
+
*/
|
286
|
+
export function getIconFromHref(href: string, fallbackIcon: string = 'folder'): string {
|
287
|
+
// 将 href 转换为小写并移除路径分隔符
|
288
|
+
const normalizedHref = href.toLowerCase().replace(/[\/\-_]/g, '');
|
289
|
+
|
290
|
+
// 遍历映射表,找到匹配的关键词
|
291
|
+
for (const [keyword, iconName] of Object.entries(hrefToIconMap)) {
|
292
|
+
if (normalizedHref.includes(keyword)) {
|
293
|
+
return iconName;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
return fallbackIcon;
|
298
|
+
}
|
299
|
+
|
300
|
+
/**
|
301
|
+
* 根据 NavItem 获取完整的图标信息
|
302
|
+
* @param item 导航项
|
303
|
+
* @returns 图标名称
|
304
|
+
*/
|
305
|
+
export function getNavItemIcon(item: NavItem): string {
|
306
|
+
// 如果显式指定了图标,优先使用
|
307
|
+
if (item.icon) {
|
308
|
+
return item.icon;
|
309
|
+
}
|
310
|
+
|
311
|
+
// 否则根据 href 自动推断
|
312
|
+
return getIconFromHref(item.href);
|
313
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@coffic/cosy-ui",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.11",
|
4
4
|
"description": "An astro component library",
|
5
5
|
"author": {
|
6
6
|
"name": "nookery",
|
@@ -22,9 +22,9 @@
|
|
22
22
|
"access": "public"
|
23
23
|
},
|
24
24
|
"sideEffects": false,
|
25
|
-
"main": "./dist/index.ts",
|
26
|
-
"module": "./dist/index.ts",
|
27
|
-
"types": "./dist/index.ts",
|
25
|
+
"main": "./dist/index-astro.ts",
|
26
|
+
"module": "./dist/index-astro.ts",
|
27
|
+
"types": "./dist/index-astro.ts",
|
28
28
|
"exports": {
|
29
29
|
".": {
|
30
30
|
"import": "./dist/index-astro.ts",
|