xt-element-ui 1.0.8 → 1.0.9
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/lib/index.common.js +617 -390
- package/lib/index.css +1 -1
- package/lib/index.umd.js +617 -390
- package/lib/index.umd.min.js +1 -1
- package/package.json +2 -2
- package/src/components/button/index.vue +48 -15
- package/src/components/button/style/index.scss +130 -0
- package/src/components/card/index.vue +20 -41
- package/src/components/card/style/index.scss +49 -0
- package/src/components/card-item/index.vue +71 -90
- package/src/components/card-item/style/index.scss +72 -0
- package/src/components/config-provider/index.js +2 -0
- package/src/components/config-provider/index.vue +176 -0
- package/src/components/config-provider/style/index.scss +12 -0
- package/src/components/flex-box/index.vue +20 -90
- package/src/components/flex-box/style/index.scss +91 -0
- package/src/components/index.scss +19 -0
- package/src/components/input/index.vue +28 -11
- package/src/components/input/style/index.scss +27 -0
- package/src/index.js +65 -122
- package/src/styles/export.scss +1 -1
- package/src/styles/theme/bg.scss +6 -0
- package/src/styles/theme/border.scss +4 -0
- package/src/styles/theme/color.scss +11 -0
- package/src/styles/theme/component.scss +70 -0
- package/src/styles/theme/dark.scss +29 -0
- package/src/styles/theme/font.scss +10 -0
- package/src/styles/theme/index.scss +11 -0
- package/src/styles/theme/radius.scss +4 -0
- package/src/styles/theme/shadow.scss +3 -0
- package/src/styles/theme/spacing.scss +5 -0
- package/src/styles/theme/text.scss +5 -0
- package/src/styles/theme/transition.scss +3 -0
- package/src/styles/theme-element.scss +0 -10
- package/src/styles/variables.scss +1 -126
- package/src/styles/{theme.scss → vars.scss} +72 -31
- package/src/utils/index.js +195 -124
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@
|
|
1
|
+
@import './theme/index.scss';
|
|
2
2
|
|
|
3
3
|
:root {
|
|
4
4
|
// 主色调系列
|
|
@@ -64,39 +64,82 @@
|
|
|
64
64
|
// 过渡动画
|
|
65
65
|
--xt-transition-duration: #{$xt-transition-duration};
|
|
66
66
|
--xt-transition-duration-fast: #{$xt-transition-duration-fast};
|
|
67
|
+
|
|
68
|
+
// 按钮专用变量
|
|
69
|
+
--xt-button-height: #{$xt-button-height};
|
|
70
|
+
--xt-button-padding-x: #{$xt-button-padding-x};
|
|
71
|
+
--xt-button-padding-y: #{$xt-button-padding-y};
|
|
72
|
+
--xt-button-font-weight: #{$xt-button-font-weight};
|
|
73
|
+
--xt-button-border-width: #{$xt-button-border-width};
|
|
74
|
+
--xt-button-transition: #{$xt-button-transition};
|
|
75
|
+
|
|
76
|
+
// 卡片专用变量
|
|
77
|
+
--xt-card-bg-color: #{$xt-card-bg-color};
|
|
78
|
+
--xt-card-border-color: #{$xt-card-border-color};
|
|
79
|
+
--xt-card-border-radius: #{$xt-card-border-radius};
|
|
80
|
+
--xt-card-padding: #{$xt-card-padding};
|
|
81
|
+
--xt-card-header-padding: #{$xt-card-header-padding};
|
|
82
|
+
--xt-card-shadow: #{$xt-card-shadow};
|
|
83
|
+
|
|
84
|
+
// 卡片项专用变量
|
|
85
|
+
--xt-card-item-min-height: #{$xt-card-item-min-height};
|
|
86
|
+
--xt-card-item-gap: #{$xt-card-item-gap};
|
|
87
|
+
--xt-card-item-border-width: #{$xt-card-item-border-width};
|
|
88
|
+
|
|
89
|
+
// 输入框专用变量
|
|
90
|
+
--xt-input-height: #{$xt-input-height};
|
|
91
|
+
--xt-input-padding-x: #{$xt-input-padding-x};
|
|
92
|
+
--xt-input-bg-color: #{$xt-input-bg-color};
|
|
93
|
+
--xt-input-border-color: #{$xt-input-border-color};
|
|
94
|
+
--xt-input-text-color: #{$xt-input-text-color};
|
|
95
|
+
--xt-input-placeholder-color: #{$xt-input-placeholder-color};
|
|
96
|
+
|
|
97
|
+
// FlexBox 专用变量
|
|
98
|
+
--xt-flex-box-gap: #{$xt-flex-box-gap};
|
|
67
99
|
}
|
|
68
100
|
|
|
69
|
-
// 暗色主题
|
|
70
|
-
[data-theme="dark"] {
|
|
71
|
-
--xt-color-primary:
|
|
72
|
-
--xt-color-success: #
|
|
73
|
-
--xt-color-warning: #
|
|
74
|
-
--xt-color-danger: #
|
|
75
|
-
--xt-color-info: #
|
|
76
|
-
|
|
77
|
-
--xt-color-text-primary:
|
|
78
|
-
--xt-color-text-regular:
|
|
79
|
-
--xt-color-text-secondary:
|
|
80
|
-
--xt-color-text-placeholder:
|
|
81
|
-
--xt-color-text-disabled:
|
|
82
|
-
|
|
83
|
-
--xt-color-bg-primary: #
|
|
84
|
-
--xt-color-bg-secondary: #
|
|
85
|
-
--xt-color-bg-hover: #
|
|
86
|
-
--xt-color-bg-container: #
|
|
87
|
-
--xt-color-bg-overlay: #
|
|
88
|
-
|
|
89
|
-
--xt-color-border: #
|
|
90
|
-
--xt-color-border-light: #
|
|
91
|
-
--xt-color-border-lighter: #
|
|
92
|
-
--xt-color-border-extra-light: #
|
|
101
|
+
// 暗色主题
|
|
102
|
+
html.dark, html[data-theme="dark"] {
|
|
103
|
+
--xt-color-primary: var(--xt-color-primary);
|
|
104
|
+
--xt-color-success: #{$xt-dark-color-success};
|
|
105
|
+
--xt-color-warning: #{$xt-dark-color-warning};
|
|
106
|
+
--xt-color-danger: #{$xt-dark-color-danger};
|
|
107
|
+
--xt-color-info: #{$xt-dark-color-info};
|
|
108
|
+
|
|
109
|
+
--xt-color-text-primary: #{$xt-dark-color-text-primary};
|
|
110
|
+
--xt-color-text-regular: #{$xt-dark-color-text-regular};
|
|
111
|
+
--xt-color-text-secondary: #{$xt-dark-color-text-secondary};
|
|
112
|
+
--xt-color-text-placeholder: #{$xt-dark-color-text-placeholder};
|
|
113
|
+
--xt-color-text-disabled: #{$xt-dark-color-text-disabled};
|
|
114
|
+
|
|
115
|
+
--xt-color-bg-primary: #{$xt-dark-color-bg-primary};
|
|
116
|
+
--xt-color-bg-secondary: #{$xt-dark-color-bg-secondary};
|
|
117
|
+
--xt-color-bg-hover: #{$xt-dark-color-bg-hover};
|
|
118
|
+
--xt-color-bg-container: #{$xt-dark-color-bg-container};
|
|
119
|
+
--xt-color-bg-overlay: #{$xt-dark-color-bg-overlay};
|
|
120
|
+
|
|
121
|
+
--xt-color-border: #{$xt-dark-color-border};
|
|
122
|
+
--xt-color-border-light: #{$xt-dark-color-border-light};
|
|
123
|
+
--xt-color-border-lighter: #{$xt-dark-color-border-lighter};
|
|
124
|
+
--xt-color-border-extra-light: #{$xt-dark-color-border-extra-light};
|
|
125
|
+
|
|
126
|
+
// 暗色主题下的组件变量
|
|
127
|
+
--xt-card-bg-color: #{$xt-dark-color-bg-primary};
|
|
128
|
+
--xt-card-border-color: #{$xt-dark-color-border};
|
|
129
|
+
--xt-input-bg-color: #{$xt-dark-color-bg-secondary};
|
|
130
|
+
--xt-input-border-color: #{$xt-dark-color-border};
|
|
131
|
+
--xt-input-text-color: #{$xt-dark-color-text-primary};
|
|
132
|
+
--xt-input-placeholder-color: #{$xt-dark-color-text-placeholder};
|
|
133
|
+
|
|
134
|
+
// 暗色主题按钮颜色变量
|
|
135
|
+
--xt-dark-button-primary-bg: #{$xt-dark-button-primary-bg};
|
|
136
|
+
--xt-dark-button-success-bg: #{$xt-dark-button-success-bg};
|
|
137
|
+
--xt-dark-button-warning-bg: #{$xt-dark-button-warning-bg};
|
|
138
|
+
--xt-dark-button-danger-bg: #{$xt-dark-button-danger-bg};
|
|
139
|
+
--xt-dark-button-info-bg: #{$xt-dark-button-info-bg};
|
|
93
140
|
}
|
|
94
141
|
|
|
95
|
-
// ===========================
|
|
96
142
|
// 字体大小主题(基于增量)
|
|
97
|
-
// ===========================
|
|
98
|
-
|
|
99
|
-
// 小字体主题 - 增量 0px
|
|
100
143
|
[data-size="small"] {
|
|
101
144
|
--xt-font-size-extra-large: #{$xt-font-size-extra-large + $xt-font-size-increment-small};
|
|
102
145
|
--xt-font-size-large: #{$xt-font-size-large + $xt-font-size-increment-small};
|
|
@@ -106,7 +149,6 @@
|
|
|
106
149
|
--xt-font-size-extra-small: #{$xt-font-size-extra-small + $xt-font-size-increment-small};
|
|
107
150
|
}
|
|
108
151
|
|
|
109
|
-
// 中等字体主题 - 增量 2px
|
|
110
152
|
[data-size="medium"] {
|
|
111
153
|
--xt-font-size-extra-large: #{$xt-font-size-extra-large + $xt-font-size-increment-medium};
|
|
112
154
|
--xt-font-size-large: #{$xt-font-size-large + $xt-font-size-increment-medium};
|
|
@@ -116,7 +158,6 @@
|
|
|
116
158
|
--xt-font-size-extra-small: #{$xt-font-size-extra-small + $xt-font-size-increment-medium};
|
|
117
159
|
}
|
|
118
160
|
|
|
119
|
-
// 大字体主题 - 增量 4px
|
|
120
161
|
[data-size="large"] {
|
|
121
162
|
--xt-font-size-extra-large: #{$xt-font-size-extra-large + $xt-font-size-increment-large};
|
|
122
163
|
--xt-font-size-large: #{$xt-font-size-large + $xt-font-size-increment-large};
|
package/src/utils/index.js
CHANGED
|
@@ -1,124 +1,195 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
// 默认配置
|
|
2
|
+
const defaultConfig = {
|
|
3
|
+
theme: 'light',
|
|
4
|
+
size: 'medium',
|
|
5
|
+
primaryColor: '#409EFF'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// 当前配置
|
|
9
|
+
let currentConfig = { ...defaultConfig }
|
|
10
|
+
|
|
11
|
+
// 调试:输出初始化信息
|
|
12
|
+
console.log('[XtElementUI] utils initialized with currentConfig:', currentConfig)
|
|
13
|
+
|
|
14
|
+
// 配置变更事件处理
|
|
15
|
+
const configChangeListeners = []
|
|
16
|
+
|
|
17
|
+
const emitConfigChange = function(key, value) {
|
|
18
|
+
configChangeListeners.forEach(listener => {
|
|
19
|
+
listener(key, value)
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 获取所有配置
|
|
24
|
+
export const getConfig = function() {
|
|
25
|
+
return { ...currentConfig }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 设置全局配置
|
|
29
|
+
export const setConfig = function(config) {
|
|
30
|
+
if (typeof config !== 'object' || config === null) {
|
|
31
|
+
console.warn('[XtElementUI] setConfig 必须传入对象参数')
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (config.theme !== undefined) {
|
|
36
|
+
setTheme(config.theme)
|
|
37
|
+
}
|
|
38
|
+
if (config.size !== undefined) {
|
|
39
|
+
setSize(config.size)
|
|
40
|
+
}
|
|
41
|
+
if (config.primaryColor !== undefined) {
|
|
42
|
+
setPrimaryColor(config.primaryColor)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// 设置主题
|
|
48
|
+
export const setTheme = function(theme) {
|
|
49
|
+
const validThemes = ['light', 'dark']
|
|
50
|
+
if (!validThemes.includes(theme)) {
|
|
51
|
+
console.warn(`[XtElementUI] 无效的主题值: ${theme},可选值: ${validThemes.join(', ')}`)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
currentConfig.theme = theme
|
|
56
|
+
const root = document.documentElement
|
|
57
|
+
|
|
58
|
+
// 使用类名方式切换主题(兼容 Element Plus 风格)
|
|
59
|
+
if (theme === 'dark') {
|
|
60
|
+
root.classList.add('dark')
|
|
61
|
+
root.setAttribute('data-theme', 'dark')
|
|
62
|
+
} else {
|
|
63
|
+
root.classList.remove('dark')
|
|
64
|
+
root.removeAttribute('data-theme')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
emitConfigChange('theme', theme)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 设置字体大小
|
|
71
|
+
export const setSize = function(size) {
|
|
72
|
+
const validSizes = ['small', 'medium', 'large']
|
|
73
|
+
if (!validSizes.includes(size)) {
|
|
74
|
+
console.warn(`[XtElementUI] 无效的大小值: ${size},可选值: ${validSizes.join(', ')}`)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
currentConfig.size = size
|
|
79
|
+
document.documentElement.setAttribute('data-size', size)
|
|
80
|
+
emitConfigChange('size', size)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 将十六进制颜色转换为 RGB 对象
|
|
84
|
+
function hexToRgb(hex) {
|
|
85
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
|
86
|
+
return result ? {
|
|
87
|
+
r: parseInt(result[1], 16),
|
|
88
|
+
g: parseInt(result[2], 16),
|
|
89
|
+
b: parseInt(result[3], 16)
|
|
90
|
+
} : null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 将 RGB 对象转换为十六进制颜色
|
|
94
|
+
function rgbToHex(r, g, b) {
|
|
95
|
+
return '#' + [r, g, b].map(x => {
|
|
96
|
+
const hex = x.toString(16)
|
|
97
|
+
return hex.length === 1 ? '0' + hex : hex
|
|
98
|
+
}).join('')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 计算浅色系列(混合白色)
|
|
102
|
+
function lightenColor(hex, percent) {
|
|
103
|
+
const rgb = hexToRgb(hex)
|
|
104
|
+
if (!rgb) return hex
|
|
105
|
+
|
|
106
|
+
const amount = Math.round(2.55 * percent)
|
|
107
|
+
const r = Math.min(255, rgb.r + amount)
|
|
108
|
+
const g = Math.min(255, rgb.g + amount)
|
|
109
|
+
const b = Math.min(255, rgb.b + amount)
|
|
110
|
+
|
|
111
|
+
return rgbToHex(r, g, b)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 设置主色调
|
|
115
|
+
export const setPrimaryColor = function(color) {
|
|
116
|
+
// 颜色格式验证(支持 3/6/8 位十六进制)
|
|
117
|
+
const colorRegex = /^#[0-9A-Fa-f]{3}$|^#[0-9A-Fa-f]{6}$|^#[0-9A-Fa-f]{8}$/
|
|
118
|
+
if (!colorRegex.test(color)) {
|
|
119
|
+
console.warn(`[XtElementUI] 无效的颜色值: ${color},请使用十六进制颜色格式,如 #1890ff`)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 转换为 6 位十六进制(去掉透明度)
|
|
124
|
+
let validColor = color
|
|
125
|
+
if (color.length === 4) {
|
|
126
|
+
// #RGB 转换为 #RRGGBB
|
|
127
|
+
validColor = '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3]
|
|
128
|
+
} else if (color.length === 9) {
|
|
129
|
+
// #RRGGBBAA 转换为 #RRGGBB(去掉 Alpha)
|
|
130
|
+
validColor = color.substring(0, 7)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
currentConfig.primaryColor = validColor
|
|
134
|
+
|
|
135
|
+
// 设置主色调
|
|
136
|
+
document.documentElement.style.setProperty('--xt-color-primary', validColor)
|
|
137
|
+
|
|
138
|
+
// 动态计算并设置浅色系列
|
|
139
|
+
document.documentElement.style.setProperty('--xt-color-primary-light-3', lightenColor(validColor, 30))
|
|
140
|
+
document.documentElement.style.setProperty('--xt-color-primary-light-5', lightenColor(validColor, 50))
|
|
141
|
+
document.documentElement.style.setProperty('--xt-color-primary-light-7', lightenColor(validColor, 70))
|
|
142
|
+
document.documentElement.style.setProperty('--xt-color-primary-light-8', lightenColor(validColor, 80))
|
|
143
|
+
document.documentElement.style.setProperty('--xt-color-primary-light-9', lightenColor(validColor, 90))
|
|
144
|
+
|
|
145
|
+
emitConfigChange('primaryColor', validColor)
|
|
146
|
+
console.log('[XtElementUI] 主色调已设置为:', validColor)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 获取当前主题
|
|
150
|
+
export const getTheme = function() {
|
|
151
|
+
return currentConfig.theme
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 获取当前字体大小
|
|
155
|
+
export const getSize = function() {
|
|
156
|
+
return currentConfig.size
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 获取当前主色调
|
|
160
|
+
export const getPrimaryColor = function() {
|
|
161
|
+
return currentConfig.primaryColor
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 重置为默认配置
|
|
165
|
+
export const resetConfig = function() {
|
|
166
|
+
setConfig(defaultConfig)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 监听配置变更
|
|
170
|
+
export const onConfigChange = function(listener) {
|
|
171
|
+
if (typeof listener === 'function') {
|
|
172
|
+
configChangeListeners.push(listener)
|
|
173
|
+
return function() {
|
|
174
|
+
const index = configChangeListeners.indexOf(listener)
|
|
175
|
+
if (index > -1) {
|
|
176
|
+
configChangeListeners.splice(index, 1)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
console.warn('[XtElementUI] onConfigChange 必须传入函数')
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export default {
|
|
185
|
+
setTheme,
|
|
186
|
+
setSize,
|
|
187
|
+
setPrimaryColor,
|
|
188
|
+
getConfig,
|
|
189
|
+
setConfig,
|
|
190
|
+
getTheme,
|
|
191
|
+
getSize,
|
|
192
|
+
getPrimaryColor,
|
|
193
|
+
resetConfig,
|
|
194
|
+
onConfigChange
|
|
195
|
+
}
|