@coffic/cosy-ui 0.9.1 → 0.9.3
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/code-container/ButtonCodeToggle.astro +1 -1
- package/dist/src-astro/code-container/ButtonCopyCode.astro +1 -1
- package/dist/src-astro/header/Header.astro +25 -4
- package/dist/src-astro/language-switcher/LanguageSwitcher.astro +42 -22
- package/dist/src-astro/language-switcher/switcher_util.ts +69 -25
- package/dist/src-astro/layout-dashboard/DashboardLayout.astro +3 -28
- package/dist/src-astro/layout-dashboard/DashboardSidebar.astro +5 -24
- package/dist/src-astro/layout-dashboard/index.ts +5 -5
- package/dist/src-astro/layout-dashboard/tools.ts +1 -1
- package/dist/src-astro/layout-dashboard/types.ts +0 -120
- package/dist/src-astro/types/header.ts +6 -0
- package/dist/src-astro/types/layout.ts +52 -52
- package/dist/src-astro/types/meta.ts +3 -1
- package/package.json +1 -1
- package/dist/src-vue/utils/language.ts +0 -121
@@ -12,19 +12,35 @@
|
|
12
12
|
* 2. 响应式适配 - 在移动端和桌面端都有合适的展现形式
|
13
13
|
* 3. 可定制性 - 支持多种配置选项,适应不同网站的风格和需求
|
14
14
|
* 4. 多语言支持 - 内置语言切换功能,便于构建国际化网站
|
15
|
+
*
|
16
|
+
* @usage
|
17
|
+
* 基本用法:
|
18
|
+
* ```astro
|
19
|
+
* <Header />
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* 启用语言切换功能:
|
23
|
+
* ```astro
|
24
|
+
* ---
|
25
|
+
* import * as astroI18n from 'astro:i18n';
|
26
|
+
* ---
|
27
|
+
* <Header astroI18n={astroI18n} />
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* @props
|
31
|
+
* - astroI18n - 完整的 astro:i18n 模块(启用语言切换时需要)
|
15
32
|
*/
|
16
33
|
import {
|
34
|
+
Image,
|
17
35
|
LanguageSwitcher,
|
36
|
+
Link,
|
18
37
|
LinkUtil,
|
19
38
|
type IHeaderProps,
|
20
39
|
type INavItem,
|
21
40
|
NavItems,
|
22
|
-
Link,
|
23
|
-
Image,
|
24
41
|
ThemeSwitcher,
|
25
42
|
} from '../../index-astro';
|
26
43
|
import Logo from '../../src/assets/logo-rounded.png';
|
27
|
-
import { i18n } from 'astro:config/server';
|
28
44
|
|
29
45
|
export interface Props extends IHeaderProps {
|
30
46
|
debug?: boolean;
|
@@ -42,6 +58,7 @@ const {
|
|
42
58
|
paddingVertical = 'none',
|
43
59
|
navPosition = 'center',
|
44
60
|
showThemeSwitcher = true,
|
61
|
+
astroI18n,
|
45
62
|
} = Astro.props;
|
46
63
|
|
47
64
|
// 根据高度设置样式
|
@@ -79,6 +96,10 @@ const logoSizeClasses = {
|
|
79
96
|
|
80
97
|
const logoSizeClass = logoSizeClasses[height];
|
81
98
|
const linkHeightClass = linkHeightClasses[height];
|
99
|
+
|
100
|
+
// 检查 i18n 是否启用,通过 Astro.currentLocale 来判断
|
101
|
+
let isI18nEnabled = Astro.currentLocale !== undefined;
|
102
|
+
|
82
103
|
const currentPath = Astro.url.pathname;
|
83
104
|
const activeLink = LinkUtil.getActiveLink(
|
84
105
|
currentPath,
|
@@ -200,7 +221,7 @@ const activeLink = LinkUtil.getActiveLink(
|
|
200
221
|
}
|
201
222
|
|
202
223
|
{showThemeSwitcher && <ThemeSwitcher />}
|
203
|
-
{
|
224
|
+
{isI18nEnabled && <LanguageSwitcher astroI18n={astroI18n} />}
|
204
225
|
|
205
226
|
<slot name="navbar-end" />
|
206
227
|
</div>
|
@@ -14,51 +14,71 @@
|
|
14
14
|
* 4. 一致的视觉风格 - 使用与整体设计系统一致的下拉菜单样式
|
15
15
|
*
|
16
16
|
* @usage
|
17
|
-
*
|
17
|
+
* 基本用法(需要用户传入 astro:i18n 模块):
|
18
18
|
* ```astro
|
19
|
-
*
|
19
|
+
* ---
|
20
|
+
* import * as astroI18n from 'astro:i18n';
|
21
|
+
* ---
|
22
|
+
* <LanguageSwitcher astroI18n={astroI18n} />
|
20
23
|
* ```
|
21
24
|
*
|
25
|
+
* @props
|
26
|
+
* - astroI18n - 完整的 astro:i18n 模块
|
27
|
+
* - class - 自定义CSS类名
|
22
28
|
*/
|
23
29
|
|
30
|
+
import { ChevronDownIcon, Link, ListItem } from '../../index-astro';
|
24
31
|
import {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
} from '../../index-astro';
|
32
|
+
checkSwitcherRenderState,
|
33
|
+
generateSwitcherLinks,
|
34
|
+
type SwitcherLink,
|
35
|
+
} from './switcher_util';
|
30
36
|
import '../../style.ts';
|
31
|
-
import { i18n } from 'astro:config/server';
|
32
37
|
|
33
38
|
interface Props {
|
39
|
+
/**
|
40
|
+
* 完整的 astro:i18n 模块
|
41
|
+
*/
|
42
|
+
astroI18n?: any;
|
43
|
+
|
34
44
|
/**
|
35
45
|
* 自定义类名
|
36
46
|
*/
|
37
47
|
class?: string;
|
38
48
|
}
|
39
49
|
|
40
|
-
const { class: className = '' } = Astro.props;
|
50
|
+
const { astroI18n, class: className = '' } = Astro.props;
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
52
|
+
// 检查渲染状态
|
53
|
+
const renderState = checkSwitcherRenderState(Astro.currentLocale, astroI18n);
|
54
|
+
|
55
|
+
// 输出警告信息
|
56
|
+
if (renderState.warnings) {
|
57
|
+
renderState.warnings.forEach((warning) => console.warn(warning));
|
58
|
+
}
|
45
59
|
|
46
|
-
|
47
|
-
const { getSwitcherLinks } = await import('./switcher_util.ts');
|
48
|
-
links = getSwitcherLinks(Astro);
|
60
|
+
let links: SwitcherLink[] = [];
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
// 如果应该渲染,生成切换链接
|
63
|
+
if (renderState.shouldRender && Astro.currentLocale) {
|
64
|
+
try {
|
65
|
+
links = generateSwitcherLinks(
|
66
|
+
astroI18n,
|
67
|
+
Astro.currentLocale,
|
68
|
+
Astro.url.pathname
|
69
|
+
);
|
70
|
+
} catch (error) {
|
71
|
+
// 如果生成链接失败,设置为不渲染
|
72
|
+
renderState.shouldRender = false;
|
73
|
+
}
|
54
74
|
}
|
55
75
|
---
|
56
76
|
|
57
77
|
{
|
58
|
-
|
78
|
+
renderState.shouldRender && (
|
59
79
|
<div class={`cosy:dropdown cosy:dropdown-end ${className}`}>
|
60
80
|
<div tabindex="0" role="button" class:list={['cosy:btn cosy:btn-ghost']}>
|
61
|
-
<span class="cosy:mr-1">{currentLanguageName}</span>
|
81
|
+
<span class="cosy:mr-1">{renderState.currentLanguageName}</span>
|
62
82
|
<ChevronDownIcon size="16px" class="cosy:w-4 cosy:h-4" />
|
63
83
|
</div>
|
64
84
|
<ul
|
@@ -66,7 +86,7 @@ if (i18n !== undefined) {
|
|
66
86
|
class="cosy:z-[1] cosy:bg-base-100 cosy:shadow cosy:p-2 cosy:rounded-box cosy:w-32 cosy:dropdown-content cosy:menu">
|
67
87
|
{links.map((link) => (
|
68
88
|
<ListItem>
|
69
|
-
<Link href={link.url} active={currentLocale === link.locale}>
|
89
|
+
<Link href={link.url} active={Astro.currentLocale === link.locale}>
|
70
90
|
{link.name}
|
71
91
|
</Link>
|
72
92
|
</ListItem>
|
@@ -1,6 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import type { AstroGlobal } from 'astro';
|
3
|
-
import { LanguageUtil } from '../../index-astro';
|
1
|
+
import { LanguageUtil } from "../../src/utils/language"
|
4
2
|
|
5
3
|
export interface SwitcherLink {
|
6
4
|
locale: string;
|
@@ -8,33 +6,79 @@ export interface SwitcherLink {
|
|
8
6
|
url: string;
|
9
7
|
}
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
/**
|
10
|
+
* 获取基础 URL
|
11
|
+
*/
|
12
|
+
export const getBaseUrl = (): string => {
|
13
|
+
return import.meta.env.BASE_URL || '/';
|
14
14
|
};
|
15
15
|
|
16
|
-
|
16
|
+
/**
|
17
|
+
* 从 URL 中提取语言代码
|
18
|
+
*/
|
19
|
+
export const getLocaleFromUrl = (url: string): string => {
|
17
20
|
return url.replace(getBaseUrl(), '').split('/')[0];
|
18
21
|
};
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
/**
|
24
|
+
* 生成语言切换链接
|
25
|
+
* @param astroI18n - astro:i18n 模块
|
26
|
+
* @param currentLocale - 当前语言代码
|
27
|
+
* @param pathname - 当前页面路径
|
28
|
+
* @returns 语言切换链接数组
|
29
|
+
*/
|
30
|
+
export const generateSwitcherLinks = (
|
31
|
+
astroI18n: any,
|
32
|
+
currentLocale: string,
|
33
|
+
pathname: string
|
34
|
+
): SwitcherLink[] => {
|
35
|
+
try {
|
36
|
+
const { getRelativeLocaleUrl, getRelativeLocaleUrlList } = astroI18n;
|
22
37
|
|
23
|
-
|
24
|
-
|
38
|
+
const currentLocalURLPrefix = getRelativeLocaleUrl(currentLocale, '');
|
39
|
+
const pathWithSlash = pathname + '/';
|
40
|
+
const slug = pathWithSlash.replace(currentLocalURLPrefix, '');
|
41
|
+
const urls = getRelativeLocaleUrlList(slug);
|
42
|
+
|
43
|
+
return urls.map((url: string) => ({
|
44
|
+
locale: getLocaleFromUrl(url),
|
45
|
+
name: LanguageUtil.getLanguageName(getLocaleFromUrl(url)),
|
46
|
+
url: url,
|
47
|
+
}));
|
48
|
+
} catch (error) {
|
49
|
+
console.warn('LanguageSwitcher: Error generating switcher links:', error);
|
50
|
+
throw error;
|
25
51
|
}
|
52
|
+
};
|
26
53
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}
|
54
|
+
/**
|
55
|
+
* 检查语言切换器是否应该渲染
|
56
|
+
* @param currentLocale - 当前语言代码
|
57
|
+
* @param astroI18n - astro:i18n 模块
|
58
|
+
* @returns 是否应该渲染的状态信息
|
59
|
+
*/
|
60
|
+
export const checkSwitcherRenderState = (
|
61
|
+
currentLocale: string | undefined,
|
62
|
+
astroI18n: any
|
63
|
+
): {
|
64
|
+
shouldRender: boolean;
|
65
|
+
currentLanguageName?: string;
|
66
|
+
warnings?: string[];
|
67
|
+
} => {
|
68
|
+
const warnings: string[] = [];
|
69
|
+
|
70
|
+
if (!currentLocale) {
|
71
|
+
warnings.push('LanguageSwitcher: i18n is not enabled in the current project');
|
72
|
+
return { shouldRender: false, warnings };
|
73
|
+
}
|
74
|
+
|
75
|
+
if (!astroI18n) {
|
76
|
+
warnings.push('LanguageSwitcher: astroI18n module is required. Please pass the astro:i18n module as a prop.');
|
77
|
+
return { shouldRender: false, warnings };
|
78
|
+
}
|
79
|
+
|
80
|
+
return {
|
81
|
+
shouldRender: true,
|
82
|
+
currentLanguageName: LanguageUtil.getLanguageName(currentLocale),
|
83
|
+
};
|
84
|
+
};
|
@@ -141,8 +141,6 @@
|
|
141
141
|
* - userMenuItems?: UserMenuItem[] - 用户菜单项,默认包含个人资料、设置、退出登录,图标会自动匹配
|
142
142
|
* - sidebarCollapsed?: boolean - 是否折叠侧边栏,默认为false
|
143
143
|
* - sidebarSize?: 'sm' | 'md' | 'lg' | 'xl' - 侧边栏尺寸,默认为"md"
|
144
|
-
* - sidebarTheme?: SidebarTheme - 侧边栏主题,默认为"default"
|
145
|
-
* - mainBackgroundTheme?: MainBackgroundTheme - 主内容区域背景主题,默认为"transparent"
|
146
144
|
* - head?: astroHTML.JSX.Element - 自定义头部内容
|
147
145
|
* - class?: string - 页面类名
|
148
146
|
* - class:list?: any - 类名列表
|
@@ -158,14 +156,7 @@ import DashboardSidebar from './DashboardSidebar.astro';
|
|
158
156
|
import DashboardTopNavbar from './DashboardTopNavbar.astro';
|
159
157
|
import { ToastContainer, ConfirmDialog } from '../../index-astro';
|
160
158
|
import '../../style.ts';
|
161
|
-
import {
|
162
|
-
type NavItem,
|
163
|
-
type SidebarSize,
|
164
|
-
type SidebarTheme,
|
165
|
-
type MainBackgroundTheme,
|
166
|
-
type UserMenuItem,
|
167
|
-
getMainBackgroundTheme,
|
168
|
-
} from './types';
|
159
|
+
import { type NavItem, type SidebarSize, type UserMenuItem } from './types';
|
169
160
|
|
170
161
|
export interface Props {
|
171
162
|
/**
|
@@ -216,18 +207,6 @@ export interface Props {
|
|
216
207
|
*/
|
217
208
|
sidebarSize?: SidebarSize;
|
218
209
|
|
219
|
-
/**
|
220
|
-
* 侧边栏主题
|
221
|
-
* @default "default"
|
222
|
-
*/
|
223
|
-
sidebarTheme?: SidebarTheme;
|
224
|
-
|
225
|
-
/**
|
226
|
-
* 主内容区域背景主题
|
227
|
-
* @default "transparent"
|
228
|
-
*/
|
229
|
-
mainBackgroundTheme?: MainBackgroundTheme;
|
230
|
-
|
231
210
|
/**
|
232
211
|
* 自定义头部内容
|
233
212
|
*/
|
@@ -278,8 +257,6 @@ const {
|
|
278
257
|
userMenuItems,
|
279
258
|
sidebarCollapsed = false,
|
280
259
|
sidebarSize = 'md',
|
281
|
-
sidebarTheme = 'default',
|
282
|
-
mainBackgroundTheme = 'base-100',
|
283
260
|
enableToast = true,
|
284
261
|
enableConfirmDialog = true,
|
285
262
|
head,
|
@@ -291,7 +268,6 @@ const {
|
|
291
268
|
} = Astro.props;
|
292
269
|
|
293
270
|
const currentPath = Astro.url.pathname;
|
294
|
-
const mainBackgroundStyles = getMainBackgroundTheme(mainBackgroundTheme);
|
295
271
|
|
296
272
|
const mainPaddingMap = {
|
297
273
|
none: '',
|
@@ -325,8 +301,7 @@ const mainPaddingMap = {
|
|
325
301
|
systemName={systemName}
|
326
302
|
navItems={navItems}
|
327
303
|
currentPath={currentPath}
|
328
|
-
size={sidebarSize}
|
329
|
-
theme={sidebarTheme}>
|
304
|
+
size={sidebarSize}>
|
330
305
|
<slot name="sidebar-footer" slot="footer" />
|
331
306
|
</DashboardSidebar>
|
332
307
|
</div>
|
@@ -346,7 +321,7 @@ const mainPaddingMap = {
|
|
346
321
|
class:list={[
|
347
322
|
'cosy:flex-1',
|
348
323
|
mainPaddingMap[mainPadding],
|
349
|
-
|
324
|
+
'cosy:bg-base-100',
|
350
325
|
]}>
|
351
326
|
<slot />
|
352
327
|
</main>
|
@@ -28,7 +28,6 @@
|
|
28
28
|
* - navItems: NavItem[] - 导航项目
|
29
29
|
* - currentPath?: string - 当前路径,用于高亮当前页面
|
30
30
|
* - size?: 'sm' | 'md' | 'lg' | 'xl' - 侧边栏尺寸,默认为"md"
|
31
|
-
* - theme?: SidebarTheme - 侧边栏主题,默认为"default"
|
32
31
|
*
|
33
32
|
* @slots
|
34
33
|
* - footer - 侧边栏底部自定义内容,可用于展示用户信息等
|
@@ -38,10 +37,8 @@ import '../../style.ts';
|
|
38
37
|
import {
|
39
38
|
getNavItemIcon,
|
40
39
|
getSidebarWidth,
|
41
|
-
getSidebarTheme,
|
42
40
|
type NavItem,
|
43
41
|
type SidebarSize,
|
44
|
-
type SidebarTheme,
|
45
42
|
} from './types';
|
46
43
|
import AstroIcon from '../icons/AstroIcon.astro';
|
47
44
|
|
@@ -67,12 +64,6 @@ export interface Props {
|
|
67
64
|
* @default "md"
|
68
65
|
*/
|
69
66
|
size?: SidebarSize;
|
70
|
-
|
71
|
-
/**
|
72
|
-
* 侧边栏主题
|
73
|
-
* @default "default"
|
74
|
-
*/
|
75
|
-
theme?: SidebarTheme;
|
76
67
|
}
|
77
68
|
|
78
69
|
const {
|
@@ -80,26 +71,16 @@ const {
|
|
80
71
|
navItems,
|
81
72
|
currentPath = '',
|
82
73
|
size = 'md',
|
83
|
-
theme = 'default',
|
84
74
|
} = Astro.props;
|
85
|
-
|
86
|
-
const themeStyles = getSidebarTheme(theme);
|
87
75
|
---
|
88
76
|
|
89
77
|
<aside
|
90
78
|
class:list={[
|
91
79
|
getSidebarWidth(size),
|
92
|
-
'cosy:min-h-full cosy:flex cosy:flex-col',
|
93
|
-
themeStyles.bg,
|
94
|
-
themeStyles.textColor,
|
80
|
+
'cosy:min-h-full cosy:flex cosy:flex-col cosy:bg-base-200 cosy:text-base-content',
|
95
81
|
]}>
|
96
82
|
<!-- 侧边栏头部 -->
|
97
|
-
<div
|
98
|
-
class:list={[
|
99
|
-
'cosy:navbar cosy:border-b',
|
100
|
-
themeStyles.headerBg,
|
101
|
-
themeStyles.borderColor,
|
102
|
-
]}>
|
83
|
+
<div class:list={['cosy:navbar cosy:border-b cosy:border-base-300']}>
|
103
84
|
<div class="cosy:navbar-start">
|
104
85
|
<a
|
105
86
|
href="/dashboard"
|
@@ -118,7 +99,7 @@ const themeStyles = getSidebarTheme(theme);
|
|
118
99
|
<!-- 导航菜单 -->
|
119
100
|
<div class="cosy:flex-1 cosy:overflow-y-auto">
|
120
101
|
<ul
|
121
|
-
class="cosy:menu cosy:p-4 cosy:space-y-1 cosy:list-none cosy:no-underline">
|
102
|
+
class="cosy:menu cosy:p-4 cosy:space-y-1 cosy:list-none cosy:no-underline cosy:w-full">
|
122
103
|
{
|
123
104
|
navItems.map((item: NavItem) => {
|
124
105
|
const isActive =
|
@@ -129,7 +110,7 @@ const themeStyles = getSidebarTheme(theme);
|
|
129
110
|
));
|
130
111
|
|
131
112
|
return (
|
132
|
-
<li>
|
113
|
+
<li class="cosy:w-full">
|
133
114
|
<a
|
134
115
|
href={item.href}
|
135
116
|
class:list={[
|
@@ -186,7 +167,7 @@ const themeStyles = getSidebarTheme(theme);
|
|
186
167
|
</div>
|
187
168
|
|
188
169
|
<!-- 侧边栏底部自定义内容 -->
|
189
|
-
<div class:list={['cosy:mt-auto cosy:border-t'
|
170
|
+
<div class:list={['cosy:mt-auto cosy:border-t cosy:border-base-300']}>
|
190
171
|
<slot name="footer" />
|
191
172
|
</div>
|
192
173
|
</aside>
|
@@ -7,11 +7,11 @@ import DashboardSidebar from './DashboardSidebar.astro';
|
|
7
7
|
import DashboardTopNavbar from './DashboardTopNavbar.astro';
|
8
8
|
|
9
9
|
export {
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
DashboardLayout,
|
11
|
+
DashboardSidebar,
|
12
|
+
DashboardTopNavbar
|
13
13
|
};
|
14
14
|
|
15
15
|
// 导出类型和函数
|
16
|
-
export type { NavItem, SidebarSize,
|
17
|
-
export { getIconFromHref, getNavItemIcon, getSidebarWidth
|
16
|
+
export type { NavItem, SidebarSize, UserMenuItem } from './types';
|
17
|
+
export { getIconFromHref, getNavItemIcon, getSidebarWidth } from './types';
|
@@ -115,7 +115,7 @@ const hrefToIconMap: Record<string, string> = {
|
|
115
115
|
*/
|
116
116
|
export function getIconFromHref(href: string, fallbackIcon: string = 'folder'): string {
|
117
117
|
// 将 href 转换为小写并移除路径分隔符
|
118
|
-
const normalizedHref = href.toLowerCase().replace(/[
|
118
|
+
const normalizedHref = href.toLowerCase().replace(/[/\-_]/g, '');
|
119
119
|
|
120
120
|
// 遍历映射表,找到匹配的关键词
|
121
121
|
for (const [keyword, iconName] of Object.entries(hrefToIconMap)) {
|
@@ -43,124 +43,4 @@ export function getSidebarWidth(size: SidebarSize = 'md'): string {
|
|
43
43
|
return sidebarSizeMap[size];
|
44
44
|
}
|
45
45
|
|
46
|
-
/**
|
47
|
-
* 侧边栏背景色主题类型
|
48
|
-
*/
|
49
|
-
export type SidebarTheme = 'default' | 'dark' | 'neutral' | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error';
|
50
|
-
|
51
|
-
/**
|
52
|
-
* 侧边栏背景色主题配置映射
|
53
|
-
*/
|
54
|
-
export const sidebarThemeMap: Record<SidebarTheme, { bg: string; headerBg: string; textColor: string; borderColor: string }> = {
|
55
|
-
'default': {
|
56
|
-
bg: 'cosy:bg-base-300',
|
57
|
-
headerBg: 'cosy:bg-base-300',
|
58
|
-
textColor: 'cosy:text-base-content',
|
59
|
-
borderColor: 'cosy:border-base-200'
|
60
|
-
},
|
61
|
-
'dark': {
|
62
|
-
bg: 'cosy:bg-base-100',
|
63
|
-
headerBg: 'cosy:bg-base-100',
|
64
|
-
textColor: 'cosy:text-base-content',
|
65
|
-
borderColor: 'cosy:border-base-200'
|
66
|
-
},
|
67
|
-
'neutral': {
|
68
|
-
bg: 'cosy:bg-neutral',
|
69
|
-
headerBg: 'cosy:bg-neutral',
|
70
|
-
textColor: 'cosy:text-neutral-content',
|
71
|
-
borderColor: 'cosy:border-neutral-focus'
|
72
|
-
},
|
73
|
-
'primary': {
|
74
|
-
bg: 'cosy:bg-primary',
|
75
|
-
headerBg: 'cosy:bg-primary',
|
76
|
-
textColor: 'cosy:text-primary-content',
|
77
|
-
borderColor: 'cosy:border-primary-focus'
|
78
|
-
},
|
79
|
-
'secondary': {
|
80
|
-
bg: 'cosy:bg-secondary',
|
81
|
-
headerBg: 'cosy:bg-secondary',
|
82
|
-
textColor: 'cosy:text-secondary-content',
|
83
|
-
borderColor: 'cosy:border-secondary-focus'
|
84
|
-
},
|
85
|
-
'accent': {
|
86
|
-
bg: 'cosy:bg-accent',
|
87
|
-
headerBg: 'cosy:bg-accent',
|
88
|
-
textColor: 'cosy:text-accent-content',
|
89
|
-
borderColor: 'cosy:border-accent-focus'
|
90
|
-
},
|
91
|
-
'info': {
|
92
|
-
bg: 'cosy:bg-info',
|
93
|
-
headerBg: 'cosy:bg-info',
|
94
|
-
textColor: 'cosy:text-info-content',
|
95
|
-
borderColor: 'cosy:border-info-focus'
|
96
|
-
},
|
97
|
-
'success': {
|
98
|
-
bg: 'cosy:bg-success',
|
99
|
-
headerBg: 'cosy:bg-success',
|
100
|
-
textColor: 'cosy:text-success-content',
|
101
|
-
borderColor: 'cosy:border-success-focus'
|
102
|
-
},
|
103
|
-
'warning': {
|
104
|
-
bg: 'cosy:bg-warning',
|
105
|
-
headerBg: 'cosy:bg-warning',
|
106
|
-
textColor: 'cosy:text-warning-content',
|
107
|
-
borderColor: 'cosy:border-warning-focus'
|
108
|
-
},
|
109
|
-
'error': {
|
110
|
-
bg: 'cosy:bg-error',
|
111
|
-
headerBg: 'cosy:bg-error',
|
112
|
-
textColor: 'cosy:text-error-content',
|
113
|
-
borderColor: 'cosy:border-error-focus'
|
114
|
-
}
|
115
|
-
};
|
116
|
-
|
117
|
-
/**
|
118
|
-
* 获取侧边栏主题样式类
|
119
|
-
* @param theme 侧边栏主题
|
120
|
-
* @returns 对应的样式配置
|
121
|
-
*/
|
122
|
-
export function getSidebarTheme(theme: SidebarTheme = 'default') {
|
123
|
-
return sidebarThemeMap[theme];
|
124
|
-
}
|
125
|
-
|
126
|
-
/**
|
127
|
-
* 主内容区域背景主题类型
|
128
|
-
*/
|
129
|
-
export type MainBackgroundTheme = 'transparent' | 'base-100' | 'base-200' | 'base-300' | 'neutral' | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error' | 'gradient-warm' | 'gradient-cool' | 'gradient-rainbow' | 'gradient-sunset' | 'gradient-ocean' | 'gradient-forest';
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
/**
|
134
|
-
* 主内容区域背景主题配置映射
|
135
|
-
*/
|
136
|
-
export const mainBackgroundThemeMap: Record<MainBackgroundTheme, string> = {
|
137
|
-
'transparent': '',
|
138
|
-
'base-100': 'cosy:bg-base-100',
|
139
|
-
'base-200': 'cosy:bg-base-200',
|
140
|
-
'base-300': 'cosy:bg-base-300',
|
141
|
-
'neutral': 'cosy:bg-neutral',
|
142
|
-
'primary': 'cosy:bg-primary',
|
143
|
-
'secondary': 'cosy:bg-secondary',
|
144
|
-
'accent': 'cosy:bg-accent',
|
145
|
-
'info': 'cosy:bg-info',
|
146
|
-
'success': 'cosy:bg-success',
|
147
|
-
'warning': 'cosy:bg-warning',
|
148
|
-
'error': 'cosy:bg-error',
|
149
|
-
'gradient-warm': 'cosy:bg-gradient-to-br cosy:from-orange-100 cosy:via-red-50 cosy:to-pink-100',
|
150
|
-
'gradient-cool': 'cosy:bg-gradient-to-br cosy:from-blue-100 cosy:via-cyan-50 cosy:to-green-100',
|
151
|
-
'gradient-rainbow': 'cosy:bg-gradient-to-br cosy:from-purple-100 cosy:via-pink-50 cosy:to-blue-100',
|
152
|
-
'gradient-sunset': 'cosy:bg-gradient-to-br cosy:from-yellow-100 cosy:via-orange-50 cosy:to-red-100',
|
153
|
-
'gradient-ocean': 'cosy:bg-gradient-to-br cosy:from-blue-100 cosy:via-teal-50 cosy:to-cyan-100',
|
154
|
-
'gradient-forest': 'cosy:bg-gradient-to-br cosy:from-green-100 cosy:via-emerald-50 cosy:to-teal-100'
|
155
|
-
};
|
156
|
-
|
157
|
-
/**
|
158
|
-
* 获取主内容区域背景主题样式类
|
159
|
-
* @param theme 主内容区域背景主题
|
160
|
-
* @returns 对应的样式类名
|
161
|
-
*/
|
162
|
-
export function getMainBackgroundTheme(theme: MainBackgroundTheme = 'base-100'): string {
|
163
|
-
return mainBackgroundThemeMap[theme];
|
164
|
-
}
|
165
|
-
|
166
46
|
export { getIconFromHref, getNavItemIcon, getUserMenuItemIcon } from './tools';
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { INavItem } from './nav';
|
2
|
+
import type { ImageMetadata } from 'astro';
|
2
3
|
|
3
4
|
export interface IHeaderProps {
|
4
5
|
/**
|
@@ -7,6 +8,11 @@ export interface IHeaderProps {
|
|
7
8
|
*/
|
8
9
|
defaultSidebarOpen?: boolean;
|
9
10
|
|
11
|
+
/**
|
12
|
+
* 完整的 astro:i18n 模块(启用语言切换时需要)
|
13
|
+
*/
|
14
|
+
astroI18n?: any;
|
15
|
+
|
10
16
|
/**
|
11
17
|
* 导航栏高度
|
12
18
|
* @default "md"
|