|
1 | 1 | import type { GenerateStyle, ProAliasToken } from '@ant-design/pro-provider';
|
2 | 2 | import { useStyle as useAntdStyle } from '@ant-design/pro-provider';
|
3 |
| -import { version } from 'antd'; |
4 | 3 |
|
5 | 4 | export interface ProLayoutToken extends ProAliasToken {
|
6 | 5 | componentCls: string;
|
7 | 6 | }
|
8 | 7 |
|
9 |
| -const getVersion = () => { |
10 |
| - if (typeof process === 'undefined') return version; |
11 |
| - return process?.env?.ANTD_VERSION || version; |
12 |
| -}; |
13 |
| - |
14 |
| -/** |
15 |
| - * 主要区别: |
16 |
| - * 需要手动引入 import 'antd/dist/antd.css'; |
17 |
| - * 需要重置 menu 的样式 |
18 |
| - * @param token |
19 |
| - * @returns |
20 |
| - */ |
21 |
| -const compatibleStyle: GenerateStyle<ProLayoutToken> = (token) => { |
22 |
| - if (getVersion()?.startsWith('5')) { |
23 |
| - return {}; |
24 |
| - } |
25 |
| - return { |
26 |
| - [token.componentCls]: { |
27 |
| - width: '100%', |
28 |
| - height: '100%', |
29 |
| - [`${token.proComponentsCls}-base-menu`]: { |
30 |
| - color: token.layout?.sider?.colorTextMenu, |
31 |
| - [`${token.antCls}-menu-sub`]: { |
32 |
| - backgroundColor: 'transparent!important', |
33 |
| - color: token.layout?.sider?.colorTextMenu, |
34 |
| - }, |
35 |
| - [`& ${token.antCls}-layout`]: { |
36 |
| - backgroundColor: 'transparent', |
37 |
| - width: '100%', |
38 |
| - }, |
39 |
| - [`${token.antCls}-menu-submenu-expand-icon, ${token.antCls}-menu-submenu-arrow`]: |
40 |
| - { |
41 |
| - color: 'inherit', |
42 |
| - }, |
43 |
| - [`&${token.antCls}-menu`]: { |
44 |
| - color: token.layout?.sider?.colorTextMenu, |
45 |
| - [`${token.antCls}-menu-item`]: { |
46 |
| - '*': { |
47 |
| - transition: 'none !important', |
48 |
| - }, |
49 |
| - }, |
50 |
| - [`${token.antCls}-menu-item a`]: { |
51 |
| - color: 'inherit', |
52 |
| - }, |
53 |
| - }, |
54 |
| - [`&${token.antCls}-menu-inline`]: { |
55 |
| - [`${token.antCls}-menu-selected::after,${token.antCls}-menu-item-selected::after`]: |
56 |
| - { |
57 |
| - display: 'none', |
58 |
| - }, |
59 |
| - }, |
60 |
| - [`${token.antCls}-menu-sub ${token.antCls}-menu-inline`]: { |
61 |
| - backgroundColor: 'transparent!important', |
62 |
| - }, |
63 |
| - [`${token.antCls}-menu-item:active, |
64 |
| - ${token.antCls}-menu-submenu-title:active`]: { |
65 |
| - backgroundColor: 'transparent!important', |
66 |
| - }, |
67 |
| - [`&${token.antCls}-menu-light`]: { |
68 |
| - [`${token.antCls}-menu-item:hover, |
69 |
| - ${token.antCls}-menu-item-active, |
70 |
| - ${token.antCls}-menu-submenu-active, |
71 |
| - ${token.antCls}-menu-submenu-title:hover`]: { |
72 |
| - color: token.layout?.sider?.colorTextMenuActive, |
73 |
| - borderRadius: token.borderRadius, |
74 |
| - [`${token.antCls}-menu-submenu-arrow`]: { |
75 |
| - color: token.layout?.sider?.colorTextMenuActive, |
76 |
| - }, |
77 |
| - }, |
78 |
| - }, |
79 |
| - [`&${token.antCls}-menu:not(${token.antCls}-menu-horizontal)`]: { |
80 |
| - [`${token.antCls}-menu-item-selected`]: { |
81 |
| - backgroundColor: token.layout?.sider?.colorBgMenuItemSelected, |
82 |
| - borderRadius: token.borderRadius, |
83 |
| - }, |
84 |
| - [`${token.antCls}-menu-item:hover, |
85 |
| - ${token.antCls}-menu-item-active, |
86 |
| - ${token.antCls}-menu-submenu-title:hover`]: { |
87 |
| - color: token.layout?.sider?.colorTextMenuActive, |
88 |
| - borderRadius: token.borderRadius, |
89 |
| - backgroundColor: `${token.layout?.header?.colorBgMenuItemHover} !important`, |
90 |
| - [`${token.antCls}-menu-submenu-arrow`]: { |
91 |
| - color: token.layout?.sider?.colorTextMenuActive, |
92 |
| - }, |
93 |
| - }, |
94 |
| - }, |
95 |
| - [`${token.antCls}-menu-item-selected`]: { |
96 |
| - color: token.layout?.sider?.colorTextMenuSelected, |
97 |
| - }, |
98 |
| - [`${token.antCls}-menu-submenu-selected`]: { |
99 |
| - color: token.layout?.sider?.colorTextMenuSelected, |
100 |
| - }, |
101 |
| - [`&${token.antCls}-menu:not(${token.antCls}-menu-inline) ${token.antCls}-menu-submenu-open`]: |
102 |
| - { |
103 |
| - color: token.layout?.sider?.colorTextMenuSelected, |
104 |
| - }, |
105 |
| - |
106 |
| - [`&${token.antCls}-menu-vertical`]: { |
107 |
| - [`${token.antCls}-menu-submenu-selected`]: { |
108 |
| - borderRadius: token.borderRadius, |
109 |
| - color: token.layout?.sider?.colorTextMenuSelected, |
110 |
| - }, |
111 |
| - }, |
112 |
| - |
113 |
| - [`${token.antCls}-menu-submenu:hover > ${token.antCls}-menu-submenu-title > ${token.antCls}-menu-submenu-arrow`]: |
114 |
| - { |
115 |
| - color: token.layout?.sider?.colorTextMenuActive, |
116 |
| - }, |
117 |
| - |
118 |
| - [`&${token.antCls}-menu-horizontal`]: { |
119 |
| - [`${token.antCls}-menu-item:hover, |
120 |
| - ${token.antCls}-menu-submenu:hover, |
121 |
| - ${token.antCls}-menu-item-active, |
122 |
| - ${token.antCls}-menu-submenu-active`]: { |
123 |
| - borderRadius: 4, |
124 |
| - transition: 'none', |
125 |
| - color: token.layout?.header?.colorTextMenuActive, |
126 |
| - backgroundColor: `${token.layout?.header?.colorBgMenuItemHover} !important`, |
127 |
| - }, |
128 |
| - |
129 |
| - [`${token.antCls}-menu-item-open, |
130 |
| - ${token.antCls}-menu-submenu-open, |
131 |
| - ${token.antCls}-menu-item-selected, |
132 |
| - ${token.antCls}-menu-submenu-selected`]: { |
133 |
| - backgroundColor: token.layout?.header?.colorBgMenuItemSelected, |
134 |
| - borderRadius: token.borderRadius, |
135 |
| - transition: 'none', |
136 |
| - color: `${token.layout?.header?.colorTextMenuSelected} !important`, |
137 |
| - [`${token.antCls}-menu-submenu-arrow`]: { |
138 |
| - color: `${token.layout?.header?.colorTextMenuSelected} !important`, |
139 |
| - }, |
140 |
| - }, |
141 |
| - [`> ${token.antCls}-menu-item, > ${token.antCls}-menu-submenu`]: { |
142 |
| - paddingInline: 16, |
143 |
| - marginInline: 4, |
144 |
| - }, |
145 |
| - [`> ${token.antCls}-menu-item::after, > ${token.antCls}-menu-submenu::after`]: |
146 |
| - { |
147 |
| - display: 'none', |
148 |
| - }, |
149 |
| - }, |
150 |
| - }, |
151 |
| - |
152 |
| - [`${token.proComponentsCls}-top-nav-header-base-menu`]: { |
153 |
| - [`&${token.antCls}-menu`]: { |
154 |
| - color: token.layout?.header?.colorTextMenu, |
155 |
| - [`${token.antCls}-menu-item a`]: { |
156 |
| - color: 'inherit', |
157 |
| - }, |
158 |
| - }, |
159 |
| - [`&${token.antCls}-menu-light`]: { |
160 |
| - [`${token.antCls}-menu-item:hover, |
161 |
| - ${token.antCls}-menu-item-active, |
162 |
| - ${token.antCls}-menu-submenu-active, |
163 |
| - ${token.antCls}-menu-submenu-title:hover`]: { |
164 |
| - color: token.layout?.header?.colorTextMenuActive, |
165 |
| - borderRadius: token.borderRadius, |
166 |
| - transition: 'none', |
167 |
| - backgroundColor: token.layout?.header?.colorBgMenuItemSelected, |
168 |
| - [`${token.antCls}-menu-submenu-arrow`]: { |
169 |
| - color: token.layout?.header?.colorTextMenuActive, |
170 |
| - }, |
171 |
| - }, |
172 |
| - |
173 |
| - [`${token.antCls}-menu-item-selected`]: { |
174 |
| - color: token.layout?.header?.colorTextMenuSelected, |
175 |
| - borderRadius: token.borderRadius, |
176 |
| - backgroundColor: token.layout?.header?.colorBgMenuItemSelected, |
177 |
| - }, |
178 |
| - }, |
179 |
| - }, |
180 |
| - }, |
181 |
| - [`${token.antCls}-menu-sub${token.antCls}-menu-inline`]: { |
182 |
| - backgroundColor: 'transparent!important', |
183 |
| - }, |
184 |
| - [`${token.antCls}-menu-submenu-popup`]: { |
185 |
| - backgroundColor: 'rgba(255, 255, 255, 0.42)', |
186 |
| - '-webkit-backdrop-filter': 'blur(8px)', |
187 |
| - backdropFilter: 'blur(8px)', |
188 |
| - [`${token.antCls}-menu`]: { |
189 |
| - background: 'transparent !important', |
190 |
| - backgroundColor: 'transparent !important', |
191 |
| - [`${token.antCls}-menu-item:active, |
192 |
| - ${token.antCls}-menu-submenu-title:active`]: { |
193 |
| - backgroundColor: 'transparent!important', |
194 |
| - }, |
195 |
| - }, |
196 |
| - [`${token.antCls}-menu-item-selected`]: { |
197 |
| - color: token.layout?.sider?.colorTextMenuSelected, |
198 |
| - }, |
199 |
| - [`${token.antCls}-menu-submenu-selected`]: { |
200 |
| - color: token.layout?.sider?.colorTextMenuSelected, |
201 |
| - }, |
202 |
| - [`${token.antCls}-menu:not(${token.antCls}-menu-horizontal)`]: { |
203 |
| - [`${token.antCls}-menu-item-selected`]: { |
204 |
| - backgroundColor: 'rgba(0, 0, 0, 0.04)', |
205 |
| - borderRadius: token.borderRadius, |
206 |
| - color: token.layout?.sider?.colorTextMenuSelected, |
207 |
| - }, |
208 |
| - [`${token.antCls}-menu-item:hover, |
209 |
| - ${token.antCls}-menu-item-active, |
210 |
| - ${token.antCls}-menu-submenu-title:hover`]: { |
211 |
| - color: token.layout?.sider?.colorTextMenuActive, |
212 |
| - borderRadius: token.borderRadius, |
213 |
| - [`${token.antCls}-menu-submenu-arrow`]: { |
214 |
| - color: token.layout?.sider?.colorTextMenuActive, |
215 |
| - }, |
216 |
| - }, |
217 |
| - }, |
218 |
| - }, |
219 |
| - }; |
220 |
| -}; |
221 |
| - |
222 | 8 | const genProLayoutStyle: GenerateStyle<ProLayoutToken> = (token) => {
|
223 | 9 | return {
|
224 | 10 | [`${token.antCls}-layout`]: {
|
@@ -275,6 +61,6 @@ export function useStyle(prefixCls: string) {
|
275 | 61 | componentCls: `.${prefixCls}`,
|
276 | 62 | } as ProLayoutToken;
|
277 | 63 |
|
278 |
| - return [genProLayoutStyle(proLayoutToken), compatibleStyle(proLayoutToken)]; |
| 64 | + return [genProLayoutStyle(proLayoutToken)]; |
279 | 65 | });
|
280 | 66 | }
|
0 commit comments