Skip to content

Commit

Permalink
fix(layout): support antd@5.6 token
Browse files Browse the repository at this point in the history
close #7188
  • Loading branch information
chenshuai2144 committed Jun 10, 2023
1 parent 8184e91 commit 28291fe
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 35 deletions.
75 changes: 41 additions & 34 deletions packages/layout/src/ProLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ProProvider,
} from '@ant-design/pro-provider';
import {
coverToNewToken,
isBrowser,
useDocumentTitle,
useMountMergeState,
Expand Down Expand Up @@ -772,7 +773,7 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
theme={{
hashed: isNeedOpenHash(),
components: {
Menu: {
Menu: coverToNewToken({
colorItemBg:
token?.layout?.sider?.colorMenuBackground ||
'transparent',
Expand Down Expand Up @@ -807,7 +808,7 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
colorBgElevated:
token?.layout?.sider?.colorBgMenuItemCollapsedElevated ||
'#fff',
},
}),
},
}}
>
Expand All @@ -827,38 +828,44 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
colorBgBody: 'transparent',
},
Menu: {
colorItemBg:
token?.layout?.header?.colorBgHeader || 'transparent',
colorSubItemBg:
token?.layout?.header?.colorBgHeader || 'transparent',
radiusItem: 4,
colorItemBgSelected:
token?.layout?.header?.colorBgMenuItemSelected ||
token?.colorBgTextHover,
colorItemBgActive:
token?.layout?.header?.colorBgMenuItemHover ||
token?.colorBgTextHover,
colorItemBgSelectedHorizontal:
token?.layout?.header?.colorBgMenuItemSelected ||
token?.colorBgTextHover,
colorActiveBarWidth: 0,
colorActiveBarHeight: 0,
colorActiveBarBorderSize: 0,
colorItemText:
token?.layout?.header?.colorTextMenu ||
token?.colorTextSecondary,
colorItemTextHoverHorizontal:
token?.layout?.header?.colorTextMenuActive ||
token?.colorText,
colorItemTextSelectedHorizontal:
token?.layout?.header?.colorTextMenuSelected ||
token?.colorTextBase,
colorItemTextHover:
token?.layout?.header?.colorTextMenuActive ||
'rgba(0, 0, 0, 0.85)',
colorItemTextSelected:
token?.layout?.header?.colorTextMenuSelected ||
'rgba(0, 0, 0, 1)',
...coverToNewToken({
colorItemBg:
token?.layout?.header?.colorBgHeader || 'transparent',
colorSubItemBg:
token?.layout?.header?.colorBgHeader || 'transparent',
radiusItem: 4,
colorItemBgSelected:
token?.layout?.header?.colorBgMenuItemSelected ||
token?.colorBgTextHover,
colorItemBgActive:
token?.layout?.header?.colorBgMenuItemHover ||
token?.colorBgTextHover,
colorItemBgSelectedHorizontal:
token?.layout?.header?.colorBgMenuItemSelected ||
token?.colorBgTextHover,
colorActiveBarWidth: 0,
colorActiveBarHeight: 0,
colorActiveBarBorderSize: 0,
colorItemText:
token?.layout?.header?.colorTextMenu ||
token?.colorTextSecondary,
colorItemTextHoverHorizontal:
token?.layout?.header?.colorTextMenuActive ||
token?.colorText,
colorItemTextSelectedHorizontal:
token?.layout?.header?.colorTextMenuSelected ||
token?.colorTextBase,
horizontalItemBorderRadius: 4,
colorItemTextHover:
token?.layout?.header?.colorTextMenuActive ||
'rgba(0, 0, 0, 0.85)',
horizontalItemHoverBg:
token?.layout?.header?.colorBgMenuItemHover ||
'rgba(0, 0, 0, 0.04)',
colorItemTextSelected:
token?.layout?.header?.colorTextMenuSelected ||
'rgba(0, 0, 0, 1)',
}),
},
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const genAppsLogoComponentsStyle: GenerateStyle<AppsLogoComponentsToken> = (
width: 28,
cursor: 'pointer',
color: token?.layout?.colorTextAppListIcon,
borderRadius: token.borderRadius,
'&:hover': {
color: token?.layout?.colorTextAppListIconHover,
backgroundColor: token?.layout?.colorBgAppListIconHover,
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/src/components/SiderMenu/style/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const genProLayoutBaseMenuStyle: GenerateStyle<ProLayoutBaseMenuToken> = (
height: '14px',
},
},
'& &-item-title': {
'&-item-title': {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
Expand Down
42 changes: 42 additions & 0 deletions packages/utils/src/compareVersions/coverToNewToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { compareVersions } from './index';
import { getVersion } from './openVisibleCompatible';

export function coverToNewToken(
token: Record<string, string | number | undefined>,
) {
if (compareVersions(getVersion(), '5.6.0') < 0) return token;
const deprecatedTokens = {
colorGroupTitle: 'groupTitleColor',
radiusItem: 'itemBorderRadius',
radiusSubMenuItem: 'subMenuItemBorderRadius',
colorItemText: 'itemColor',
colorItemTextHover: 'itemHoverColor',
colorItemTextHoverHorizontal: 'horizontalItemHoverColor',
colorItemTextSelected: 'itemSelectedColor',
colorItemTextSelectedHorizontal: 'horizontalItemSelectedColor',
colorItemTextDisabled: 'itemDisabledColor',
colorDangerItemText: 'dangerItemColor',
colorDangerItemTextHover: 'dangerItemHoverColor',
colorDangerItemTextSelected: 'dangerItemSelectedColor',
colorDangerItemBgActive: 'dangerItemActiveBg',
colorDangerItemBgSelected: 'dangerItemSelectedBg',
colorItemBg: 'itemBg',
colorItemBgHover: 'itemHoverBg',
colorSubItemBg: 'subMenuItemBg',
colorItemBgActive: 'itemActiveBg',
colorItemBgSelected: 'itemSelectedBg',
colorItemBgSelectedHorizontal: 'horizontalItemSelectedBg',
colorActiveBarWidth: 'activeBarWidth',
colorActiveBarHeight: 'activeBarHeight',
colorActiveBarBorderSize: 'activeBarBorderWidth',
};

const newToken = { ...token };
Object.keys(deprecatedTokens).forEach((key) => {
if (newToken[key] !== undefined) {
newToken[deprecatedTokens[key]] = newToken[key];
delete newToken[key];
}
});
return newToken;
}
2 changes: 2 additions & 0 deletions packages/utils/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useStyle,
} from '@ant-design/pro-provider';
import { compareVersions } from './compareVersions';
import { coverToNewToken } from './compareVersions/coverToNewToken';
import { menuOverlayCompatible } from './compareVersions/menuOverlayCompatible';
import { openVisibleCompatible } from './compareVersions/openVisibleCompatible';
import { useDebounceFn } from './hooks/useDebounceFn';
Expand Down Expand Up @@ -105,6 +106,7 @@ export {
useDocumentTitle,
isImg,
omitBoolean,
coverToNewToken,
isNil,
merge,
isDropdownValueType,
Expand Down

0 comments on commit 28291fe

Please sign in to comment.