Skip to content

Commit

Permalink
fix(layout): use best className slove token error
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed May 8, 2023
1 parent 69070f1 commit 8090248
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
11 changes: 0 additions & 11 deletions packages/layout/src/ProLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,6 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
theme={{
hashed: isNeedOpenHash(),
components: {
Layout: {
colorBgHeader: 'transparent',
colorBgBody: 'transparent',
},
Menu: {
colorItemBg:
token?.layout?.sider?.colorMenuBackground ||
Expand All @@ -779,7 +775,6 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
controlHeightLG:
token?.layout?.sider?.menuHeight ||
token?.controlHeightLG,

colorItemBgSelected:
token?.layout?.sider?.colorBgMenuItemSelected ||
token?.colorBgTextHover,
Expand All @@ -795,12 +790,6 @@ const BaseProLayout: React.FC<ProLayoutProps> = (props) => {
colorItemText:
token?.layout?.sider?.colorTextMenu ||
token?.colorTextSecondary,
colorItemTextHoverHorizontal:
token?.layout?.sider?.colorTextMenuActive ||
token?.colorText,
colorItemTextSelectedHorizontal:
token?.layout?.sider?.colorTextMenuSelected ||
token?.colorTextBase,
colorItemTextHover:
token?.layout?.sider?.colorTextMenuActive ||
'rgba(0, 0, 0, 0.85)',
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/src/components/SiderMenu/BaseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ const BaseMenu: React.FC<BaseMenuProps & PrivateSiderMenuProps> = (props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
[openKeys && openKeys.join(','), props.layout, props.collapsed],
);
const { wrapSSR, hashId } = useStyle(baseClassName);
const { wrapSSR, hashId } = useStyle(baseClassName + '-' + mode, mode);

const menuUtils = useMemo(() => {
return new MenuUtil({
Expand Down
17 changes: 11 additions & 6 deletions packages/layout/src/components/SiderMenu/style/menu.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import type { GenerateStyle, ProAliasToken } from '@ant-design/pro-provider';
import { useStyle as useAntdStyle } from '@ant-design/pro-provider';
import { MenuMode } from '../BaseMenu';

export interface ProLayoutBaseMenuToken extends ProAliasToken {
componentCls: string;
}

const genProLayoutBaseMenuStyle: GenerateStyle<ProLayoutBaseMenuToken> = (
token,
mode,
) => {
const menuToken = mode.includes('horizontal')
? token.layout?.header
: token.layout?.sider;
return {
[`${token.componentCls}`]: {
background: 'transparent',
color: token.layout?.sider?.colorTextMenu,
color: menuToken?.colorTextMenu,
border: 'none',
[`${token.componentCls}-menu-item`]: {
transition: 'none !important',
Expand Down Expand Up @@ -42,7 +47,7 @@ const genProLayoutBaseMenuStyle: GenerateStyle<ProLayoutBaseMenuToken> = (
[`${token.antCls}-menu-item-group > ${token.antCls}-menu-item-group-list > ${token.antCls}-menu-submenu-selected > ${token.antCls}-menu-submenu-title,
${token.antCls}-menu-submenu-selected > ${token.antCls}-menu-submenu-title`]:
{
backgroundColor: token.layout?.sider?.colorBgMenuItemSelected,
backgroundColor: menuToken?.colorBgMenuItemSelected,
borderRadius: token.borderRadiusLG,
},
[`${token.componentCls}-group`]: {
Expand All @@ -67,7 +72,7 @@ const genProLayoutBaseMenuStyle: GenerateStyle<ProLayoutBaseMenuToken> = (
flexDirection: 'row',
alignItems: 'center',
gap: 8,
color: token.layout?.sider?.colorTextMenu,
color: menuToken?.colorTextMenu,
'&-collapsed': {
flexDirection: 'column',
justifyContent: 'center',
Expand Down Expand Up @@ -145,12 +150,12 @@ const genProLayoutBaseMenuStyle: GenerateStyle<ProLayoutBaseMenuToken> = (
};
};

export function useStyle(prefixCls: string) {
return useAntdStyle('ProLayoutBaseMenu', (token) => {
export function useStyle(prefixCls: string, mode: MenuMode | undefined) {
return useAntdStyle('ProLayoutBaseMenu' + mode, (token) => {
const proLayoutMenuToken: ProLayoutBaseMenuToken = {
...token,
componentCls: `.${prefixCls}`,
};
return [genProLayoutBaseMenuStyle(proLayoutMenuToken)];
return [genProLayoutBaseMenuStyle(proLayoutMenuToken, mode || 'inline')];
});
}
2 changes: 1 addition & 1 deletion packages/provider/src/useStyle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const lighten = (baseColor: string, brightness: number) => {
export type GenerateStyle<
ComponentToken extends object = GlobalToken,
ReturnType = CSSInterpolation,
> = (token: ComponentToken) => ReturnType;
> = (token: ComponentToken, ...rest: any[]) => ReturnType;

const genTheme = (): any => {
if (typeof theme === 'undefined' || !theme) return batToken as any;
Expand Down

0 comments on commit 8090248

Please sign in to comment.