@yh-ui/theme 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present YH-UI Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.componentThemeProps = exports.COMPONENT_THEME_KEY = void 0;
7
+ exports.createComponentThemes = createComponentThemes;
8
+ exports.mergeComponentThemes = mergeComponentThemes;
9
+ exports.provideComponentThemes = provideComponentThemes;
10
+ exports.useComponentTheme = useComponentTheme;
11
+ var _vue = require("vue");
12
+ const COMPONENT_THEME_KEY = exports.COMPONENT_THEME_KEY = Symbol("component-theme");
13
+ const componentThemeProps = exports.componentThemeProps = {
14
+ /** 组件主题变量覆盖 */
15
+ themeOverrides: {
16
+ type: Object,
17
+ default: void 0
18
+ }
19
+ };
20
+ function useComponentTheme(componentName, localOverrides) {
21
+ const globalThemes = (0, _vue.inject)(COMPONENT_THEME_KEY, {});
22
+ const mergedVars = (0, _vue.computed)(() => {
23
+ const globalVars = globalThemes[componentName] || {};
24
+ const local = (0, _vue.unref)(localOverrides) || {};
25
+ return {
26
+ ...globalVars,
27
+ ...local
28
+ };
29
+ });
30
+ const themeStyle = (0, _vue.computed)(() => {
31
+ const vars = mergedVars.value;
32
+ const style = {};
33
+ Object.entries(vars).forEach(([key, value]) => {
34
+ if (value !== void 0) {
35
+ const cssVarName = `--yh-${componentName}-${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
36
+ style[cssVarName] = value;
37
+ }
38
+ });
39
+ return style;
40
+ });
41
+ const hasCustomTheme = (0, _vue.computed)(() => {
42
+ return Object.keys(mergedVars.value).length > 0;
43
+ });
44
+ return {
45
+ themeVars: mergedVars,
46
+ themeStyle,
47
+ hasCustomTheme
48
+ };
49
+ }
50
+ function provideComponentThemes(themes) {
51
+ (0, _vue.provide)(COMPONENT_THEME_KEY, themes);
52
+ }
53
+ function createComponentThemes(themes) {
54
+ return themes;
55
+ }
56
+ function mergeComponentThemes(base, overrides) {
57
+ const result = {
58
+ ...base
59
+ };
60
+ Object.keys(overrides).forEach(key => {
61
+ const baseVars = result[key] || {};
62
+ const overrideVars = overrides[key] || {};
63
+ result[key] = {
64
+ ...baseVars,
65
+ ...overrideVars
66
+ };
67
+ });
68
+ return result;
69
+ }
@@ -0,0 +1,269 @@
1
+ /**
2
+ * YH-UI 组件级主题覆盖
3
+ * @description 支持单个组件实例的主题定制,类似 Naive UI 的 themeOverrides
4
+ */
5
+ import type { InjectionKey, PropType, ExtractPropTypes } from 'vue';
6
+ import { type MaybeRef } from 'vue';
7
+ /** 组件主题变量 */
8
+ export interface ComponentThemeVars {
9
+ textColor?: string;
10
+ bgColor?: string;
11
+ borderColor?: string;
12
+ borderRadius?: string;
13
+ fontSize?: string;
14
+ fontWeight?: string;
15
+ hoverBgColor?: string;
16
+ hoverTextColor?: string;
17
+ hoverBorderColor?: string;
18
+ activeBgColor?: string;
19
+ activeTextColor?: string;
20
+ activeBorderColor?: string;
21
+ disabledBgColor?: string;
22
+ disabledTextColor?: string;
23
+ disabledBorderColor?: string;
24
+ height?: string;
25
+ padding?: string;
26
+ gap?: string;
27
+ boxShadow?: string;
28
+ transition?: string;
29
+ [key: string]: string | undefined;
30
+ }
31
+ /** 组件主题配置 */
32
+ export interface ComponentTheme<T extends ComponentThemeVars = ComponentThemeVars> {
33
+ /** 组件类型名称 */
34
+ name: string;
35
+ /** 主题变量 */
36
+ vars: T;
37
+ /** 是否继承父级主题 */
38
+ inherit?: boolean;
39
+ }
40
+ /** 全局组件主题覆盖 */
41
+ export type GlobalComponentThemes = Partial<Record<string, ComponentThemeVars>>;
42
+ export declare const COMPONENT_THEME_KEY: InjectionKey<GlobalComponentThemes>;
43
+ export declare const componentThemeProps: {
44
+ /** 组件主题变量覆盖 */
45
+ readonly themeOverrides: {
46
+ readonly type: PropType<ComponentThemeVars>;
47
+ readonly default: undefined;
48
+ };
49
+ };
50
+ export type ComponentThemeProps = ExtractPropTypes<typeof componentThemeProps>;
51
+ /**
52
+ * 使用组件主题
53
+ * @param componentName 组件名称
54
+ * @param localOverrides 本地覆盖(props.themeOverrides)
55
+ * @returns CSS 变量样式对象
56
+ */
57
+ export declare function useComponentTheme(componentName: string, localOverrides?: MaybeRef<ComponentThemeVars | undefined>): {
58
+ themeVars: import("vue").ComputedRef<{
59
+ [x: string]: string | undefined;
60
+ textColor?: string;
61
+ bgColor?: string;
62
+ borderColor?: string;
63
+ borderRadius?: string;
64
+ fontSize?: string;
65
+ fontWeight?: string;
66
+ hoverBgColor?: string;
67
+ hoverTextColor?: string;
68
+ hoverBorderColor?: string;
69
+ activeBgColor?: string;
70
+ activeTextColor?: string;
71
+ activeBorderColor?: string;
72
+ disabledBgColor?: string;
73
+ disabledTextColor?: string;
74
+ disabledBorderColor?: string;
75
+ height?: string;
76
+ padding?: string;
77
+ gap?: string;
78
+ boxShadow?: string;
79
+ transition?: string;
80
+ }>;
81
+ themeStyle: import("vue").ComputedRef<Record<string, string>>;
82
+ hasCustomTheme: import("vue").ComputedRef<boolean>;
83
+ };
84
+ /**
85
+ * 提供全局组件主题
86
+ * @param themes 组件主题配置
87
+ */
88
+ export declare function provideComponentThemes(themes: GlobalComponentThemes): void;
89
+ /** Button 组件主题变量 */
90
+ export interface ButtonThemeVars extends ComponentThemeVars {
91
+ primaryBgColor?: string;
92
+ primaryTextColor?: string;
93
+ primaryBorderColor?: string;
94
+ successBgColor?: string;
95
+ successTextColor?: string;
96
+ warningBgColor?: string;
97
+ warningTextColor?: string;
98
+ dangerBgColor?: string;
99
+ dangerTextColor?: string;
100
+ infoBgColor?: string;
101
+ infoTextColor?: string;
102
+ roundBorderRadius?: string;
103
+ }
104
+ /** Input 组件主题变量 */
105
+ export interface InputThemeVars extends ComponentThemeVars {
106
+ placeholderColor?: string;
107
+ focusBorderColor?: string;
108
+ focusShadow?: string;
109
+ prefixColor?: string;
110
+ suffixColor?: string;
111
+ }
112
+ /** Select 组件主题变量 */
113
+ export interface SelectThemeVars extends ComponentThemeVars {
114
+ optionHoverBgColor?: string;
115
+ optionSelectedBgColor?: string;
116
+ optionSelectedTextColor?: string;
117
+ dropdownBgColor?: string;
118
+ dropdownBorderColor?: string;
119
+ dropdownShadow?: string;
120
+ }
121
+ /** Table 组件主题变量 */
122
+ export interface TableThemeVars extends ComponentThemeVars {
123
+ headerBgColor?: string;
124
+ headerTextColor?: string;
125
+ rowHoverBgColor?: string;
126
+ rowStripeBgColor?: string;
127
+ rowSelectedBgColor?: string;
128
+ cellPadding?: string;
129
+ borderWidth?: string;
130
+ }
131
+ /** Card 组件主题变量 */
132
+ export interface CardThemeVars extends ComponentThemeVars {
133
+ headerBgColor?: string;
134
+ headerBorderColor?: string;
135
+ bodyPadding?: string;
136
+ footerBgColor?: string;
137
+ }
138
+ /** Modal/Dialog 组件主题变量 */
139
+ export interface ModalThemeVars extends ComponentThemeVars {
140
+ maskBgColor?: string;
141
+ headerPadding?: string;
142
+ bodyPadding?: string;
143
+ footerPadding?: string;
144
+ closeIconColor?: string;
145
+ closeIconHoverColor?: string;
146
+ }
147
+ /** Menu 组件主题变量 */
148
+ export interface MenuThemeVars extends ComponentThemeVars {
149
+ itemHoverBgColor?: string;
150
+ itemActiveBgColor?: string;
151
+ itemActiveTextColor?: string;
152
+ subMenuBgColor?: string;
153
+ groupTitleColor?: string;
154
+ iconSize?: string;
155
+ itemHeight?: string;
156
+ }
157
+ /** Tooltip/Popover 组件主题变量 */
158
+ export interface TooltipThemeVars extends ComponentThemeVars {
159
+ arrowSize?: string;
160
+ maxWidth?: string;
161
+ contentPadding?: string;
162
+ }
163
+ /** Tag 组件主题变量 */
164
+ export interface TagThemeVars extends ComponentThemeVars {
165
+ closeBtnColor?: string;
166
+ closeBtnHoverColor?: string;
167
+ defaultBgColor?: string;
168
+ primaryBgColor?: string;
169
+ successBgColor?: string;
170
+ warningBgColor?: string;
171
+ dangerBgColor?: string;
172
+ infoBgColor?: string;
173
+ }
174
+ /** Alert 组件主题变量 */
175
+ export interface AlertThemeVars extends ComponentThemeVars {
176
+ iconSize?: string;
177
+ titleFontSize?: string;
178
+ descriptionFontSize?: string;
179
+ closeBtnSize?: string;
180
+ successBgColor?: string;
181
+ warningBgColor?: string;
182
+ errorBgColor?: string;
183
+ infoBgColor?: string;
184
+ }
185
+ /** Tabs 组件主题变量 */
186
+ export interface TabsThemeVars extends ComponentThemeVars {
187
+ tabGap?: string;
188
+ tabPadding?: string;
189
+ tabActiveTextColor?: string;
190
+ tabActiveBorderColor?: string;
191
+ tabHoverTextColor?: string;
192
+ panePadding?: string;
193
+ inkBarHeight?: string;
194
+ }
195
+ /** Form 组件主题变量 */
196
+ export interface FormThemeVars extends ComponentThemeVars {
197
+ labelWidth?: string;
198
+ labelFontSize?: string;
199
+ labelColor?: string;
200
+ requiredMarkColor?: string;
201
+ errorColor?: string;
202
+ helpColor?: string;
203
+ itemMarginBottom?: string;
204
+ }
205
+ /** Calendar 组件主题变量 */
206
+ export interface CalendarThemeVars extends ComponentThemeVars {
207
+ headerBgColor?: string;
208
+ headerTextColor?: string;
209
+ titleFontSize?: string;
210
+ dayFontSize?: string;
211
+ dayTextColor?: string;
212
+ dayHoverBgColor?: string;
213
+ daySelectedBgColor?: string;
214
+ daySelectedTextColor?: string;
215
+ todayTextColor?: string;
216
+ weekendTextColor?: string;
217
+ }
218
+ /** Tree 组件主题变量 */
219
+ export interface TreeThemeVars extends ComponentThemeVars {
220
+ nodeHoverBgColor?: string;
221
+ nodeSelectedBgColor?: string;
222
+ nodeSelectedTextColor?: string;
223
+ nodeHeight?: string;
224
+ indentSize?: string;
225
+ labelFontSize?: string;
226
+ labelTextColor?: string;
227
+ expandIconColor?: string;
228
+ expandIconHoverColor?: string;
229
+ }
230
+ /** Mention 组件主题变量 */
231
+ export interface MentionThemeVars extends ComponentThemeVars {
232
+ dropdownShadow?: string;
233
+ dropdownBgColor?: string;
234
+ optionHoverBgColor?: string;
235
+ optionActiveTextColor?: string;
236
+ }
237
+ export interface AllComponentThemes {
238
+ button?: ButtonThemeVars;
239
+ input?: InputThemeVars;
240
+ select?: SelectThemeVars;
241
+ table?: TableThemeVars;
242
+ card?: CardThemeVars;
243
+ modal?: ModalThemeVars;
244
+ dialog?: ModalThemeVars;
245
+ menu?: MenuThemeVars;
246
+ tooltip?: TooltipThemeVars;
247
+ popover?: TooltipThemeVars;
248
+ tag?: TagThemeVars;
249
+ alert?: AlertThemeVars;
250
+ tabs?: TabsThemeVars;
251
+ form?: FormThemeVars;
252
+ calendar?: CalendarThemeVars;
253
+ tree?: TreeThemeVars;
254
+ mention?: MentionThemeVars;
255
+ [key: string]: ComponentThemeVars | undefined;
256
+ }
257
+ /**
258
+ * 创建组件主题配置
259
+ * @param themes 组件主题配置
260
+ * @returns 类型安全的组件主题配置
261
+ */
262
+ export declare function createComponentThemes<T extends AllComponentThemes>(themes: T): T;
263
+ /**
264
+ * 合并组件主题
265
+ * @param base 基础主题
266
+ * @param overrides 覆盖主题
267
+ * @returns 合并后的主题
268
+ */
269
+ export declare function mergeComponentThemes(base: AllComponentThemes, overrides: AllComponentThemes): AllComponentThemes;
@@ -0,0 +1,54 @@
1
+ import { inject, provide, computed, unref } from "vue";
2
+ export const COMPONENT_THEME_KEY = Symbol("component-theme");
3
+ export const componentThemeProps = {
4
+ /** 组件主题变量覆盖 */
5
+ themeOverrides: {
6
+ type: Object,
7
+ default: void 0
8
+ }
9
+ };
10
+ export function useComponentTheme(componentName, localOverrides) {
11
+ const globalThemes = inject(COMPONENT_THEME_KEY, {});
12
+ const mergedVars = computed(() => {
13
+ const globalVars = globalThemes[componentName] || {};
14
+ const local = unref(localOverrides) || {};
15
+ return {
16
+ ...globalVars,
17
+ ...local
18
+ };
19
+ });
20
+ const themeStyle = computed(() => {
21
+ const vars = mergedVars.value;
22
+ const style = {};
23
+ Object.entries(vars).forEach(([key, value]) => {
24
+ if (value !== void 0) {
25
+ const cssVarName = `--yh-${componentName}-${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
26
+ style[cssVarName] = value;
27
+ }
28
+ });
29
+ return style;
30
+ });
31
+ const hasCustomTheme = computed(() => {
32
+ return Object.keys(mergedVars.value).length > 0;
33
+ });
34
+ return {
35
+ themeVars: mergedVars,
36
+ themeStyle,
37
+ hasCustomTheme
38
+ };
39
+ }
40
+ export function provideComponentThemes(themes) {
41
+ provide(COMPONENT_THEME_KEY, themes);
42
+ }
43
+ export function createComponentThemes(themes) {
44
+ return themes;
45
+ }
46
+ export function mergeComponentThemes(base, overrides) {
47
+ const result = { ...base };
48
+ Object.keys(overrides).forEach((key) => {
49
+ const baseVars = result[key] || {};
50
+ const overrideVars = overrides[key] || {};
51
+ result[key] = { ...baseVars, ...overrideVars };
52
+ });
53
+ return result;
54
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _tokens = require("./tokens/index.cjs");
7
+ Object.keys(_tokens).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _tokens[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _tokens[key];
14
+ }
15
+ });
16
+ });
17
+ var _theme = require("./theme.cjs");
18
+ Object.keys(_theme).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _theme[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _theme[key];
25
+ }
26
+ });
27
+ });
28
+ var _componentTheme = require("./component-theme.cjs");
29
+ Object.keys(_componentTheme).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _componentTheme[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _componentTheme[key];
36
+ }
37
+ });
38
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @yh-ui/theme - Theme System
3
+ * @description 设计令牌和主题系统
4
+ */
5
+ export * from './tokens';
6
+ export * from './theme';
7
+ export * from './component-theme';
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./tokens/index.mjs";
2
+ export * from "./theme.mjs";
3
+ export * from "./component-theme.mjs";